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

怎样做免费抽皮肤的网站博客营销案例

怎样做免费抽皮肤的网站,博客营销案例,洛阳做网站公司地址,深圳手机网站建设概述 业务中有时会需要解析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://www.hkea.cn/news/309485/

相关文章:

  • 徐州有哪些做网站苏州网站建设费用
  • 统一企业信息管理系统网站直通车怎么开效果最佳
  • 武汉外贸网站建设公司外链相册
  • java做网站的权限管理seo描述是什么
  • 招聘网最新招聘信息网武汉seo计费管理
  • 直播软件开发源码重庆seo顾问
  • 公司网站如何做宣传百度视频推广怎么收费
  • 淄博市 网站建设报价郑州seo外包阿亮
  • 网络服务商是指什么网站优化排名工具
  • 网站优化的分析比较好的品牌策划公司有哪些
  • 国外比较好的资源网站电商运营推广是做什么的
  • 佛山房地产网站建设seo实战培训王乃用
  • 如何做可以赚钱的网站关键词如何快速排名
  • 深圳品牌做网站公司有哪些百度app推广
  • 重庆建设行业信息网站搜狗登录入口
  • 同仁行业网站建设报价北京做的好的seo公司
  • 陕西自助建站做网站郑州外语网站建站优化
  • 小型企业网站系统cilimao磁力猫最新版地址
  • 铁岭网站建设移动网站广东网站seo
  • 网站模板插件sem和seo
  • 用wordpress制作网站模板沈阳seo
  • 优化一个网站多少钱宜昌网站seo
  • 刚做的网站怎么才能搜索到枸橼酸西地那非片功效效及作用
  • 罗湖区网站公司专业模板建站
  • 哪有备案好的网站国产系统2345
  • 网站开发怎么让别人看到最新营销模式有哪些
  • ssm网站开发源码百度推广多少钱一个月
  • 手游门户网站建设appstore关键词优化
  • 齐河网站开发seo服务内容
  • 北京微信网站建设费用想卖产品怎么推广宣传