提交 6a49a9de 作者: 薛凌堃

经营分析脚本维护

上级 b127603f
import pymysql import pymysql
...@@ -8,6 +8,8 @@ import time ...@@ -8,6 +8,8 @@ import time
import numpy as np import numpy as np
import json import json
import datetime import datetime
import sys
sys.path.append('D:\\KK\\zzsn_spider\\base')
import BaseCore import BaseCore
baseCore = BaseCore.BaseCore() baseCore = BaseCore.BaseCore()
log = baseCore.getLogger() log = baseCore.getLogger()
...@@ -63,7 +65,7 @@ def operate_analysis(i,com_code,social_code): ...@@ -63,7 +65,7 @@ def operate_analysis(i,com_code,social_code):
list_category.append('按产品分类') list_category.append('按产品分类')
if one_info['MAINOP_TYPE'] == '3': if one_info['MAINOP_TYPE'] == '3':
list_category.append('按地区分类') list_category.append('按地区分类')
select_sql = f'''select stock_code from operation_analysis_copy1 where stock_code = %s and date = '{one_info['REPORT_DATE'][:10]}' ''' select_sql = f'''select stock_code from operation_analysis where stock_code = %s and date = '{one_info['REPORT_DATE'][:10]}' '''
y = cursor.execute(select_sql, com_code[2:]) y = cursor.execute(select_sql, com_code[2:])
if y: if y:
i += 1 i += 1
...@@ -157,34 +159,55 @@ def operate_analysis(i,com_code,social_code): ...@@ -157,34 +159,55 @@ def operate_analysis(i,com_code,social_code):
print(f'{com_code}',response.text) print(f'{com_code}',response.text)
except Exception as e: except Exception as e:
print(e) print(e)
log.info(f'数据疑似有重复===={com_code}')
send_end = time.time() send_end = time.time()
log.info(f'{com_code} 传入接口用时:{send_end-send_start}') log.info(f'{com_code} 传入接口用时:{send_end-send_start}')
return com_code,list_code, list_zygc, list_income,list_income_sca, list_chengben, list_chengben_sca, list_lirun, list_lirun_sca, list_maolilv, list_time,list_category return com_code,list_code, list_zygc, list_income,list_income_sca, list_chengben, list_chengben_sca, list_lirun, list_lirun_sca, list_maolilv, list_time,list_category
else: else:
return return
df_all = pd.read_excel('D:/kkwork/zzsn_spider/data/上市企业(有财务数据)清单.xlsx',dtype=str) # df_all = pd.read_excel('D:/kkwork/zzsn_spider/data/上市企业(有财务数据)清单.xlsx',dtype=str)
list_non = [] list_non = []
i = 1 i = 1
while True: while True:
if i>=len(df_all): # 从redis中获取企业信用代码
log.info('采集已完成') social_code = baseCore.redicPullData('Jingyingfenxi:finance_socialCode')
break # if i>=len(df_all):
start_time = time.time() # log.info('采集已完成')
com_code_ = df_all['股票代码'][i] # break
social_code = df_all['信用代码'][i] # start_time = time.time()
num = len(com_code_) # com_code_ = df_all['股票代码'][i]
if 'HK' in com_code_: # social_code = df_all['信用代码'][i]
# num = len(com_code_)
if social_code == None or social_code == 'None':
log.info('======已没有数据==========等待=====')
time.sleep(20)
if baseCore.check_mysql_conn(cnx):
cnx = baseCore.cnx_
cursor = baseCore.cursor_
sql_sel = f'''select securities_code,exchange from sys_base_enterprise_ipo where exchange = '1' or exchange = '2' or exchange = '3' and listed = '1' and social_credit_code='{social_code}' '''
cursor.execute(sql_sel)
row = cursor.fetchone()
try:
securities_code = row[0]
pass
except:
log.info(f'======{social_code}没有股票代码======')
continue
exchange = row[1]
num = len(securities_code)
if 'HK' in securities_code:
# com_code = com_code_.split('.')[0] # com_code = com_code_.split('.')[0]
i+=1 i+=1
continue continue
else: else:
if num != 6: if num != 6:
com_code1 = '0' * (6 - num) + com_code_ com_code1 = '0' * (6 - num) + securities_code
else: else:
com_code1 = com_code_ com_code1 = securities_code
# 股票代码0、2、3开头的为深圳交易所,6、9开头的为上海交易所,8开头的为北京交易所 # 股票代码0、2、3开头的为深圳交易所,6、9开头的为上海交易所,8开头的为北京交易所
if com_code1[0] == '2' or com_code1[0] == '0' or com_code1[0] == '3': if com_code1[0] == '2' or com_code1[0] == '0' or com_code1[0] == '3':
com_code = 'sz' + com_code1 com_code = 'sz' + com_code1
...@@ -193,7 +216,7 @@ while True: ...@@ -193,7 +216,7 @@ while True:
elif com_code1[0] == '8' or com_code1[0] == '4': elif com_code1[0] == '8' or com_code1[0] == '4':
com_code = 'bj' + com_code1 com_code = 'bj' + com_code1
else: else:
log.error(f'{com_code_},{social_code}:无法获取正确的股票代码!') log.error(f'{securities_code},{social_code}:无法获取正确的股票代码!')
list_updata = [] list_updata = []
# # 判断该条信息是否已经采集过 # # 判断该条信息是否已经采集过
# select_sql = '''select stock_code from operation_analysis_copy1 where stock_code = %s''' # select_sql = '''select stock_code from operation_analysis_copy1 where stock_code = %s'''
...@@ -310,6 +333,6 @@ while True: ...@@ -310,6 +333,6 @@ while True:
# end_time = time.time() # end_time = time.time()
# log.info(f'企业经营分析采集用时:{end_time-start_time}') # log.info(f'企业经营分析采集用时:{end_time-start_time}')
break # break
# df_non = pd.DataFrame(list_non) # df_non = pd.DataFrame(list_non)
# df_non.to_excel('无经营分析数据企业.xlsx',index=False) # df_non.to_excel('无经营分析数据企业.xlsx',index=False)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论