refactor: 🎉 refactor code

main
jackluson 3 years ago
parent 26bdf10b93
commit 78a429abe8

@ -0,0 +1,18 @@
代码,晨星专属号,名称,类型,页码,备注
000889, 0P00014ZLM, 上投摩根纯债添利债券 - A, 普通债券型基金, 0, 页面跳转有问题
001683, 0P00016DLP, 华夏新经济灵活配置混合, 灵活配置型基金, 0, 页面跳转有问题
001769, 0P00016GJM, 易方达瑞惠灵活配置混合, 灵活配置型基金, 0, 页面跳转有问题
159963, 0P0001F572, 富国恒生中国企业ETF, 普通股票型, 10, 页面跳转有问题
160136, 0P000162QH, 南方中证国有企业改革指数LOFA, 普通股票型, 10, 页面跳转有问题
160142, 0P0001DI3W, 南方3年封闭运作战略配售灵活配置混合(LOF), 灵活配置型基金(封闭), 10, 页面跳转有问题
161131, 0P0001DI3T, 易方达3年封闭运作战略配售灵活配置混合LOF), 灵活配置型基金(封闭), 10, 页面跳转有问题
161629, 0P00016C35, 融通中证精准医疗主题指数LOF, 行业股票 - 医药, 10, 页面跳转有问题
161728, 0P0001DI3Y, 招商3年封闭运作战略配售灵活配置混合(LOF), 灵活配置型基金(封闭), 10, 页面跳转有问题
168108, 0P0001H50O, 九泰锐诚灵活配置混合LOF, 灵活配置型基金, 10, 页面跳转有问题
370021, 0P0000W4FQ, 上投摩根分红添利债券 - A, 普通债券型基金, 10, 页面跳转有问题
501186, 0P0001DI3X, 华夏3年封闭运作战略配售灵活配置混合(LOF), 灵活配置型基金(封闭), 20, 页面跳转有问题
501188, 0P0001DI3U, 汇添富3年封闭运作战略配售灵活配置混合LOF, 灵活配置型基金(封闭), 20, 页面跳转有问题
501189, 0P0001DI3V, 嘉实3年封闭运作战略配售灵活配置混合(LOF), 灵活配置型基金(封闭), 20, 页面跳转有问题
512340, 0P00015KX3, 南方中证500原材料指数ETF, 普通股票型, 20, 页面跳转有问题
512860, 0P0001E1FC, 华安MSCI中国A股国际ETF, 普通股票型, 20, 页面跳转有问题
515620, 0P0001JF1J, 建信中证800ETF, 普通股票型, 20, 页面跳转有问题
1 代码 晨星专属号 名称 类型 页码 备注
2 000889 0P00014ZLM 上投摩根纯债添利债券 - A 普通债券型基金 0 页面跳转有问题
3 001683 0P00016DLP 华夏新经济灵活配置混合 灵活配置型基金 0 页面跳转有问题
4 001769 0P00016GJM 易方达瑞惠灵活配置混合 灵活配置型基金 0 页面跳转有问题
5 159963 0P0001F572 富国恒生中国企业ETF 普通股票型 10 页面跳转有问题
6 160136 0P000162QH 南方中证国有企业改革指数(LOF)A 普通股票型 10 页面跳转有问题
7 160142 0P0001DI3W 南方3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 10 页面跳转有问题
8 161131 0P0001DI3T 易方达3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 10 页面跳转有问题
9 161629 0P00016C35 融通中证精准医疗主题指数(LOF) 行业股票 - 医药 10 页面跳转有问题
10 161728 0P0001DI3Y 招商3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 10 页面跳转有问题
11 168108 0P0001H50O 九泰锐诚灵活配置混合(LOF) 灵活配置型基金 10 页面跳转有问题
12 370021 0P0000W4FQ 上投摩根分红添利债券 - A 普通债券型基金 10 页面跳转有问题
13 501186 0P0001DI3X 华夏3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 20 页面跳转有问题
14 501188 0P0001DI3U 汇添富3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 20 页面跳转有问题
15 501189 0P0001DI3V 嘉实3年封闭运作战略配售灵活配置混合(LOF) 灵活配置型基金(封闭) 20 页面跳转有问题
16 512340 0P00015KX3 南方中证500原材料指数ETF 普通股票型 20 页面跳转有问题
17 512860 0P0001E1FC 华安MSCI中国A股国际ETF 普通股票型 20 页面跳转有问题
18 515620 0P0001JF1J 建信中证800ETF 普通股票型 20 页面跳转有问题

