Skip to content

Commit 270e148

Browse files
committed
fix build problem
1 parent d846cce commit 270e148

File tree

4 files changed

+223
-3
lines changed

4 files changed

+223
-3
lines changed

basic/maintest.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
if __name__ == '__main__':
11-
print('----start----')
12-
print('aaa;'[:-1])
11+
aa = {"1", 2}
12+
print("aaa='{}','{}'".format(*aa))
13+
print("a'a'a'".replace("'", ";"))
1314

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: 检查企业数据哪些已经在我们数据库里面
5+
"""
6+
import sys
7+
import copy
8+
9+
import logging
10+
import datetime
11+
import mysql.connector
12+
from mysql.connector import errorcode
13+
14+
# 查询航信CRM表
15+
sql_select_name = """
16+
SELECT COUNT(*) FROM t_crm_company
17+
WHERE cust_name='{}' OR cust_tax_name='{}';
18+
"""
19+
20+
logging.basicConfig(level=logging.INFO,
21+
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
22+
datefmt='%Y-%m-%d %H:%M:%S',
23+
handlers=[logging.FileHandler('d:/logs/merge_table.log', 'a', 'utf-8')])
24+
_log = logging.getLogger('app.' + __name__)
25+
26+
27+
def _connect():
28+
config = {
29+
'user': 'root',
30+
'password': 'mysql',
31+
'host': '192.168.203.95',
32+
'database': 'fastloan_test',
33+
'raise_on_warnings': True,
34+
}
35+
cnx = None
36+
try:
37+
cnx = mysql.connector.connect(**config)
38+
except mysql.connector.Error as err:
39+
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
40+
print("Something is wrong with your user name or password")
41+
elif err.errno == errorcode.ER_BAD_DB_ERROR:
42+
print("Database does not exist")
43+
else:
44+
print(err)
45+
if cnx:
46+
cnx.close()
47+
return cnx
48+
49+
50+
def check_table():
51+
conn_ = _connect()
52+
_log.info('---------------------------分割线-----------------------------')
53+
cursor = conn_.cursor()
54+
55+
data_yes = []
56+
data_no = []
57+
for idx in [1, 2, 3]:
58+
data_file = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}.txt'.format(idx)
59+
data_file_y = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}y.txt'.format(idx)
60+
data_file_n = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}n.txt'.format(idx)
61+
with open(data_file, encoding='utf-8') as f:
62+
for tline in f:
63+
tline = tline.strip()
64+
if tline:
65+
cursor.execute(sql_select_name.format(tline, tline))
66+
count_num = cursor.fetchone()[0]
67+
if count_num > 0:
68+
data_yes.append(tline + "\n")
69+
else:
70+
data_no.append(tline + "\n")
71+
with open(data_file_y, mode='w', encoding='utf-8') as f:
72+
f.writelines(data_yes)
73+
with open(data_file_n, mode='w', encoding='utf-8') as f:
74+
f.writelines(data_no)
75+
data_yes.clear()
76+
data_no.clear()
77+
78+
cursor.close()
79+
conn_.close()
80+
81+
82+
if __name__ == '__main__':
83+
check_table()
84+
pass
+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: mysql数据表结构和数据合并
5+
Desc : 有两个表,航信CRM企业表t_crm_company,税局企业资料表t_tax_company,
6+
现在需要将其记录合并,使用税号和名称组合来作为唯一性标识
7+
"""
8+
import sys
9+
import copy
10+
11+
import logging
12+
import datetime
13+
import mysql.connector
14+
from mysql.connector import errorcode
15+
16+
# 查询航信CRM表
17+
sql_select_taxcode_name = """
18+
SELECT DISTINCT cust_tax_code,cust_name
19+
FROM t_crm_company
20+
WHERE update_time IS NULL OR update_time < '{}';
21+
"""
22+
# 通过税号和名称查询税局表中记录
23+
sql_select_tax_info = """
24+
SELECT
25+
legal_person,
26+
business_scope,
27+
reg_code,
28+
tax_number,
29+
cust_tax_name,
30+
addr,
31+
reg_type,
32+
tax_institution,
33+
duty,
34+
is_back_taxes,
35+
is_overdue,
36+
status,
37+
valid_st_date,
38+
qualification_nm,
39+
business,
40+
notes
41+
FROM t_tax_company
42+
WHERE cust_tax_code='{}' AND cust_name='{}' AND (notes is NULL OR notes<>'税号无效')
43+
LIMIT 1;
44+
"""
45+
# 将税局的数据更新到航信表中
46+
sql_update_crm = """
47+
UPDATE t_crm_company
48+
SET
49+
legal_person={},
50+
business_scope={},
51+
reg_code={},
52+
tax_number={},
53+
cust_tax_name={},
54+
addr={},
55+
reg_type={},
56+
tax_institution={},
57+
duty={},
58+
is_back_taxes={},
59+
is_overdue={},
60+
status={},
61+
valid_st_date={},
62+
qualification_nm={},
63+
business={},
64+
tax_notes={},
65+
update_time=now()
66+
WHERE cust_tax_code='{}' AND cust_name='{}'
67+
"""
68+
69+
logging.basicConfig(level=logging.INFO,
70+
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
71+
datefmt='%Y-%m-%d %H:%M:%S',
72+
handlers=[logging.FileHandler('d:/logs/merge_table.log', 'a', 'utf-8')])
73+
_log = logging.getLogger('app.' + __name__)
74+
75+
76+
def _connect():
77+
config = {
78+
'user': 'root',
79+
'password': 'mysql',
80+
'host': '192.168.203.95',
81+
'database': 'fastloan_test',
82+
'raise_on_warnings': True,
83+
}
84+
cnx = None
85+
try:
86+
cnx = mysql.connector.connect(**config)
87+
except mysql.connector.Error as err:
88+
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
89+
print("Something is wrong with your user name or password")
90+
elif err.errno == errorcode.ER_BAD_DB_ERROR:
91+
print("Database does not exist")
92+
else:
93+
print(err)
94+
if cnx:
95+
cnx.close()
96+
return cnx
97+
98+
99+
def merge_table():
100+
conn_ = _connect()
101+
_log.info('---------------------------分割线-----------------------------')
102+
_log.info('数据库更新start')
103+
cursor = conn_.cursor()
104+
cursor.execute(sql_select_taxcode_name.format('2015-09-10 00:00:00'))
105+
code_names = [list(r) for r in cursor.fetchall()]
106+
_log.info("待更新数据量大小为:{}".format(len(code_names)))
107+
108+
_log.info('合并企业资料start')
109+
for i, d2 in enumerate(code_names):
110+
try:
111+
cursor.execute(sql_select_tax_info.format(d2[0], d2[1]))
112+
each_record = cursor.fetchone()
113+
if each_record:
114+
u_list = [ "'{}'".format(r.replace("'", ";")) if r else 'null' for r in each_record]
115+
u_list.extend([d2[0], d2[1]])
116+
cursor.execute(sql_update_crm.format(*u_list))
117+
except:
118+
_log.error('--合并企业资料Exception,taxcode={},name={}--'.format(d2[0], d2[1]))
119+
cursor.close()
120+
conn_.rollback()
121+
conn_.close()
122+
return
123+
if i % 50 == 0:
124+
_log.info("更新下标...i={}".format(i))
125+
conn_.commit()
126+
conn_.commit()
127+
_log.info('合并企业资料end')
128+
_log.info('数据库更新end')
129+
cursor.close()
130+
conn_.close()
131+
132+
133+
if __name__ == '__main__':
134+
merge_table()
135+
pass

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PIL==1.1.6
1+
PIL==1.1.7
22
greenlet==0.4.5
33
gunicorn==19.1.1
44
oauthlib==0.7.2

0 commit comments

Comments
 (0)