def get_stock_hist_data_multithreading(): df = ts.get_stock_basics() index = df.index count = len(index) threads = [] t1 = threading.Thread(target=get_stock_hist_data, args=( 0, 600, )) threads.append(t1) t2 = threading.Thread(target=get_stock_hist_data, args=( 601, 1200, )) threads.append(t2) t3 = threading.Thread(target=get_stock_hist_data, args=( 1201, 1800, )) threads.append(t3) t4 = threading.Thread(target=get_stock_hist_data, args=( 1801, 2400, )) threads.append(t4) t5 = threading.Thread(target=get_stock_hist_data, args=(2401, count)) threads.append(t5) for t in threads: t.setDaemon(True) t.start() t.join() tushare_data_util.zip_dir_and_delete('hist_data') logger.info('execute hist_data:tushare_data_util.upload_zip_files()...')
def get_assurance_data(): Final_Case = FinalOutPut() #Final_Case = ['aaaaaaaaaa'] # 5.将前一天新增的担保记录逐条写入txt文件 year, month = tushare_data_util.get_current_year_month() dirpath = path + str(year) + '-' + str(month) if not os.path.exists(dirpath): os.makedirs(dirpath) else: pass pub_date = '公告日期:' + yesterday assurance_dir = dirpath + '/assurance' if not os.path.exists(assurance_dir): os.makedirs(assurance_dir) file_name = assurance_dir + '/Assurance' + suffix_date + '.txt' f = open(file_name, 'w+') for i in Final_Case: if pub_date in i: a = i.replace('Stockid:','').replace('公告日期:','').replace('提供担保方:','').replace('获得担保方:','').replace('担保内容:','') b = a.replace('担保形式:','').replace('担保起始日:','').replace('担保终止日:','').replace('交易金额(万元):','').replace('币种:','') c = b.replace(' ','') item = c.split('|') if item[5]=='' or item[6]=='' or item[7]=='': f.write(c + str(0) + '\n') else: f.write(c + str(1) + '\n') f.close() tushare_data_util.zip_dir_and_delete('assurance') logger.info('execute assurance:tushare_data_util.upload_zip_files()...') tushare_data_util.upload_zip_files('assurance')
def get_fundamental_data_by_quarter(): try: year, month = tushare_data_util.get_current_year_month() if month in (1, 4, 7, 10): quarter = int( tushare_data_util.get_quarter_by_month( (lambda x: 12 if (x == 1) else (x - 1))(month))) dir_name = str(year) + 'y' + str(quarter) + 'q' logger.info('get %s year %s quarter 基本面数据 starting...' % (year, quarter)) get_cashflow_data(year, quarter) get_debtpaying_data(year, quarter) get_growth_data(year, quarter) get_operation_data(year, quarter) get_profit_data(year, quarter) get_report_data(year, quarter) tushare_data_util.zip_dir_and_delete(dir_name) logger.info('execute ' + dir_name + ':tushare_data_util.upload_zip_files()...') tushare_data_util.upload_zip_files(dir_name) logger.info('get %s year %s quarter 基本面数据 end...' % (year, quarter)) else: pass except: logger.exception('some errors between get 基本面数据:')
def get_stock_classification_datas(): logger.info('Run task %s (%s)...' % ('get_stock_classification_datas', os.getpid())) get_industry_classified() get_concept_classified() get_area_classified() get_gem_classified() get_hs300s() get_sme_classified() get_st_classified() get_suspended() get_sz50s() get_terminated() logger.info( 'execute classifications:tushare_data_util.zip_dir_and_delete()...') tushare_data_util.zip_dir_and_delete('classifications') logger.info( 'execute classifications:tushare_data_util.upload_zip_files()...') tushare_data_util.upload_zip_files('classifications')
def get_stock_deal_data(): logger.info('Run task %s (%s)...' % ('get_stock_deal_data', os.getpid())) get_stock_basics() get_index() get_today_all() df = ts.get_stock_basics() index = df.index for i in index: get_hist_data(i) get_realtime_quotes(i) get_today_ticks(i) get_sina_dd(i) get_tick_data(i) dir_names = ('hist_data', 'realtime_quotes', 'today_ticks', 'sina_dd', 'tick_data') for dn in dir_names: tushare_data_util.zip_dir_and_delete(dn) logger.info('execute ' + dn + ':tushare_data_util.upload_zip_files()...') tushare_data_util.upload_zip_files(dn)
def get_fundamental_datas_history(): for s in tushare_data_util.get_history_year_quarters( )[:len(tushare_data_util.get_history_year_quarters()) - 2]: year, quarter = tushare_data_util.get_year_quarter(s) dir_name = str(year) + 'y' + str(quarter) + 'q' try: logger.info('get 基本面数据 starting...') get_cashflow_data(year, quarter) get_debtpaying_data(year, quarter) get_growth_data(year, quarter) get_operation_data(year, quarter) get_profit_data(year, quarter) get_report_data(year, quarter) tushare_data_util.zip_dir_and_delete(dir_name) logger.info('execute ' + dir_name + ':tushare_data_util.upload_zip_files()...') tushare_data_util.upload_zip_files(dir_name) logger.info('get 基本面数据 end...') except: logger.exception('some errors between get 基本面数据:')