@ -13,21 +13,15 @@ import math
from threading import Thread, Lock, current_thread
from time import sleep, time
from pprint import pprint
import pandas
from db.connect import connect
from fund_info.crawler import FundSpider
from fund_info.api import FundApier
from fund_info.csv import FundCSV
from lib.mysnowflake import IdWorker
from utils.login import login_morning_star
from utils.index import bootstrap_thread
from sql_model.fund_query import FundQuery
from sql_model.fund_insert import FundInsert
connect_instance = connect()
cursor = connect_instance.cursor()
lock = Lock()
# 利用api获取同类基金的资产
@ -37,29 +31,22 @@ def get_total_asset(fund_code, platform):
# 如果在爱基金平台找不到,则到展恒基金找
if total_asset == None and platform == 'ai_fund':
print("fund_code", total_asset, fund_code)
each_fund = FundApier(fund_code, end_date='2021-05-10', platform='zh_fund')
each_fund = FundApier(
fund_code, end_date='2021-05-10', platform='zh_fund')
total_asset = each_fund.get_total_asset()
return total_asset
if __name__ == '__main__':
if __name__ == '__main__':
lock = Lock()
each_fund_query = FundQuery()
record_total = each_fund_query.get_crawler_quarter_fund_total() # 获取记录条数
print('record_total', record_total)
IdWorker = IdWorker()
page_start = 0
# error_funds = []
# 设置表头
result_dir = './output/'
fund_csv = FundCSV(result_dir)
if page_start == 0:
fund_csv.write_season_catch_fund(True)
fund_csv.write_abnormal_url_fund(True)
# df = pandas.read_csv(
# result_dir + 'fund_morning_quarter_error.csv', usecols=[0, 2, 4])
# fund_list = df.values.tolist()
# print(len(d[d['代码'].astype(str).str.contains('10535')]))
# print(df[df['代码'].astype(str).str.contains('10535')]
# ['股票总仓位'].values)
fund_csv.write_season_catch_fund(True)
fund_csv.write_abnormal_url_fund(True)
def crawlData(start, end):
login_url = 'https://www.morningstar.cn/membership/signin.aspx'
@ -150,6 +137,7 @@ if __name__ == '__main__':
'morning_star_rating_5': each_fund.morning_star_rating.get(5),
'morning_star_rating_10': each_fund.morning_star_rating.get(10),
}
print('fund_code', each_fund.fund_code)
fund_insert.fund_quarterly_info(quarterly_dict)
# 入库十大股票持仓
stock_position_total = each_fund.stock_position.get(
@ -186,46 +174,18 @@ if __name__ == '__main__':
quarterly_dict['fund_code'] = item_code
quarterly_dict['total_asset'] = total_asset
quarterly_dict['id'] = snow_flake_id + i + 1
#入库
# 入库
fund_insert.fund_quarterly_info(quarterly_dict)
if float(stock_position_total) > 0:
stock_dict['fund_code'] = item_code
stock_dict['id'] = snow_flake_id + i + 1
#入库
# 入库
fund_insert.fund_stock_info(stock_dict)
# pprint(fundDict)
page_start = page_start + page_limit
print(current_thread().getName(), 'page_start', page_start)
sleep(3)
chrome_driver.close()
threaders = []
start_time = time()
# steps = [{
# "start": 0,
# "end": 1000
# }, {
# "start": 1000,
# "end": 2000
# }, {
# "start": 2000,
# "end": 3000
# }, {
# "start": 3500,
# "end": record_total
# }]
thread_count = 4
step_num = record_total / thread_count
for i in range(thread_count):
# start = steps[i]['start']
# end = steps[i]['end']
start = i * step_num
end = (i + 1) * step_num
t = Thread(target=crawlData, args=(int(start), int(end)))
t.setDaemon(True)
threaders.append(t)
t.start()
for threader in threaders:
threader.join()
end_time = time()
print(record_total, 'run time is %s' % (end_time - start_time))
bootstrap_thread(crawlData, record_total, 4)
exit()

@ -290,8 +290,8 @@ class FundSpider:
'qt_stock').find_elements_by_xpath("li")
for index in range(4, len(li_elements) - 1, 4):
temp_stock_info = dict() # 一只股票信息
stock_base = re.split('\.|\s',li_elements[index].text) #
stock_code= stock_base[0]
stock_base = re.split('\.|\s', li_elements[index].text)
stock_code = stock_base[0]
stock_market = None if len(
stock_base) == 1 else stock_base.pop()
#纠正港股市场及代码 -- 港股号位是5位
@ -303,8 +303,10 @@ class FundSpider:
stock_code = stock_code.replace('S', '')
stock_code = '0' * (5 - len(stock_code)) + stock_code
temp_stock_info['stock_code'] = stock_code
temp_stock_info['stock_market'] = stock_market.replace(' ', '')
temp_stock_info['stock_name'] = li_elements[index + 1].text.replace(' ', '')
temp_stock_info['stock_market'] = stock_market.replace(
' ', '') if stock_market else stock_market
temp_stock_info['stock_name'] = li_elements[index +
1].text.replace(' ', '')
# temp_stock_info['stock_value'] = li_elements[index+2].text
temp_stock_info['stock_portion'] = li_elements[index +
3].text if li_elements[index + 3].text != '-' else None

@ -13,9 +13,9 @@ from fund_info.supplement import FundSupplement
if __name__ == '__main__':
fund_supplement = FundSupplement()
#补充基金清算维度信息
#fund_supplement.update_archive_status()
fund_supplement = FundSupplement()
# 补充基金清算维度信息
fund_supplement.update_archive_status()
#补充除了A类基金的其他类基金的总资产信息
fund_supplement.update_fund_total_asset()
# 补充除了A类基金的其他类基金的总资产信息
# fund_supplement.update_fund_total_asset()

Loading…
Cancel
Save