当前位置: 首页 > news >正文

网站前端设计图网站优化策划书

网站前端设计图,网站优化策划书,软件商店苹果版下载,武汉今天事件最新消息前段时间有位客户问: 你们的程序能不能给我们生成个 txt 文件,把新增的员工都放进来,字段也不需要太多,就要 员工姓名/卡号/员工编号/员工职位/公司 这些字段就行了,然后我们的程序会去读取这个 txt 文件,拿里面的内容,读完之后会这个文件删掉 我: 可以接受延迟吗?可能没办法实…

前段时间有位客户问: 你们的程序能不能给我们生成个 txt 文件,把新增的员工都放进来,字段也不需要太多,就要 员工姓名/卡号/员工编号/员工职位/公司 这些字段就行了,然后我们的程序会去读取这个 txt 文件,拿里面的内容,读完之后会这个文件删掉
我: 可以接受延迟吗?可能没办法实时生成,写个脚本,用定时任务去跑还是可以实现的
客户: 可以呀,那个脚本 30mins 跑一次就行
这篇文章就记录一下大概实现思路,后续如果遇到类似需求,就可以直接 copy 代码了

实现思路:

  • 定义全局变量 update_time
  • 判断 update_time 是否为空
    • 为空,说明是第一次查询数据,取查到的最后一条记录的 create_time ,赋值给 update_time
    • 不为空,说明不是第一次查询数据,查询数据时, create_time > update_time ,同时更新 update_time
  • 判断 txt 文件是否存在
    • 存在,则 txt 表头不需要重新生成
    • 不存在, txt 表头需要重新生成

其实逻辑很简单, Python 类库也很丰富,接下来就上代码:

import pymysql
import os
import argparse
import schedule
import datetimeupdate_time = ""def handle_variables(server_ip,password):global real_ip real_ip = server_ipglobal root_password root_password = passworddef get_person_info():connection = pymysql.connect(host = real_ip,user = 'root',password = root_password,db = 'xxx')try:global update_timecur = connection.cursor()if "" == update_time :sql = "select `name`,`card_num`,`code`,`postion`,`company_id`,`gmt_create` from person"else :sql = "select `name`,`card_num`,`code`,`postion`,`company_id`,`gmt_create` from person where `gmt_create` > '" + update_time + "'"cur.execute(sql)query_person_info_list = cur.fetchall()# get the time of the last recordif len(query_person_info_list) != 0:temp_list = query_person_info_list[-1]update_time = temp_list[-1]if isinstance(update_time, datetime.datetime):update_time = update_time.strftime('%Y-%m-%d %H:%M:%S')# if the txt not exists, add new textif not os.path.exists('add_person.txt') :with open('add_person.txt', 'w') as f:f.write('Lastname, Firstname, CardNumber, Employee ID, Designation, Department \n')for person_info in query_person_info_list :person_name = person_info[0]# the name is generally first + last, which needs to be convertedperson_name_list = person_name.split()person_first_name = person_name_list[0]start_length = len(person_first_name) + 1person_last_name = person_name[start_length:]f.write(str(person_last_name) + ', ' + str(person_first_name) + ', ')card_number = person_info[1]employee_id = person_info[2]designation = person_info[3]department = person_info[4]if card_number is not None :f.write(str(card_number) + ', ')else :f.write(', ')if employee_id is not None :f.write(str(employee_id) + ', ')else :f.write(', ')if designation is not None :f.write(str(designation) + ', ')else :f.write(', ')if department is not None :# get department namedepartment_sql = "select `name` from zone where id = " + str(department)cur.execute(department_sql)department_result = cur.fetchone()department_name = department_result[0]f.write(str(department_name))else :f.write(', ')f.write('\n')# if the txt exists, update the textelse :# get original datawith open('add_person.txt', 'r') as e:data = e.readlines()with open('add_person.txt', 'w') as f:# first save the original data for write_data in data :f.write(write_data)# then save new datafor person_info in query_person_info_list :person_name = person_info[0]# the name is generally first + last, which needs to be convertedperson_name_list = person_name.split()person_first_name = person_name_list[0]start_length = len(person_first_name) + 1person_last_name = person_name[start_length:]f.write(str(person_last_name) + ', ' + str(person_first_name) + ', ')card_number = person_info[1]employee_id = person_info[2]designation = person_info[3]department = person_info[4]if card_number is not None :f.write(str(card_number) + ', ')else :f.write(', ')if employee_id is not None :f.write(str(employee_id) + ', ')else :f.write(', ')if designation is not None :f.write(str(designation) + ', ')else :f.write(', ')if department is not None :# get department namedepartment_sql = "select `name` from zone where id = " + str(department)cur.execute(department_sql)department_result = cur.fetchone()department_name = department_result[0]f.write(str(department_name))else :f.write(', ')f.write('\n')except IOError:print('Error: get update person info fail')finally:cur.close()connection.close()if __name__ == '__main__':parser = argparse.ArgumentParser(description="please enter")parser.add_argument("--server_ip", "-server", help="server ip", default="", type=str, required=False)parser.add_argument("--password", "-p", help="devops infra password", default="", type=str, required=False)args = parser.parse_args()# let the variable become a global variable, no need to pass ithandle_variables(args.server_ip, args.password)# execute the method every 30mins#schedule.every(30).minutes.do(get_person_info)# for test -- execute the method every 30 secondsschedule.every(30).seconds.do(get_person_info)while True:# run task schedule.run_pending()   

以上~

http://www.hkea.cn/news/375519/

相关文章:

  • 注册科技有限公司可以做网站吗百度搜索排名机制
  • 武汉做网站好网站制作多少钱一个
  • 安阳网站建设怎么从网上找客户
  • 文章博客媒体网站模板怎样在百度上打广告
  • 做网站是不是要模板直接打开百度
  • 哪个网站做app推广服务商
  • 中国哪里在大建设网站优化培训学校
  • 自己做的网站点首页出错腾讯广告代理商加盟
  • 如何做免费的网站推广东莞百度seo
  • 宜昌网站制作公司百度竞价官网
  • 建站公司网站模板论坛怎么建网站
  • 上海做b2b网站公司深圳公司网络推广该怎么做
  • 自己做的网站怎么在百度可以查到网络小说网站三巨头
  • 怎么做网站客服弹窗站长之家seo工具包
  • 自己建一个电商网站吗网络营销的定义
  • 专门做金融的招聘网站四川seo选哪家
  • wordpress nginx伪静态配置拼多多seo怎么优化
  • 深圳网站开发电话惠州网络营销
  • 中宁网站建设公司商城全网推广运营公司
  • 网站文章列表如何排版郑州seo技术培训班
  • 小型b2c网站百度开户渠道商哪里找
  • 武进区住房和城乡建设局网站爱站网能不能挖掘关键词
  • APP手机端电子商务网站建设营销成功的案例
  • 公司网站引导页百度搜索关键词排名优化技术
  • 网站开发与维护学什么网站建设seo优化培训
  • 常州网站开发百度网盘电脑版官网
  • wordpress安全权限关键词优化公司哪家好
  • 银川做网站服务google play下载安卓
  • 科技型中小企业服务网安徽搜索引擎优化seo
  • 网站建设专家排名邯郸seo营销