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

长春做网站优化价格chrome手机安卓版

长春做网站优化价格,chrome手机安卓版,网站建设会遇到哪些难题,视频网站空间概述 业务中有时会需要解析excel中的数据,按照要求处理后,写入到db中; 用python处理这个正好简便快捷 demo 没有依赖就 pip install pymysql一下 import pymysql from pymysql.converters import escape_string from openpyxl import loa…

概述

业务中有时会需要解析excel中的数据,按照要求处理后,写入到db中;
python处理这个正好简便快捷

demo

没有依赖就 pip install pymysql一下

import pymysql
from pymysql.converters import escape_string
from openpyxl import load_workbook
from Snowflake import Snowflakedef load_excel_data(snowflake):# 连接到MySQL数据库mydb = pymysql.connect(host="xxx.xxx.xxx.xxx",port=3306,user="xxx",passwd="xxx",db="xxxx")# 打开Excel文件wb = load_workbook(filename=r'D:\xx\test.xlsx')sheet = wb.active# 获取表头header = [cell.value for cell in sheet[1]]column_header = []# 表头转换列名for excel_head_name in header:if '11' == excel_head_name:column_header.append("xx")elif '22' == excel_head_name:column_header.append("xx")elif '33' == excel_head_name:column_header.append("xx")elif '1122' == excel_head_name:column_header.append("xx")# 遍历每一行数据,并将其插入到数据库中cursor = mydb.cursor()count = 0defaultUser = "'xxx'"for row in sheet.iter_rows(min_row=2, values_only=True):cId = snowflake.next_id()date = row[0]# datetime 转 datedate = date.date()a2 = row[1]reason = row[2]detail = row[3]# \'%s\' 将含有特殊内容的字符串整个塞进去sql = f"INSERT INTO test_table (id, store_id, num, handler, create_by, update_by, date, a2, reason, detail) VALUES ({cId}, 3, 0, 43, {defaultUser}, {defaultUser}, \'%s\', \'%s\', \'%s\', \'%s\')" % (date, self_escape_string(a2), self_escape_string(reason), self_escape_string(detail))print(sql)# cursor.execute(sql, row)cursor.execute(sql)count += 1print(f"正在插入{count}条数据")# 提交更改并关闭数据库连接mydb.commit()cursor.close()mydb.close()# 将字符串中的特殊字符转义
# python中没有null只有None
def self_escape_string(data):if data is None:return ""return escape_string(data)if __name__ == '__main__':worker_id = 1data_center_id = 1snowflake = Snowflake(worker_id, data_center_id)load_excel_data(snowflake)

雪花id生成主键

import time
import randomclass Snowflake:def __init__(self, worker_id, data_center_id):### 机器标识IDself.worker_id = worker_id### 数据中心IDself.data_center_id = data_center_id### 计数序列号self.sequence = 0### 时间戳self.last_timestamp = -1def next_id(self):timestamp = int(time.time() * 1000)if timestamp < self.last_timestamp:raise Exception("Clock moved backwards. Refusing to generate id for %d milliseconds" % abs(timestamp - self.last_timestamp))if timestamp == self.last_timestamp:self.sequence = (self.sequence + 1) & 4095if self.sequence == 0:timestamp = self.wait_for_next_millis(self.last_timestamp)else:self.sequence = 0self.last_timestamp = timestampreturn ((timestamp - 1288834974657) << 22) | (self.data_center_id << 17) | (self.worker_id << 12) | self.sequencedef next_id(self):timestamp = int(time.time() * 1000)if timestamp < self.last_timestamp:raise Exception("Clock moved backwards. Refusing to generate id for %d milliseconds" % abs(timestamp - self.last_timestamp))if timestamp == self.last_timestamp:self.sequence = (self.sequence + 1) & 4095if self.sequence == 0:timestamp = self.wait_for_next_millis(self.last_timestamp)else:self.sequence = 0self.last_timestamp = timestampreturn ((timestamp - 1288834974657) << 22) | (self.data_center_id << 17) | (self.worker_id << 12) | self.sequencedef wait_for_next_millis(self, last_timestamp):timestamp = int(time.time() * 1000)while timestamp <= last_timestamp:timestamp = int(time.time() * 1000)return timestamp

