fix build problem

This commit is contained in:
XiongNeng
2015-09-21 09:36:33 +08:00
parent d846cce1f7
commit 270e1486f5
4 changed files with 223 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import os
if __name__ == '__main__':
print('----start----')
print('aaa;'[:-1])
aa = {"1", 2}
print("aaa='{}','{}'".format(*aa))
print("a'a'a'".replace("'", ";"))

View File

@@ -0,0 +1,84 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Topic: 检查企业数据哪些已经在我们数据库里面
"""
import sys
import copy
import logging
import datetime
import mysql.connector
from mysql.connector import errorcode
# 查询航信CRM表
sql_select_name = """
SELECT COUNT(*) FROM t_crm_company
WHERE cust_name='{}' OR cust_tax_name='{}';
"""
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[logging.FileHandler('d:/logs/merge_table.log', 'a', 'utf-8')])
_log = logging.getLogger('app.' + __name__)
def _connect():
config = {
'user': 'root',
'password': 'mysql',
'host': '192.168.203.95',
'database': 'fastloan_test',
'raise_on_warnings': True,
}
cnx = None
try:
cnx = mysql.connector.connect(**config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
if cnx:
cnx.close()
return cnx
def check_table():
conn_ = _connect()
_log.info('---------------------------分割线-----------------------------')
cursor = conn_.cursor()
data_yes = []
data_no = []
for idx in [1, 2, 3]:
data_file = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}.txt'.format(idx)
data_file_y = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}y.txt'.format(idx)
data_file_n = r'D:\work\projects\gitprojects\python3-cookbook\basic\samples\excel\data{}n.txt'.format(idx)
with open(data_file, encoding='utf-8') as f:
for tline in f:
tline = tline.strip()
if tline:
cursor.execute(sql_select_name.format(tline, tline))
count_num = cursor.fetchone()[0]
if count_num > 0:
data_yes.append(tline + "\n")
else:
data_no.append(tline + "\n")
with open(data_file_y, mode='w', encoding='utf-8') as f:
f.writelines(data_yes)
with open(data_file_n, mode='w', encoding='utf-8') as f:
f.writelines(data_no)
data_yes.clear()
data_no.clear()
cursor.close()
conn_.close()
if __name__ == '__main__':
check_table()
pass

View File

@@ -0,0 +1,135 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Topic: mysql数据表结构和数据合并
Desc : 有两个表航信CRM企业表t_crm_company税局企业资料表t_tax_company
现在需要将其记录合并,使用税号和名称组合来作为唯一性标识
"""
import sys
import copy
import logging
import datetime
import mysql.connector
from mysql.connector import errorcode
# 查询航信CRM表
sql_select_taxcode_name = """
SELECT DISTINCT cust_tax_code,cust_name
FROM t_crm_company
WHERE update_time IS NULL OR update_time < '{}';
"""
# 通过税号和名称查询税局表中记录
sql_select_tax_info = """
SELECT
legal_person,
business_scope,
reg_code,
tax_number,
cust_tax_name,
addr,
reg_type,
tax_institution,
duty,
is_back_taxes,
is_overdue,
status,
valid_st_date,
qualification_nm,
business,
notes
FROM t_tax_company
WHERE cust_tax_code='{}' AND cust_name='{}' AND (notes is NULL OR notes<>'税号无效')
LIMIT 1;
"""
# 将税局的数据更新到航信表中
sql_update_crm = """
UPDATE t_crm_company
SET
legal_person={},
business_scope={},
reg_code={},
tax_number={},
cust_tax_name={},
addr={},
reg_type={},
tax_institution={},
duty={},
is_back_taxes={},
is_overdue={},
status={},
valid_st_date={},
qualification_nm={},
business={},
tax_notes={},
update_time=now()
WHERE cust_tax_code='{}' AND cust_name='{}'
"""
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[logging.FileHandler('d:/logs/merge_table.log', 'a', 'utf-8')])
_log = logging.getLogger('app.' + __name__)
def _connect():
config = {
'user': 'root',
'password': 'mysql',
'host': '192.168.203.95',
'database': 'fastloan_test',
'raise_on_warnings': True,
}
cnx = None
try:
cnx = mysql.connector.connect(**config)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
if cnx:
cnx.close()
return cnx
def merge_table():
conn_ = _connect()
_log.info('---------------------------分割线-----------------------------')
_log.info('数据库更新start')
cursor = conn_.cursor()
cursor.execute(sql_select_taxcode_name.format('2015-09-10 00:00:00'))
code_names = [list(r) for r in cursor.fetchall()]
_log.info("待更新数据量大小为:{}".format(len(code_names)))
_log.info('合并企业资料start')
for i, d2 in enumerate(code_names):
try:
cursor.execute(sql_select_tax_info.format(d2[0], d2[1]))
each_record = cursor.fetchone()
if each_record:
u_list = [ "'{}'".format(r.replace("'", ";")) if r else 'null' for r in each_record]
u_list.extend([d2[0], d2[1]])
cursor.execute(sql_update_crm.format(*u_list))
except:
_log.error('--合并企业资料Exception,taxcode={},name={}--'.format(d2[0], d2[1]))
cursor.close()
conn_.rollback()
conn_.close()
return
if i % 50 == 0:
_log.info("更新下标...i={}".format(i))
conn_.commit()
conn_.commit()
_log.info('合并企业资料end')
_log.info('数据库更新end')
cursor.close()
conn_.close()
if __name__ == '__main__':
merge_table()
pass

View File

@@ -1,4 +1,4 @@
PIL==1.1.6
PIL==1.1.7
greenlet==0.4.5
gunicorn==19.1.1
oauthlib==0.7.2