Commit 0951e5ad by 杨林龙

添加脚本

1 parent 79bde267
......@@ -9,3 +9,4 @@
*/__pycache__
*/*.xlsx
fentan_0625_common/*/*.csv
fentan_0707_common/
import logging
import threading
import multiprocessing
import time
import redis
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger('deal_equity_data')
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler('import.log')
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# 创建 Redis 连接对象
r = redis.Redis(host='192.168.3.207', port=6379, db=0, decode_responses=True)
r = redis.Redis(host="192.168.3.207", port=6379, db=0, decode_responses=True)
def deal_redis_data():
# 向 Redis 中写入数据
r.set('mykey', 'Hello Redis!')
r.set("mykey", "Hello Redis!")
# 从 Redis 中读取数据
value = r.get('mykey')
value = r.get("mykey")
# 向 Redis 中写入数据
r.set('mykey01', value)
r.set("mykey01", value)
value = r.get('mykey01')
value = r.get("mykey01")
# 打印读取到的数据
print(value)
......@@ -46,6 +48,40 @@ def my_thread_deal():
thread2.join()
if __name__ == '__main__':
# 第一个函数
def func1():
print("开始执行函数1")
time.sleep(3) # 模拟函数执行耗时
print("函数1执行完毕")
# 第二个函数
def func2():
print("开始执行函数2")
time.sleep(2) # 模拟函数执行耗时
print("函数2执行完毕")
def my_multiprocessing_deal():
# 创建进程
process1 = multiprocessing.Process(target=func1) # 创建第一个进程,目标函数为func1
process2 = multiprocessing.Process(target=func2) # 创建第二个进程,目标函数为func2
# 启动进程
process1.start() # 启动第一个进程
process2.start() # 启动第二个进程
# 等待进程执行完毕
process1.join()
process2.join()
print("所有进程执行完毕")
# end def
if __name__ == "__main__":
# deal_redis_data()
my_thread_deal()
# my_thread_deal()
my_multiprocessing_deal()
import logging
import time
from datetime import datetime
from decimal import Decimal
import MySQLdb
from dateutil.relativedelta import *
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
gps_db_cfg = {
"host": "192.168.5.22",
"port": 3307,
"user": "user_yangll",
"passwd": "vGxw9jWg",
"db": "gps",
"charset": "utf8",
}
bhg_db_cfg = {
"host": "192.168.5.1",
"port": 3307,
"user": "user_yangll",
"passwd": "vGxw9jWg",
"db": "glsx_car_service",
"charset": "utf8",
}
def exportFile(fileName):
gpsbizConn = MySQL(gps_db_cfg)
bhgbizConn = MySQL(bhg_db_cfg)
fileHandle = open(file=fileName, mode="w", encoding="utf-8")
headName = "工单号,车架号,创建时间,审核人"
headName += "\n"
fileHandle.write(headName)
sql = """
SELECT dvw.sqbh ,dvw.standno ,dvw.createtime FROM d_vehicle_workorder dvw
LEFT JOIN d_vehicle dv ON dv.workOrderId = dvw.workOrderId
LEFT JOIN d_class dc ON dc.classid = dv.classId
WHERE dvw.status = 1 AND dv.status = 0
AND dc.vehicleGroupId = 402 AND dvw.createtime >= '2023-05-01';
"""
if not gpsbizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = gpsbizConn.fetchAllRows()
for row in result:
lineValue = f"{row[0]},{row[1]},{str(row[2])}"
sql = f"""
SELECT so.work_order_no ,su.name FROM sys_order so LEFT JOIN sys_user su ON su.id = so.update_by
WHERE so.order_source = 'PAZL' AND so.work_order_no = '{row[0]}';
"""
if not bhgbizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result01 = bhgbizConn.fetchAllRows()
for row01 in result01:
lineValue += f",{row01[1]}"
# 写入一行数据
lineValue += "\n"
logger.debug(lineValue)
fileHandle.write(lineValue)
# 关闭流
fileHandle.close()
def paddstr(strx):
return (
"NULL"
if strx == None
else "'" + MySQLdb.escape_string(str(strx)).decode() + "'"
)
if __name__ == "__main__":
exportFile("平安.csv")
......@@ -282,7 +282,7 @@ if __name__ == '__main__':
# 创建数据表
# BaseCreateTable().create_table()
# 处理基础数据
# deal_equity_data()
deal_equity_data()
# 处理减少数据
# deal_jianshao_equity_data()
# 处理增加数据
......
......@@ -2,11 +2,11 @@ import logging
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger('deal_equity_data')
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler('import.log')
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
......@@ -19,28 +19,33 @@ logger.addHandler(cnslhandler)
# 'db': 'saas_plus',
# 'charset': 'utf8'}
saas_shen_db_cfg = {'host': '192.168.3.222',
'port': 3306,
'user': 'biz_audit',
'passwd': 'hqVIs6jF',
'db': 'saas_shen_ft',
'charset': 'utf8'}
g_pro_biz_dbcfg = {
"host": "192.168.5.2",
"port": 3306,
"user": "biz_glsx_data",
"passwd": "unEKczDc",
"db": "glsx_biz_data",
"charset": "utf8",
}
class BaseCreateTable:
def __init__(self, ft_table='temp_dj_device_details_20230620_settle_record_ft', zj_table='temp_dj_device_details_20230620_settle_record_zj'):
self.bizConn = MySQL(saas_shen_db_cfg)
def __init__(
self,
ft_table="temp_dj_device_details_20230620_settle_record_ft",
zj_table="temp_dj_device_details_20230620_settle_record_zj",
):
self.bizConn = MySQL(g_pro_biz_dbcfg)
self.base_table = ft_table
self.zj_table = zj_table
def create_table(self):
drop_table_sql = f'''
drop_table_sql = f"""
drop table if exists {self.base_table};
'''
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f'''
create_table_sql = f"""
CREATE TABLE `{self.base_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`device_id` int(11) DEFAULT NULL COMMENT '设备表ID',
......@@ -49,15 +54,15 @@ class BaseCreateTable:
PRIMARY KEY (`id`),
KEY `idx_device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='基础分摊表';
'''
"""
self.bizConn.query(create_table_sql)
drop_table_sql = f'''
drop_table_sql = f"""
drop table if exists {self.zj_table};
'''
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f'''
create_table_sql = f"""
CREATE TABLE `{self.zj_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`device_id` int(11) DEFAULT NULL COMMENT '设备表ID',
......@@ -74,10 +79,10 @@ class BaseCreateTable:
PRIMARY KEY (`id`),
KEY `idx_device_id` (`device_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='增减表';
'''
"""
self.bizConn.query(create_table_sql)
if __name__ == '__main__':
if __name__ == "__main__":
my_base = BaseCreateTable()
my_base.create_table()
......@@ -19,12 +19,21 @@ logger.addHandler(cnslhandler)
# 'db': 'saas_plus',
# 'charset': 'utf8'}
# saas_shen_db_cfg = {
# "host": "192.168.3.222",
# "port": 3306,
# "user": "biz_audit",
# "passwd": "hqVIs6jF",
# "db": "saas_shen_ft",
# "charset": "utf8",
# }
saas_shen_db_cfg = {
"host": "192.168.3.222",
"host": "192.168.5.2",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen_ft",
"user": "biz_glsx_data",
"passwd": "unEKczDc",
"db": "glsx_biz_data",
"charset": "utf8",
}
......
import logging
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# saas_shen_db_cfg = {'host': '192.168.5.77',
# 'port': 3306,
# 'user': 'biz_saas_plus',
# 'passwd': 'lOmEudkc',
# 'db': 'saas_plus',
# 'charset': 'utf8'}
# saas_shen_db_cfg = {'host': '192.168.3.35',
# 'port': 3306,
# 'user': 'os_user',
# 'passwd': 'os#123',
# 'db': 'saas_shen',
# 'charset': 'utf8'}
saas_shen_db_cfg = {
"host": "192.168.3.222",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen",
"charset": "utf8",
}
class BaseCreateTable:
def __init__(
self,
base_table="temp_eq_order_20230727_ft",
zj_table="temp_eq_order_20230727_zj",
):
self.bizConn = MySQL(saas_shen_db_cfg)
self.base_table = base_table
self.zj_table = zj_table
def create_table(self):
drop_table_sql = f"""
drop table {self.base_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.base_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`apportionment_date` datetime DEFAULT NULL COMMENT '分摊日期',
`apportionment_price` decimal(12,2) DEFAULT NULL COMMENT '分摊金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='基础分摊表';
"""
self.bizConn.query(create_table_sql)
drop_table_sql = f"""
drop table {self.zj_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.zj_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`order_year` varchar(32) DEFAULT NULL COMMENT '订单年份',
`qichu_num` int(11) DEFAULT NULL COMMENT '期初数量',
`qichu_unit_price` decimal(12,2) DEFAULT NULL COMMENT '期初单价',
`qichu_total_price` decimal(12,2) DEFAULT NULL COMMENT '期初金额',
`zengjia_num` int(11) DEFAULT NULL COMMENT '增加数量',
`zengjia_unit_price` decimal(12,2) DEFAULT NULL COMMENT '增加单价',
`zengjia_total_price` decimal(12,2) DEFAULT NULL COMMENT '增加金额',
`jianshao_num` int(11) DEFAULT NULL COMMENT '减少数量',
`jianshao_unit_price` decimal(12,2) DEFAULT NULL COMMENT '减少单价',
`jianshao_total_price` decimal(12,2) DEFAULT NULL COMMENT '减少金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='增减表';
"""
self.bizConn.query(create_table_sql)
if __name__ == "__main__":
my_base = BaseCreateTable()
my_base.create_table()
def myfunc():
print("你好")
if __name__ == "__main__":
print("你好")
import logging
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# saas_shen_db_cfg = {'host': '192.168.5.77',
# 'port': 3306,
# 'user': 'biz_saas_plus',
# 'passwd': 'lOmEudkc',
# 'db': 'saas_plus',
# 'charset': 'utf8'}
# saas_shen_db_cfg = {'host': '192.168.3.35',
# 'port': 3306,
# 'user': 'os_user',
# 'passwd': 'os#123',
# 'db': 'saas_shen',
# 'charset': 'utf8'}
saas_shen_db_cfg = {
"host": "192.168.3.222",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen",
"charset": "utf8",
}
class BaseCreateTable:
def __init__(
self,
base_table="temp_xwx_eqorder_001_20230804_ft",
zj_table="temp_xwx_eqorder_001_20230804_zj",
):
self.bizConn = MySQL(saas_shen_db_cfg)
self.base_table = base_table
self.zj_table = zj_table
def create_table(self):
drop_table_sql = f"""
drop table {self.base_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.base_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`apportionment_date` datetime DEFAULT NULL COMMENT '分摊日期',
`apportionment_price` decimal(12,2) DEFAULT NULL COMMENT '分摊金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='基础分摊表';
"""
self.bizConn.query(create_table_sql)
drop_table_sql = f"""
drop table {self.zj_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.zj_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`order_year` varchar(32) DEFAULT NULL COMMENT '订单年份',
`qichu_num` int(11) DEFAULT NULL COMMENT '期初数量',
`qichu_unit_price` decimal(12,2) DEFAULT NULL COMMENT '期初单价',
`qichu_total_price` decimal(12,2) DEFAULT NULL COMMENT '期初金额',
`zengjia_num` int(11) DEFAULT NULL COMMENT '增加数量',
`zengjia_unit_price` decimal(12,2) DEFAULT NULL COMMENT '增加单价',
`zengjia_total_price` decimal(12,2) DEFAULT NULL COMMENT '增加金额',
`jianshao_num` int(11) DEFAULT NULL COMMENT '减少数量',
`jianshao_unit_price` decimal(12,2) DEFAULT NULL COMMENT '减少单价',
`jianshao_total_price` decimal(12,2) DEFAULT NULL COMMENT '减少金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='增减表';
"""
self.bizConn.query(create_table_sql)
if __name__ == "__main__":
my_base = BaseCreateTable()
my_base.create_table()
import logging
from itertools import groupby
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# saas_shen_db_cfg = {'host': '192.168.5.77',
# 'port': 3306,
# 'user': 'biz_saas_plus',
# 'passwd': 'lOmEudkc',
# 'db': 'saas_plus',
# 'charset': 'utf8'}
g_pro_biz_dbcfg = {
"host": "192.168.5.2",
"port": 3306,
"user": "biz_glsx_data",
"passwd": "unEKczDc",
"db": "glsx_biz_data",
"charset": "utf8",
}
class Difference:
def __init__(self):
self.bizConn = MySQL(g_pro_biz_dbcfg)
def deal(self):
fileHandle = open(file="差异.txt", mode="w", encoding="utf-8")
sql = """
SELECT settle_merchant,LEFT(settle_time,7),count(1) FROM dj_2021_settle_details WHERE device_type = 8 AND channel = '渠道'
AND LEFT(settle_time,4) = '2023' AND settle_merchant IN (
'成都车亿科技有限公司',
'成都创晟汽车服务有限公司',
'成都福聚盈汽车服务有限公司',
'成都易博鑫科技有限公司',
'赤峰易云信息咨询服务有限责任公司',
'佛山市鑫车汽车服务有限公司',
'甘肃诚利源汽车销售服务有限公司',
'广东盛世创客汽车科技有限公司',
'广西控桂商务信息咨询有限公司',
'广西瑜健连投资有限公司',
'广州盟锐科技发展有限公司',
'贵阳嘉鑫汽车装饰经营部',
'贵州车吉家信息咨询服务有限公司',
'贵州车喜达汽车销售服务有限责任公司',
'哈尔滨诚丰商贸有限公司',
'哈密市名驰汽车服务有限公司',
'杭州佳途实业有限公司',
'杭州天一汽车有限公司',
'河北程尊汽车服务有限公司',
'河北益智康商贸有限公司',
'湖北凯众汽车销售服务有限公司',
'湖北路琥揽星商贸有限公司',
'湖南达阳汽车用品销售有限公司',
'江西乐车林贸易有限公司',
'乐山市城琪汽车销售服务有限公司',
'聊城荣泰网络科技有限公司',
'零售电商客户 ',
'南京趣融网络技术有限公司',
'内蒙古威耀商贸有限公司',
'内蒙古银创投资管理有限公司',
'萍乡市睿宇科技有限公司',
'厦门富创新汽车科技有限公司',
'厦门国戎华汽车销售服务有限公司',
'汕头市卓信汽车服务有限公司',
'上海泓合科技服务有限公司',
'上海联越电子科技有限公司',
'深圳市富恒业科技有限公司',
'沈阳合德祥商贸有限公司',
'四川正通安吉汽车服务有限公司',
'铜仁德恒汽车销售服务有限公司',
'乌鲁木齐市汇享汇融汽车服务有限公司',
'乌鲁木齐玉利金鸿汽车用品有限公司',
'武汉融易租汽车服务有限公司',
'武汉众银信息咨询服务有限公司',
'云南金拓投资有限公司',
'云南行知经济信息咨询服务有限公司',
'长春市鑫车圣汽车用品销售服务有限公司',
'长春沃杰斯汽车科技有限公司',
'郑州汇聚汽车用品有限公司',
'郑州润希汽车服务有限公司',
'重庆车乐道汽车用品有限公司',
'重庆卡达能汽车用品有限公司',
'安徽优盾信息科技有限公司',
'福建省联合车尚贸易有限公司',
'广东优客云汽车科技有限公司',
'杭州电车家汽车科技有限公司',
'杭州交创汽车贸易有限公司',
'吉林市兴孚汽车销售服务有限公司',
'茂名市茂南盈汇汽车贸易有限公司',
'其他',
'深圳市宝旌科技有限公司',
'四川汇鹏兴成汽车服务有限公司',
'天津恺益约车租赁有限公司',
'西藏鸿瑞汽车贸易有限公司',
'北京海韵山峦商贸有限公司',
'合肥望京科技有限公司',
'重庆车生缘商贸有限公司',
'东莞市玖众科技有限责任公司',
'赣州名荣汽车销售服务有限公司',
'杭州禄通科技有限公司',
'三亚百亿鑫实业有限公司',
'石家庄岚申汽车销售有限公司',
'石家庄兴和汽车销售服务有限公司',
'四川众联兴通汽车服务有限公司',
'郑州远之创电子科技有限公司',
'济南新中兴汽车用品有限责任公司',
'重庆雅尚汽车饰品有限公司',
'湖北华瑞智联科技有限公司',
'哈尔滨哈得力金宜汽车销售有限公司',
'衡阳市沪德包装有限公司',
'天津市亿嘉信息技术有限公司',
'森风集团有限公司',
'云南众锐金泉汽车销售有限公司',
'南昌领鑫信息咨询有限公司',
'非常品牌生活文化传播茂名)有限公司 ',
'宁夏吉源辉汽车信息咨询服务有限公司',
'厦门盈鹭通汽车服务有限公司',
'都江堰市速达汽车贸易有限公司',
'上海鲁悦汽车服务有限公司',
'云南鸿超汽车服务有限公司',
'长沙祺捷汽车用品有限公司',
'联通租赁集团有限公司',
'茂鑫实业投资集团有限公司',
'云南众锐汽车服务有限公司',
'贵州林荣汽车装饰服务有限公司',
'哈尔滨市博能汽车销售有限公司',
'遵义市千汇汽车销售服务有限公司',
'贵州林荣汽车贸易股份有限公司',
'合肥云成汽车科技有限公司',
'四川众联晟通国际贸易有限公司',
'大连友联电子有限公司'
) GROUP BY settle_merchant ,LEFT(settle_time,7);
"""
self.bizConn.query(sql)
result01 = self.bizConn.fetchAllRows()
my_customer_big_map = {}
my_dic = [
(key, list(group)) for key, group in groupby(result01, key=get_job_id)
]
for job_id, group_list in my_dic:
my_customer_big_map[job_id] = {
int(i[1].split("-")[1]): i for i in group_list
}
print("my_customer_big_map:", my_customer_big_map)
sql = """
SELECT customer ,settle_202201,settle_202202,settle_202203,settle_202204,settle_202205,settle_202206,settle_202207,settle_202208,settle_202209,settle_202210,settle_202211,settle_202212
FROM dj_2023_direct_cus_active_20231219;
"""
self.bizConn.query(sql)
result = self.bizConn.fetchAllRows()
for item in result:
# print(item)
month_list = my_customer_big_map.get(item[0])
# print("month_list===", month_list)
for key in range(12):
value = item[key + 1]
if int(value) == 0:
continue
print(item[0], ":", key + 1, "月===", item[key + 1])
if month_list is not None:
if month_list.get(key + 1) is not None:
print(
item[0],
":",
"month_list:",
key + 1,
"月===",
month_list.get(key + 1)[2],
)
if int(month_list.get(key + 1)[2]) != int(item[key + 1]):
print(month_list.get(key + 1)[2], item[key + 1])
fileHandle.write(
f"{item[0]},{key + 1}月,{item[key + 1]},{month_list.get(key + 1)[2]} "
)
fileHandle.write("\n")
print("不相等")
else:
fileHandle.write(f"{item[0]},{key + 1}月,{item[key + 1]},无 ")
fileHandle.write("\n")
print("不相等")
# 关闭流
fileHandle.close()
def get_job_id(job_info_data):
return job_info_data[0]
if __name__ == "__main__":
my_difference = Difference()
my_difference.deal()
成都车亿科技有限公司,8月,92,184
成都车亿科技有限公司,9月,116,232
成都易博鑫科技有限公司,3月,-55,无
广东盛世创客汽车科技有限公司,3月,-6,无
广东盛世创客汽车科技有限公司,5月,-4,无
广东盛世创客汽车科技有限公司,6月,-107,无
广州盟锐科技发展有限公司,2月,-18,无
广州盟锐科技发展有限公司,4月,-34,无
广州盟锐科技发展有限公司,6月,-48,无
广州盟锐科技发展有限公司,8月,-5,无
哈尔滨诚丰商贸有限公司,6月,-70,无
南京趣融网络技术有限公司,6月,15,35
南京趣融网络技术有限公司,8月,16,32
南京趣融网络技术有限公司,9月,66,132
厦门富创新汽车科技有限公司,8月,15,30
乌鲁木齐玉利金鸿汽车用品有限公司,8月,500,1000
郑州汇聚汽车用品有限公司,8月,8,16
重庆卡达能汽车用品有限公司,8月,100,200
安徽优盾信息科技有限公司,2月,50,无
其他,1月,130,无
其他,2月,140,无
其他,5月,5,无
其他,8月,-34,无
四川汇鹏兴成汽车服务有限公司,5月,-378,100
四川汇鹏兴成汽车服务有限公司,9月,400,800
石家庄兴和汽车销售服务有限公司,8月,5,10
石家庄兴和汽车销售服务有限公司,9月,1,2
四川众联兴通汽车服务有限公司,5月,200,300
四川众联兴通汽车服务有限公司,9月,1000,2000
济南新中兴汽车用品有限责任公司,1月,30,无
济南新中兴汽车用品有限责任公司,3月,120,无
济南新中兴汽车用品有限责任公司,4月,50,无
济南新中兴汽车用品有限责任公司,5月,70,无
济南新中兴汽车用品有限责任公司,6月,52,无
济南新中兴汽车用品有限责任公司,7月,51,无
济南新中兴汽车用品有限责任公司,8月,102,无
济南新中兴汽车用品有限责任公司,9月,130,无
济南新中兴汽车用品有限责任公司,10月,52,无
济南新中兴汽车用品有限责任公司,11月,131,无
非常品牌生活文化传播(茂名)有限公司,2月,10,无
非常品牌生活文化传播(茂名)有限公司,9月,10,无
联通租赁集团有限公司,1月,27,无
联通租赁集团有限公司,2月,8,无
联通租赁集团有限公司,3月,62,无
联通租赁集团有限公司,4月,266,无
联通租赁集团有限公司,5月,753,无
联通租赁集团有限公司,6月,402,无
联通租赁集团有限公司,7月,164,无
联通租赁集团有限公司,8月,112,无
联通租赁集团有限公司,9月,116,无
联通租赁集团有限公司,10月,40,无
联通租赁集团有限公司,11月,126,无
茂鑫实业投资集团有限公司,1月,11,无
茂鑫实业投资集团有限公司,2月,4,无
茂鑫实业投资集团有限公司,3月,6,无
茂鑫实业投资集团有限公司,4月,4,无
茂鑫实业投资集团有限公司,5月,4,无
茂鑫实业投资集团有限公司,6月,1,无
贵州林荣汽车装饰服务有限公司,2月,100,无
贵州林荣汽车装饰服务有限公司,4月,2,无
贵州林荣汽车装饰服务有限公司,5月,100,无
贵州林荣汽车装饰服务有限公司,6月,-102,无
哈尔滨市博能汽车销售有限公司,2月,100,无
哈尔滨市博能汽车销售有限公司,3月,100,无
哈尔滨市博能汽车销售有限公司,4月,100,无
哈尔滨市博能汽车销售有限公司,5月,100,无
哈尔滨市博能汽车销售有限公司,6月,100,无
哈尔滨市博能汽车销售有限公司,7月,100,无
哈尔滨市博能汽车销售有限公司,8月,100,无
哈尔滨市博能汽车销售有限公司,9月,100,无
哈尔滨市博能汽车销售有限公司,10月,100,无
哈尔滨市博能汽车销售有限公司,11月,100,无
合肥云成汽车科技有限公司,9月,20,40
四川众联晟通国际贸易有限公司,9月,200,400
This file is too large to display.
# -*- coding:utf-8 -*-
from __future__ import print_function
import time
import MySQLdb
import pymysql
pymysql.install_as_MySQLdb()
from pymysql.converters import escape_string
#
def paddstr(strx):
return "NULL" if strx == None else "\'" + escape_string(str(strx))+ "\'"
def paddnum(numx, default='NULL'):
return default if numx == None else str(numx)
class MySQL:
u'''对MySQLdb常用函数进行封装的类'''
error_code = '' # MySQL错误号码
_instance = None # 本类的实例
_conn = None # 数据库conn
_cur = None # 游标
_TIMEOUT = 30 # 默认超时30秒
_timecount = 0
def __init__(self, dbconfig):
u'构造器:根据数据库连接参数,创建MySQL连接'
try:
self._conn = MySQLdb.connect(host=dbconfig['host'],
port=dbconfig['port'],
user=dbconfig['user'],
passwd=dbconfig['passwd'],
db=dbconfig['db'],
charset=dbconfig['charset'])
except MySQLdb.Error as e:
self.error_code = e.args[0]
error_msg = 'MySQL error! ', e.args[0], e.args[1]
print(error_msg)
# 如果没有超过预设超时时间,则再次尝试连接,
if self._timecount < self._TIMEOUT:
interval = 5
self._timecount += interval
time.sleep(interval)
return self.__init__(dbconfig)
else:
raise Exception(error_msg)
self._cur = self._conn.cursor()
self._instance = MySQLdb
def query(self, sql):
u'执行 SELECT 语句'
try:
# self._cur.execute("SET NAMES utf8")
result = self._cur.execute(sql)
result = True
except MySQLdb.Error as e:
self.error_code = e.args[0]
print("数据库错误代码:", e.args[0], e.args[1])
result = False
return result
def update(self, sql):
u'执行 UPDATE 及 DELETE 语句'
try:
# self._cur.execute("SET NAMES utf8")
result = self._cur.execute(sql)
self._conn.commit()
result = True
except MySQLdb.Error as e:
self.error_code = e.args[0]
print("数据库错误代码:", e.args[0], e.args[1])
result = False
return result
def insert(self, sql, data=None):
u'执行 INSERT 语句。如主键为自增长int,则返回新生成的ID'
try:
self._cur.execute("SET NAMES utf8")
if data == None:
self._cur.execute(sql)
else:
self._cur.executemany(sql, data)
self._conn.commit()
return True
return self._conn.insert_id()
except MySQLdb.Error as e:
self.error_code = e.args[0]
return False
def callproc(self, procname, *arg):
try:
self._cur.execute("SET NAMES utf8")
self._cur.callproc(procname, arg)
self._conn.commit()
result = True
except MySQLdb.Error as e:
self.error_code = e.args[0]
print("数据库错误代码:", e.args[0], e.args[1])
result = False
return result
def fetchAllRows(self):
u'返回结果列表'
return self._cur.fetchall()
def fetchOneRow(self):
u'返回一行结果,然后游标指向下一行。到达最后一行以后,返回None'
return self._cur.fetchone()
def getRowCount(self):
u'获取结果行数'
return self._cur.rowcount
def commit(self):
u'数据库commit操作'
self._conn.commit()
def rollback(self):
u'数据库回滚操作'
self._conn.rollback()
def __del__(self):
u'释放资源(系统GC自动调用)'
try:
self._cur.close()
self._conn.close()
except:
pass
def close(self):
u'关闭数据库连接'
self.__del__()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!