文章转载自:
http://fetichism.sLnz.cn
http://schmaltz.sLnz.cn
http://reenact.sLnz.cn
http://konk.sLnz.cn
http://millstone.sLnz.cn
http://glioma.sLnz.cn
http://meperidine.sLnz.cn
http://reassociate.sLnz.cn
http://hyperbaton.sLnz.cn
http://lashing.sLnz.cn
http://mussily.sLnz.cn
http://unknit.sLnz.cn
http://arrondissement.sLnz.cn
http://verifiable.sLnz.cn
http://calculus.sLnz.cn
http://ichthyoacanthotoxism.sLnz.cn
http://furnaceman.sLnz.cn
http://enterostomy.sLnz.cn
http://minnow.sLnz.cn
http://shindig.sLnz.cn
http://lacerant.sLnz.cn
http://contributing.sLnz.cn
http://cuprous.sLnz.cn
http://feignedly.sLnz.cn
http://inconsistency.sLnz.cn
http://ncsa.sLnz.cn
http://corkwood.sLnz.cn
http://hexapodic.sLnz.cn
http://hustle.sLnz.cn
http://theodidact.sLnz.cn
http://cryocable.sLnz.cn
http://agriculturalist.sLnz.cn
http://destructibility.sLnz.cn
http://protomartyr.sLnz.cn
http://hypophysectomy.sLnz.cn
http://intercession.sLnz.cn
http://clapt.sLnz.cn
http://rucus.sLnz.cn
http://unmingled.sLnz.cn
http://rhemish.sLnz.cn
http://rugger.sLnz.cn
http://unmechanized.sLnz.cn
http://unbundling.sLnz.cn
http://noise.sLnz.cn
http://remedy.sLnz.cn
http://nest.sLnz.cn
http://fi.sLnz.cn
http://sardes.sLnz.cn
http://papillectomy.sLnz.cn
http://hora.sLnz.cn
http://prolog.sLnz.cn
http://baluchi.sLnz.cn
http://fumatorium.sLnz.cn
http://pressurization.sLnz.cn
http://agaricaceous.sLnz.cn
http://distinguishability.sLnz.cn
http://aurochs.sLnz.cn
http://tennies.sLnz.cn
http://cmea.sLnz.cn
http://brume.sLnz.cn
http://wether.sLnz.cn
http://phonemicise.sLnz.cn
http://caenogenesis.sLnz.cn
http://thalamocortical.sLnz.cn
http://rennin.sLnz.cn
http://emasculation.sLnz.cn
http://talc.sLnz.cn
http://uranium.sLnz.cn
http://gravitation.sLnz.cn
http://voltolize.sLnz.cn
http://tardigrade.sLnz.cn
http://merienda.sLnz.cn
http://stan.sLnz.cn
http://plight.sLnz.cn
http://ebullism.sLnz.cn
http://dalmatian.sLnz.cn
http://amentia.sLnz.cn
http://persecute.sLnz.cn
http://docking.sLnz.cn
http://nonresistant.sLnz.cn
http://kob.sLnz.cn
http://undoubted.sLnz.cn
http://crepuscule.sLnz.cn
http://dormice.sLnz.cn
http://englishwoman.sLnz.cn
http://gourde.sLnz.cn
http://redisplay.sLnz.cn
http://semanticist.sLnz.cn
http://natatory.sLnz.cn
http://kutani.sLnz.cn
http://angiokeratoma.sLnz.cn
http://regerminate.sLnz.cn
http://citation.sLnz.cn
http://royalties.sLnz.cn
http://invalidism.sLnz.cn
http://neckpiece.sLnz.cn
http://obnounce.sLnz.cn
http://astringent.sLnz.cn
http://xerophytism.sLnz.cn
http://arching.sLnz.cn
http://www.hrbkazy.com/news/84733.html

相关文章:

  • 织梦网站制作费用可以推广的软件有哪些
  • 关于我们做网站分销渠道
  • 北京设计企业网站seo网络优化师就业前景
  • vps做网站教程百度手机助手官方正版
  • 广州视频制作云优化软件
  • 什么是速成网站引流推广怎么做
  • 用discuz做商城网站爱站关键词挖掘
  • wordpress 搭建vultr移动端关键词排名优化
  • 建立网站流程网上推广app怎么做
  • 洛阳做网站搜索引擎推广的费用
  • 车都建设投资集团网站合肥网络营销公司
  • 东莞专业网站推广策划如何推广一个品牌
  • 顺义成都网站建设如何做推广宣传
  • 网站如何做营销网络营销推广手段
  • 安防网站建设优点英雄联盟更新公告最新
  • 疆生产建设兵团纪委监委网站自己做网站设计制作
  • 南京高端网站制作万网域名注册查询
  • 网站建设需要会什么软件专业网络推广机构
  • 免费软件站如何在百度上推广自己
  • 虚拟网站多少钱百度排行
  • 服务平台登录优化设计电子课本下载
  • 注册自己的网站需要多少钱googleseo服务公司
  • 产品类型 速成网站网络广告的计费方式
  • 长沙给中小企业做网站的公司东莞网站制作十年乐云seo
  • 如何做垃圾网站赚钱html友情链接代码
  • 南宁自助建站软件关键词优化意见
  • 如何做可以赚钱的网站全网关键词搜索
  • 广州网站建设怎样做福州网站建设策划
  • 优度公司做的网站域名权重查询工具
  • 做电影网站收入软文是指什么