def capttal_xlsx_to_db(code): sheet = read_xlsx(code) data_list = [] for i in range(sheet.nrows): if i == 0: continue d = {} for j in range(sheet.ncols): cell = sheet.cell_value(i, j) if sheet.cell(i, j).ctype == 3: date = datetime(*xldate_as_tuple(cell, 0)) cell = date.strftime('%Y-%m-%d') if j == 0: d['date'] = cell elif j == 1: d['changeReasonDesc'] = cell else: d['totalShares'] = cell else: # text格式 if j == 0: d['date'] = cell elif j == 1: d['changeReasonDesc'] = cell else: d['totalShares'] = cell data_list.append(d) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': code}, 'history_capital_stock', data_list)
def daily_sina_capital(code): res = requests.get( url= 'http://vip.stock.finance.sina.com.cn/corp/go.php/vCI_StockStructureHistory/stockid/{}/stocktype/TotalStock.phtml' .format(code), headers=headers, ) res.encoding = 'gb2312' soup = BeautifulSoup(res.text, 'lxml') tr_list = soup.find('table', id='StockStructureHistoryTable').find_all( 'tr')[2].find('table').find_all( id=['historyTable07', 'historyTable06', 'historyTable05']) data_list = [] for tr in tr_list: for item in tr.find_all('tr'): if item.find_all('td'): data_list.append({ 'date': item.find_all('td')[0].text, 'totalShares': str(item.find_all('td')[1].text).replace('万股', '') }) wz_date = date_timestamp(data_list[-1]['date']) db_date = date_timestamp( LmInnerReportDBMgr.get_data_list( 'lm_stock_data', {'code': code}, 'sina_history_capital_stock')[-1]['date']) if wz_date > db_date: print(code, '有变更股本信息,变更前日期为:%s,变更后日期为:%s') LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': code}, 'sina_history_capital_stock', data_list) else: print(code, '股本信息已经是最新...')
def install_capital_to_price_enddate(history_price_stock, history_capital_stock, code): begin_date = history_price_stock[0]['date'] end_date = history_capital_stock[-1]['date'] date_lists = getEveryDay(begin_date, end_date, 1) for price in history_price_stock: for date in date_lists: if price['date'] == date: price['capital_stock'] = history_capital_stock[-1]['totalShares'] LmInnerReportDBMgr.save_set_result(tablename='lm_stock_data', condition={'code': code}, result_type='history_price_stock', result=history_price_stock)
def total_market(code): code_data = LmInnerReportDBMgr.get_code_data('lm_stock_data', code) history_price_stock = code_data['history_price_stock'] for item in history_price_stock: total_market = float(item['settlement']) * float(item['capital_stock']) item['total_market'] = total_market LmInnerReportDBMgr.save_set_result(tablename='lm_stock_data', condition={'code': code}, result_type='history_price_stock', result=history_price_stock) print(code, 'total_market finish...')
def install_capital_to_price(code): code_data = LmInnerReportDBMgr.get_code_data('lm_stock_data', code) if code_data: history_price_stock = code_data['history_price_stock'] # history_capital_stock = code_data['history_capital_stock'] history_capital_stock = code_data['sina_history_capital_stock'] date_list = [("" if i == 0 else history_capital_stock[i - 1]["date"], "" if i == (len(history_capital_stock)) else history_capital_stock[i]["date"], history_capital_stock[i]['totalShares']) for i in range(len(history_capital_stock))] for date_t in date_list: if date_t[0] == "": end_date = history_price_stock[-1]['date'] begin_date = date_t[1] date_list = getEveryDay(begin_date, end_date, 1) else: end_date = date_t[0] begin_date = date_t[1] date_list = getEveryDay(begin_date, end_date, 0) for price in history_price_stock: for date in date_list: if price['date'] == date: price['capital_stock'] = date_t[2] install_capital_to_price_enddate(history_price_stock, history_capital_stock, code) print(code, 'price stock of capital finish....')
def install(): # code_list = ["600000", "600016", "600028", "600029", "600030", "600036", "600048", "600050", "600100", # "600104", "600111", "600340", "600485", "600518", "600519", "600547", "600606", "600837", # "600887", "600919", "600958", "600999", "601006", "601088", "601166", "601169", "601186", # "601198", "601211", "601229", "601288", "601318", "601328", "601336", "601390", "601398", # "601601", "601628", "601668", "601688", "601766", "601788", "601800", "601818", "601857", # "601881", "601901", "601985", "601988", "601989",'600019', '600309', '601669', '601878', '603993'] # code_list=['600000'] code_list = [] data = LmInnerReportDBMgr.get_data('lm_index_data', {'code': '000016'})['constituent_shares_list'] for item in data: for code in item['cfg']: if str(code).split('.')[0] not in code_list: code_list.append(str(code).split('.')[0]) print(len(code_list)) print(code_list) code_list = code_list[55:] print(code_list) for code in code_list: try: install_history_financial_crawler(code) install_history_price_crawler(code) history_sina_capital(code) install_capital_to_price(code) total_market(code) except JSONDecodeError: continue
def install_daily_sharepirce(code): url = 'http://pdfm.eastmoney.com/EM_UBG_PDTI_Fast/api/js?rtntype=5&id={}1&type=k'.format( code) data = requests.get(url=url) data_json = json.loads(data.text.split('(')[1].split(')')[0]) stock_data = data_json['data'] # [1999-11-10,29.50,27.75,29.80,27.00,1740850,48.6亿,-] [date,开盘价,收盘价,最高价,最低价,交易量,交易金额,振幅] day_data = str(stock_data[-1]).split(',') day_date = day_data[0] opening = day_data[1] settlement = day_data[2] ceilingPrice = day_data[3] bottomPrice = day_data[4] volumeOfTransaction = day_data[5] transactionAmount = day_data[6] amplitude = day_data[7] today_date = date_timestamp(get_today_date()) capital_data_list = LmInnerReportDBMgr.get_data_list( 'lm_stock_data', {'code': code}, 'sina_history_capital_stock') # capital_data_list = LmInnerReportDBMgr.get_data_list('lm_stock_data', {'code': code}, 'history_capital_stock') date_list = [date_timestamp(item['date']) for item in capital_data_list] sorted(date_list) print(date_list) max_date = date_list[-1] date = timestamp_date(max_date) if max_date == today_date: date = timestamp_date(date_list[-2]) for item in capital_data_list: if item['date'] == date: capital_stock = item['totalShares'] all_day_data = { 'date': day_date, 'opening': opening, 'settlement': settlement, 'ceilingPrice': ceilingPrice, 'bottomPrice': bottomPrice, 'volumeOfTransaction': volumeOfTransaction, 'transactionAmount': transactionAmount, 'amplitude': amplitude, 'capital_stock': capital_stock, 'total_market': float(settlement) * float(capital_stock) } LmInnerReportDBMgr.save_push_result('lm_stock_data', {'code': code}, 'history_price_stock', all_day_data)
def cwbbzy(response, stock_code): ''' :param response: 财务报表摘要的数据 str :param stock_code: 股票代码 :return: ''' zd_list = [ "YEAREND_DATE", "OPERATING_RECEIPT", "COST_IN_BUSINESS", "OPERATING_PROFIT", "TOTAL_PROFIT", "INCOME_TAX_EXPENSE", "NET_PROFIT", "BASIC_PER_SHARE_PROFIT", "MONETARY_RESOURCES", "ACCOUNTS_RECEIVABLE", "STOCK", "TOTAL_CURRENT_ASSETS", "NET_FIXED_ASSETS", "TOTAL_ASSETS", "TOTAL_CURRENT_LIABILITIES", "TOTAL_NON_CURRENT_LIABILTIES", "TOTAL_LIABILITIES", "OWNER_S_EQUITY", "BALANCE_CASH_AND_CASH_EQUIVALENTS_BEGINNING_PERIOD", "NET_CASH_FLOW_ARISIONG_FROM_OPERATIONG_ACTIVITIES", "NET_CASH_FLOW_ARISIONG_FROM_INVESTMENT_ACTIVITIES", "NET_CASH_FLOW_ARISIONG_FROM_FINANCING_ACTIVITIES", "NET_INCRWASE_IN_CASH_AND_CASH_EQUICALENTS", "BALANCE_CASH_AND_CASH_EQUIVALENTS_END_PERIOD" ] cwbbzy_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in zip(*[ item.strip().split(",")[1:-1] for item in response.text.strip().split("\n") ]))] db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, cwbbzy_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.cwbbzy', cwbbzy_data) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': cwbbzy_data[0]['YEAREND_DATE'], 'report': { 'cwbbzy': cwbbzy_data } })
def zycwzb(response, stock_code): ''' :param response: 主要财务指标的数据 str :param stock_code: 股票代码 :return: ''' zd_list = [ "YEAREND_DATE", "BASIC_PER_SHARE_PROFIT", "NET_ASSET_VALUE_PER_SHARE", "NET_CASH_FLOW_ARISIONG_FROM_OPERATING_ACTIVITIES_PER_SHARE", "MAIN_BUSINESS_INCOME", "MAIN_BUSINESS_PROFIT", "OPERATIONG_PROFIT", "INCOME_FROM_INVESTMENT", "NON_BALANCE_OF_PAYMENTS_NET_AMOUNT", "TOTAL_PROFIT", "NET_MARGIN", "NET_PROFIT_DEDUCTION_RECURRENT_PROFIT_AND_LOSS", "NET_AMOUNT_OPERATIONG_ACTIVITIES_CASH_FLOW", "NET_INCREASE_IN_CASH_AND_CASH_EQUIVALENTS", "TOTAL_ASSETS", "CURRENT_ASSETS", "TOTAL_LIABILITIES", "CURRENT_LIABILITIES", "STOCKHOLDERS_S_EQUITY_DOES_NOT_MINORITY_EQUITY", "NET_ASSET_YIELD_WEIGHTED" ] zycwzb_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in zip(*[ item.strip().split(",")[1:-1] for item in response.text.strip().split("\n") ]))] db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, zycwzb_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.zycwzb', zycwzb_data) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': zycwzb_data[0]['YEAREND_DATE'], 'report': { 'zycwzb': zycwzb_data } })
def Tencent_history_price_crawler(code): url = 'http://web.ifzq.gtimg.cn/appstock/app/fqkline/get?param=sh{},day,2002-01-01,2010-01-31,320,qfq'.format( code) res = requests.get( url=url, headers=headers, ) stock_data = json.loads(res.text)['data']['sh600591']['qfqday'] stock_name = json.loads(res.text)['data']['sh600591']['qt']['sh600591'][1] isHalt = is_halt(code) all_day_data_list = [] for day_data in stock_data: # ['2008-07-15', '6.100', '6.070', '6.240', '6.000', '133681.350'] [date,开盘价,收盘价,最高价,最低价,交易量] day_date = day_data[0] opening = day_data[1] settlement = day_data[2] ceilingPrice = day_data[3] bottomPrice = day_data[4] volumeOfTransaction = day_data[5] all_day_data_list.append({ 'date': day_date, 'opening': opening, 'settlement': settlement, 'ceilingPrice': ceilingPrice, 'bottomPrice': bottomPrice, 'volumeOfTransaction': volumeOfTransaction, }) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': code}, 'history_price_stock', all_day_data_list) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': code}, 'company_name', stock_name) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': code}, 'isHalt', isHalt) print('%s save history price of stock successful...' % stock_name)
def func(): first_2013 = '/aboutus/mediacenter/hotandd/c/c_20150912_3987651.shtml' second_2013 = '/market/sseindex/diclosure/c/c_20150911_3985098.shtml' first_2014 = '/market/sseindex/diclosure/c/c_20150911_3985111.shtml' second_2014 = '/market/sseindex/diclosure/c/c_20150911_3985128.shtml' first_2015 = '/market/sseindex/diclosure/c/c_20150911_3985155.shtml' second_2015 = '/market/sseindex/diclosure/c/c_20151130_4017237.shtml' first_2016 = '/market/sseindex/diclosure/c/c_20160530_4121664.shtml' second_2016 = '/market/sseindex/diclosure/c/c_20161128_4207421.shtml' first_2017 = '/market/sseindex/diclosure/c/c_20170531_4318582.shtml' second_2017 = '/market/sseindex/diclosure/c/c_20171127_4424760.shtml' url_list = [second_2017, first_2017] try: for i in range(len(url_list)): obtain_xlsx_data(url_list[i]) shxx_date = entry_into_force_time(url_list[i - 1]) # 获取列表中最后一个日期 mongo_save_date = \ list(LmInnerReportDBMgr.get_index_comstock_data('lm_index_data', {'code': '000016'}).keys())[-1] data_list = LmInnerReportDBMgr.get_index_comstock_teble( 'lm_index_data', {'code': '000016'}, '2014-06-16') print(data_list) wb = xlrd.open_workbook('20131216.xls') #将调入的调出去,调出的调进来(往前推理成分股) tr_data = add_component_code(wb, data_list, 0) tc_data = out_component_code(wb, tr_data, 1) # #将调入的调进去,调出的调出去(往后推理成分股) # tr_data = add_component_code(wb, data_list, 1) # tc_data = out_component_code(wb, tr_data, 0) LmInnerReportDBMgr.save_set_result( 'lm_index_data', {'code': '000016'}, 'component_stock_dict.%s' % '2013-12-16', tc_data) except Exception as e: traceback.print_exc(e)
def dfcf_history_price_crawler(code): url = 'http://pdfm.eastmoney.com/EM_UBG_PDTI_Fast/api/js?rtntype=5&id={}1&type=k'.format( code) data = requests.get(url=url, headers=headers) data_json = json.loads(data.text.split('(')[1].split(')')[0]) stock_code = data_json['code'] stock_name = data_json['name'] stock_data = data_json['data'] all_day_data_list = [] isHalt = is_halt(code) for i in stock_data: # i 就是一天的数据 # [1999-11-10,29.50,27.75,29.80,27.00,1740850,48.6亿,-] [date,开盘价,收盘价,最高价,最低价,交易量,交易金额,振幅] day_data = str(i).split(',') day_date = day_data[0] #date opening = day_data[1] #开盘价 settlement = day_data[2] #收盘价 ceilingPrice = day_data[3] #最高价 bottomPrice = day_data[4] #最低价 volumeOfTransaction = day_data[5] #交易量 # transactionAmount = day_data[6] #交易金额 all_day_data_list.append({ 'date': day_date, 'opening': opening, 'settlement': settlement, 'ceilingPrice': ceilingPrice, 'bottomPrice': bottomPrice, 'volumeOfTransaction': volumeOfTransaction, # 'transactionAmount': transactionAmount, }) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'history_price_stock', all_day_data_list) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'company_name', stock_name) LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'isHalt', isHalt) print('%s save history price of stock successful...' % stock_name)
first :[ [每一年的10-31到09-01] ] 第二步 按照每个列表日期进行规则处理 ''' from common.db_utils.stock_crawler_inner_db import LmInnerReportDBMgr from common.utils.time_utils import getEveryDay, get_date_object date_dict = { 'first': [], 'second': [], 'third': [], } constituent_shares_list = LmInnerReportDBMgr.get_data_list('lm_index_data', {'code': '000016'}, 'constituent_shares_list') __list = sorted(constituent_shares_list, key=lambda item: item['date'], reverse=True) max_date = __list[0]['date'] min_date = __list[-1]['date'] # 1、获取此指数从头到尾的所有日期 date_list = getEveryDay(min_date, max_date, 1) date_list = sorted(date_list, reverse=True) # 2、将日期按照规则分配到date_dict中 for date in date_list: date_obj = get_date_object(date) # [每一年的10-31到09-01] if 9 <= date_obj.month <= 10: date_dict['first'].append(date) # [每一年08-31到05-01] elif 5 <= date_obj.month <= 8:
def xjllb(response, stock_code): zd_list = [ "YEAREND_DATE", "NET_INCREASE_IN_CUSTOMER_DEPOSITS_AND_TRADE_DEPOSITS", "NET_INCREASE_IN_BORROWING_FROM_THE_CENTRAL_BANK", "FROM_OTHER_FINANCIAL_INSTITUIONS_NET_INCREASE_OF_LOANS", "CASH_FOR_INTEREST,COMMISSION_AND_COMMISSION", "OTHER_CASH_RELATED_TO_BUSINESS_ACTIVITIES_RECEIVED", "CASH_INFLOWS_FROM_OPERATING_ACTIVITIES", "NET_INCREASE_IN_LOANS_AND_ADVANCES", "NET_INCREASE_OF_NET_INCREASE_OF_CENTRAL_BANK_AND_INDUSTRY", "CASH_PAID_TO_WORKERS_AND_WORKERS", "VARIOUS_TAXES_AND_FEES_PAID", "OTHER_CASH_RELATED_TO_BUSIONESS_ACTIVITIES", "CASH_FOR_PAYMENT_OF_INTEREST,COMMISSION_AND_COMMISSION", "OPERATING_CASH_OUTFLOWSUBTOTAL", "NET_CASH_FLOW_GENERATED_BY_OPERAtiNG_ACTIVITI", "CASH_RECEIVED_FROM_THE_RETURN_OF_INVESTMENT", "CASH_RECEIVED_FROM_THE_PROCEEDS_OF_INVESTMENT", "NET_CASH_RECOVERED_FROM_THE_DISPOSAL_OF_FIX_ASSETS,INTANGIBLE_ASSETS_AND_OTHER_LONG_TERM_ASSETS", "NET_ASHT_RECEIVED_BY_THE_SUBSIDIARY_AND_OTHER_BUSINESS_UNITS", "OTHER_CASH_RELATED_TO_INVESTMENT_ACTIVITIES_RECEIVED", "CASH_INFLOW_FROM_INVESTMENT_ACTIVITIES", "THE_CASH_PAID_BY_THE_INVESTMENT", "CASH_PAID_FOR_PURCHASE_OF_FIX_ASSETS,INTANGIBLE_ASSET_AND_OTHER_LONG_TERM_ASSET", "OTHER_CASH_RELATED_TO_INVESTMENT_ACTIVITIEs", "CASH_OUTFLOW_FOR_INVESTMENT_ACTIVITIES", "NET_CASH_FLOW_GENERATED_BY_INVESTMENT_ACTIVITIES", "CASH_RECEIVED_BY_INVESTMENT", "CASH_RECEIVED_FROM_THE_ISSUANCE_OF_BONDS", "RECEIVING_OTHER_CASH_RELATED_TO_FUND_RAISING_ACTIVITIES", "CASH_INFLOW_FROM_FINANCING_ACTIVITIES", "CASH_IN_PAYMENT_OF_DEBT", "CASH_PAID_FOR_DISTRBUTION_OG_DIVIDENDS,PROFITS,OR_PAYMENT_OF_INTEREST", "PAYMENT_OF_OTHER_CASH_RELATED_TO_FUND_RAISIONG_ACTIVItiES", "CASH_OUTFLOW_FOR_FINANCING_ACTIVITIES", "NET_CASH_FLOW_GENERATED_BY_FUND_RAISING_ACTIVITIES", "EFFECT_OF_EXCHANGE_RATE_CHANGES_ON_CASH_AND_CASH_EQUIVALENTS", "NET_INCREASE_IN_CASH_AND_EQUIVALENTS", "ADD:THE_BALANCE_OF_CASH_AND_CASH_EQUIVALENTS", "END_OF_TERM_CASH_AND_CASH_EQUIVALENTS_BALANCE", "NET_PROFIT", "PROFIT_AND_LOSS_OF_MINORITY_SHAREHOLDERS", "ASSET_IMPAIRMENT_PREPARATION", "FIXED_ASSETS_DEPRECIATION,DEPLETION_OF_OIL_AND_GASASSETS,DEPRECIATION_OF_PRODUCTION_MATERIALS", "AMORTIZATION_OF_INTANGIBLE_ASSETS", "AMORTIZATION_OF_LONG_TERM_APPORTIONED_EXPENSES", "DISPOSE_OF_LOSS_OF_FIXED_ASSETS,INTANGIBLE_ASSETS_AND_OTHER_LONG_TERM_ASSETS", "LOSS_OF_FIXED_ASSETS", "FINANCIAL_COST", "INVESTMENT_LOSS", "LOSS_OF_FAIR_VALUE_CHANGE", "REDUCTION_IN_INVENTORY", "DEFERRED_INCOME_TAX_ASSETS", "INCREASE_OF_DEFERRED_INCOME_TAX_LIABILITIES", "REDUCTION_OF_OPERATIONAL_RECEIVABLE_PROJECTS", "AN_INCREASE_IN_OPERATIONAL_PROJECTS", "OTHER", "OPERATING_ACTIVIITIES_PRODUCE_NET_CASH_FLOW", "DEBT_TO_CAPITAL", "SWITCHING_COMPANY_BONDS_THAT_EXPIRE_WITHIN_ONE_YEAR", "FINANCING_IS_RENTED_INTO_FIXED_ASSETS", "FINAL_BALANCE_OF_CASH", "INITIAL_BALANCE_OF_CASH", "FINAL_BALANCE_OF_CASH_EQUIVALENTS", "THE_INITIAL_BALANCE_OF_THE_CASH_EQUIVALENTS", 'INCREASE_THE_AMOUNT_OF_CASH_PAID_BY_PLEDGE_AND_FIX_DEPOSIT', 'AMONG_THEM:THE_DIVIDEND_AND_PROFIT_PAID_BY_SUBSIDIARY_TO_MINORITY_SHAREHOLDERS', 'AMONG_THEM:SUBSIDIARY_COMPANY_ABSORBS_THE_CASH_RECEIVED_BY_THE_MINORITY_SHAREHOLDERS', 'NET_INCREASE_IN_MORTGAGE_LOAN', 'REDUCTIONG_OF_COMPLETED_UNSETTLED_PAYMENTS(REDUCE:INCREASE)', 'CHASH_RECEIVED_FROM_THE_LOAN', 'CASH_FOR_PURCHASE_OF_GOODS_AND_LABOR_SERVICES', 'INSURED_SAVINGS_AND_INVESTMENT_FUND_NET_INCREASE', 'UNIDENTIFIED_INVESTMENT_LOSSES', 'EXPECTED_LIABILITIES', 'CASH_PAYMENT_OF_POLICY_BONUS', 'SELLING_CASH_RECEIVED_FROM_SERVICES', 'AN_INCREASE_IN_THE_ADVANCE_COAST', 'CASH_PAID_FOR_THE_ORIGINAL_INSURANCE_CONTRACT', 'RECEIPT_OF_REINSURANCE_NET_CASH', 'NET_INCREASE_IN_CASH_AND_CASH_EQUIVALENTS', 'NET_CASH_PAID_BY_SUBSIDIARY_AND_OTHER_BUSINESS_UNITS', 'REDUCED_COAST_OF_APPORTIONED', 'AN_INCREASE_IN_THE_SETTLEMENT_OF_UNCOMPLETED_FUNDS(REDUCE:REDUCTION)', 'INCREASE_IN_DEFERRED_INCOME(REDUCE:REDUCTION)', 'NET_INCREASE_IN_REPO_BUSINESS_FUNDS', 'THE_TAX_AND_FEE_RECEIVED', 'DISPOSAL_OF_NET_INCREASE_IN_TRANSACTION_FINANCIAL_ASSETS', 'REDUCTION_OF_CASH_RECEIVED_BY_PLEDGE_AND_FIX_DEPOSIT', 'NET_INCREASE_OF_LOANS', 'CASH_RECEIVED_FROM_THE_PERMIUMS_OF_THE_ORIGINAL_INSURANCE_CONTRACT' ] CJ_zd_list = [ 'INCREASE_THE_AMOUNT_OF_CASH_PAID_BY_PLEDGE_AND_FIX_DEPOSIT', 'AMONG_THEM:THE_DIVIDEND_AND_PROFIT_PAID_BY_SUBSIDIARY_TO_MINORITY_SHAREHOLDERS', 'AMONG_THEM:SUBSIDIARY_COMPANY_ABSORBS_THE_CASH_RECEIVED_BY_THE_MINORITY_SHAREHOLDERS', 'NET_INCREASE_IN_MORTGAGE_LOAN', 'REDUCTIONG_OF_COMPLETED_UNSETTLED_PAYMENTS(REDUCE:INCREASE)', 'CHASH_RECEIVED_FROM_THE_LOAN', 'CASH_FOR_PURCHASE_OF_GOODS_AND_LABOR_SERVICES', 'INSURED_SAVINGS_AND_INVESTMENT_FUND_NET_INCREASE', 'UNIDENTIFIED_INVESTMENT_LOSSES', 'EXPECTED_LIABILITIES', 'CASH_PAYMENT_OF_POLICY_BONUS', 'SELLING_CASH_RECEIVED_FROM_SERVICES', 'AN_INCREASE_IN_THE_ADVANCE_COAST', 'CASH_PAID_FOR_THE_ORIGINAL_INSURANCE_CONTRACT', 'RECEIPT_OF_REINSURANCE_NET_CASH', 'NET_INCREASE_IN_CASH_AND_CASH_EQUIVALENTS', 'NET_CASH_PAID_BY_SUBSIDIARY_AND_OTHER_BUSINESS_UNITS', 'REDUCED_COAST_OF_APPORTIONED', 'AN_INCREASE_IN_THE_SETTLEMENT_OF_UNCOMPLETED_FUNDS(REDUCE:REDUCTION)', 'INCREASE_IN_DEFERRED_INCOME(REDUCE:REDUCTION)', 'NET_INCREASE_IN_REPO_BUSINESS_FUNDS', 'THE_TAX_AND_FEE_RECEIVED', 'DISPOSAL_OF_NET_INCREASE_IN_TRANSACTION_FINANCIAL_ASSETS', 'REDUCTION_OF_CASH_RECEIVED_BY_PLEDGE_AND_FIX_DEPOSIT', 'NET_INCREASE_OF_LOANS', 'CASH_RECEIVED_FROM_THE_PERMIUMS_OF_THE_ORIGINAL_INSURANCE_CONTRACT' ] data = response.text.strip().split("\n") tmp_list = [] for i in range(len(data)): if i in [ 1, 2, 17, 29, 31, 33, 38, 39, 47, 51, 52, 53, 55, 56, 59, 61, 66, 67, 68, 70, 71, 72, 73, 74, 75, 80, 81, 84, 85, 86, 90, 95 ]: continue tmp_list.append(data[i].strip().split("\t")[1:]) for j in range(len(CJ_zd_list)): tmp_list.append(["0" for c in range(len(data[0]))]) xjllb_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in list(zip(*tmp_list)))] db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, xjllb_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.xjllb', xjllb_data) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': xjllb_data[0]['YEAREND_DATE'], 'report': { 'xjllb': xjllb_data } })
if __name__ == '__main__': new_code_list = [ "600000", "600016", "600028", "600029", "600030", "600036", "600048", "600050", "600019", "600104", "600111", "600340", "600309", "600518", "600519", "600547", "600606", "600837", "600887", "600919", "600958", "600999", "601006", "601088", "601166", "601169", "601186", "601669", "601211", "601229", "601288", "601318", "601328", "601336", "601390", "601398", "601601", "601628", "601668", "601688", "601766", "601878", "601800", "601818", "601857", "601881", "603993", "601985", "601988", "601989" ] report_list = [] market_list = [] for code in new_code_list: code_data = LmInnerReportDBMgr.get_code_data('lm_stock_data', code) if not code_data['isHalt']: market_list.append( float(code_data['history_price_stock'][-1]['total_market'])) else: market_list.append( float(code_data['history_price_stock'][-1]['total_market'])) # for i in code_data['history_price_stock']: # if i['date'] == '2017-12-27': # market_list.append(float(i['total_market'])) for i in range(4): report_list.append( float(code_data['report']['lrb'][i] ['SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'])) print(sum(market_list))
with open('1213', encoding='utf-8') as json_file: for i in json_file: d_1213 = eval(i) dlist += [{'date': i[0], 'cfg': i[1]} for i in zip(c_1213, d_1213)] with open('1415', encoding='utf-8') as json_file: for i in json_file: d_1415 = eval(i) dlist += [{'date': i[0], 'cfg': i[1]} for i in zip(c_1415, d_1415)] with open('1617', encoding='utf-8') as json_file: for i in json_file: d_1617 = eval(i) dlist += [{'date': i[0], 'cfg': i[1]} for i in zip(c_1617, d_1617)] LmInnerReportDBMgr.save_set_result('lm_index_data', {'code': '000016'}, 'constituent_shares_list', dlist) # 第一次循环存储,库里没有数据的情况下 # for i in range(len(data)): # if i == 0: # data[0][1].append('600018.XSHG') # d_list.append({'date': data[0][0], 'cfg': data[0][1]}) # else: # t = 0 # for f in d_list[-1]['cfg']: # for s in data[i][1]: # if f == s: # t += 1 # if t != 49: # data[i][1].append('600018.XSHG') # d_list.append({'date': data[i][0], 'cfg': data[i][1]}) # LmInnerReportDBMgr.save_set_result('lm_index_data', {'code': '000016'}, 'constituent_shares_list', d_list)
def xjllb(response, stock_code): ''' :param response: 现金流量表的数据 str :param stock_code: 股票代码 :return: ''' zd_list = [ "YEAREND_DATE", "SELLING_CASH_RECEIVED_FROM_SERVICES", "NET_INCREASE_IN_CUSTOMER_DEPOSITS_AND_TRADE_DEPOSITS", "NET_INCREASE_IN_BORROWING_FROM_THE_CENTRAL_BANK", "FROM_OTHER_FINANCIAL_INSTITUIONS_NET_INCREASE_OF_LOANS", "CASH_RECEIVED_FROM_THE_PERMIUMS_OF_THE_ORIGINAL_INSURANCE_CONTRACT", "RECEIPT_OF_REINSURANCE_NET_CASH", "INSURED_SAVINGS_AND_INVESTMENT_FUND_NET_INCREASE", "DISPOSAL_OF_NET_INCREASE_IN_TRANSACTION_FINANCIAL_ASSETS", "CASH_FOR_INTEREST,COMMISSION_AND_COMMISSION", "NET_INCREASE_OF_LOANS", "NET_INCREASE_IN_REPO_BUSINESS_FUNDS", "THE_TAX_AND_FEE_RECEIVED", "OTHER_CASH_RELATED_TO_BUSINESS_ACTIVITIES_RECEIVED", "CASH_INFLOWS_FROM_OPERATING_ACTIVITIES", "CASH_FOR_PURCHASE_OF_GOODS_AND_LABOR_SERVICES", "NET_INCREASE_IN_LOANS_AND_ADVANCES", "NET_INCREASE_OF_NET_INCREASE_OF_CENTRAL_BANK_AND_INDUSTRY", "CASH_PAID_FOR_THE_ORIGINAL_INSURANCE_CONTRACT", "CASH_FOR_PAYMENT_OF_INTEREST,COMMISSION_AND_COMMISSION", "CASH_PAYMENT_OF_POLICY_BONUS", "CASH_PAID_TO_WORKERS_AND_WORKERS", "VARIOUS_TAXES_AND_FEES_PAID", "OTHER_CASH_RELATED_TO_BUSIONESS_ACTIVITIES", "OPERATING_CASH_OUTFLOWSUBTOTAL", "NET_CASH_FLOW_GENERATED_BY_OPERAtiNG_ACTIVITI", "CASH_RECEIVED_FROM_THE_RETURN_OF_INVESTMENT", "CASH_RECEIVED_FROM_THE_PROCEEDS_OF_INVESTMENT", "NET_CASH_RECOVERED_FROM_THE_DISPOSAL_OF_FIX_ASSETS,INTANGIBLE_ASSETS_AND_OTHER_LONG_TERM_ASSETS", "NET_ASHT_RECEIVED_BY_THE_SUBSIDIARY_AND_OTHER_BUSINESS_UNITS", "OTHER_CASH_RELATED_TO_INVESTMENT_ACTIVITIES_RECEIVED", "REDUCTION_OF_CASH_RECEIVED_BY_PLEDGE_AND_FIX_DEPOSIT", "CASH_INFLOW_FROM_INVESTMENT_ACTIVITIES", "CASH_PAID_FOR_PURCHASE_OF_FIX_ASSETS,INTANGIBLE_ASSET_AND_OTHER_LONG_TERM_ASSET", "THE_CASH_PAID_BY_THE_INVESTMENT", "NET_INCREASE_IN_MORTGAGE_LOAN", "NET_CASH_PAID_BY_SUBSIDIARY_AND_OTHER_BUSINESS_UNITS", "OTHER_CASH_RELATED_TO_INVESTMENT_ACTIVITIEs", "INCREASE_THE_AMOUNT_OF_CASH_PAID_BY_PLEDGE_AND_FIX_DEPOSIT", "CASH_OUTFLOW_FOR_INVESTMENT_ACTIVITIES", "NET_CASH_FLOW_GENERATED_BY_INVESTMENT_ACTIVITIES", "CASH_RECEIVED_BY_INVESTMENT", "AMONG_THEM:SUBSIDIARY_COMPANY_ABSORBS_THE_CASH_RECEIVED_BY_THE_MINORITY_SHAREHOLDERS", "CHASH_RECEIVED_FROM_THE_LOAN", "CASH_RECEIVED_FROM_THE_ISSUANCE_OF_BONDS", "RECEIVING_OTHER_CASH_RELATED_TO_FUND_RAISING_ACTIVITIES", "CASH_INFLOW_FROM_FINANCING_ACTIVITIES", "CASH_IN_PAYMENT_OF_DEBT", "CASH_PAID_FOR_DISTRBUTION_OG_DIVIDENDS,PROFITS,OR_PAYMENT_OF_INTEREST", "AMONG_THEM:THE_DIVIDEND_AND_PROFIT_PAID_BY_SUBSIDIARY_TO_MINORITY_SHAREHOLDERS", "PAYMENT_OF_OTHER_CASH_RELATED_TO_FUND_RAISIONG_ACTIVItiES", "CASH_OUTFLOW_FOR_FINANCING_ACTIVITIES", "NET_CASH_FLOW_GENERATED_BY_FUND_RAISING_ACTIVITIES", "EFFECT_OF_EXCHANGE_RATE_CHANGES_ON_CASH_AND_CASH_EQUIVALENTS", "NET_INCREASE_IN_CASH_AND_EQUIVALENTS", "ADD:THE_BALANCE_OF_CASH_AND_CASH_EQUIVALENTS", "END_OF_TERM_CASH_AND_CASH_EQUIVALENTS_BALANCE", "NET_PROFIT", "PROFIT_AND_LOSS_OF_MINORITY_SHAREHOLDERS", "UNIDENTIFIED_INVESTMENT_LOSSES", "ASSET_IMPAIRMENT_PREPARATION", "FIXED_ASSETS_DEPRECIATION,DEPLETION_OF_OIL_AND_GASASSETS,DEPRECIATION_OF_PRODUCTION_MATERIALS", "AMORTIZATION_OF_INTANGIBLE_ASSETS", "AMORTIZATION_OF_LONG_TERM_APPORTIONED_EXPENSES", "REDUCED_COAST_OF_APPORTIONED", "AN_INCREASE_IN_THE_ADVANCE_COAST", "DISPOSE_OF_LOSS_OF_FIXED_ASSETS,INTANGIBLE_ASSETS_AND_OTHER_LONG_TERM_ASSETS", "LOSS_OF_FIXED_ASSETS", "LOSS_OF_FAIR_VALUE_CHANGE", "INCREASE_IN_DEFERRED_INCOME(REDUCE:REDUCTION)", "EXPECTED_LIABILITIES", "FINANCIAL_COST", "INVESTMENT_LOSS", "DEFERRED_INCOME_TAX_ASSETS", "INCREASE_OF_DEFERRED_INCOME_TAX_LIABILITIES", "REDUCTION_IN_INVENTORY", "REDUCTION_OF_OPERATIONAL_RECEIVABLE_PROJECTS", "AN_INCREASE_IN_OPERATIONAL_PROJECTS", "REDUCTIONG_OF_COMPLETED_UNSETTLED_PAYMENTS(REDUCE:INCREASE)", "AN_INCREASE_IN_THE_SETTLEMENT_OF_UNCOMPLETED_FUNDS(REDUCE:REDUCTION)", "OTHER", "OPERATING_ACTIVIITIES_PRODUCE_NET_CASH_FLOW", "DEBT_TO_CAPITAL", "SWITCHING_COMPANY_BONDS_THAT_EXPIRE_WITHIN_ONE_YEAR", "FINANCING_IS_RENTED_INTO_FIXED_ASSETS", "FINAL_BALANCE_OF_CASH", "INITIAL_BALANCE_OF_CASH", "FINAL_BALANCE_OF_CASH_EQUIVALENTS", "THE_INITIAL_BALANCE_OF_THE_CASH_EQUIVALENTS", "NET_INCREASE_IN_CASH_AND_CASH_EQUIVALENTS" ] xjllb_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in zip(*[ item.strip().split(",")[1:-1] for item in response.text.strip().split("\n") ]))] db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, xjllb_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.xjllb', xjllb_data) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': xjllb_data[0]['YEAREND_DATE'], 'report': { 'xjllb': xjllb_data } })
def lrb(response, stock_code): ''' :param response: 利润表的数据 str :param stock_code: 股票代码 :return: ''' zd_list = [ "YEAREND_DATE", "GROSS_REVENUE", "OPERATIONG_RECEIPT", "INTEREST_REVENUE", "EARNED_PREMIUM", "POUNDAGE_AND_COMMISSION_INCOME", "SALES_INCOME_OF_REAL_ESTATE", "OTHER_BUSINESS_INCOME", "TOTAL_OPERATING_COST", "COST_IN_BUSINESS", "INTEREST_EXPENSE", "POUNDAGE_AND_COMMISSION_EXPENSES", "SALE_COST_OF_REAL_ESTATE", "RESEARCH_AND_DEV_ELOPMENT_COST", "SURRENDER_VALUE", "PAYMENT_NET_EXPENDITURE", "EXTRACT_INSURANCE_CONTRACT_RESERVE_NET", "EXPENDITURE_DIVIDEND_POLICY", "REINSURANCE_EXPENSES", "OTHER_BUSINESS_COSTS", "BUSINESS_TAXES_AND_SURCHARGES", "SELLING_EXPENSES", "MANAGEMENT_EXPENSES", "FINANCIAL_EXPENSES", "ASSETS_IMPAIRMENT_LOSS", "FAIR_VALUE_CHANGE_INCOME", "INVESTMENT_PROFIT", "INVESTMENT_INCOME_FOR_VENTURES_AND_JOINT_VENTURES", "EXCHANGE_EARNINGS", "FUTURES_PROFIT_AND_LOSS", "MANAGED_INCOME", "SUBSIDY_INCOME", "OTHER_BUSINESS_PROFITS", "OPERATING_PROFIT", "NON_BUSINESS_INCOME", "NON_BUSINESS_ESPENDITURE", "DISPOSAL_LOSS_OF_NON_CURRENT_ASSETS", "TOTAL_PROFIT", "INCOME_TAX_EXPENSE", "UNCINFIRMED_INVESTMENT_LOSS", "NET_MARGIN", "VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN", "NET_PROFIT_OF_THE_MERGED_PARTY_BEFORE_MERGER", "MINORITY_SHAREHOLDER_PROFIT_AND_LOSS", "BASIC_PER_SHARE_PROFIT", "BILUTED_EARNINGS_PER_SHARE" ] lrb_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in zip(*[ item.strip().split(",")[1:-1] for item in response.text.strip().split("\n") ]))] for i in range(len(lrb_data)): ''' 处理单季度归属母公司净利润数据 ''' try: first_data = lrb_data[i] second_data = lrb_data[i + 1] first_date_obj = get_date_object(first_data['YEAREND_DATE']) second_date_obj = get_date_object(second_data['YEAREND_DATE']) if first_date_obj.month == 3 or first_date_obj.year != second_date_obj.year: # 3月的库里数据就是单季度的,则直接设置新字段存入mongo # print('三月的数据,可直接存入库中...first: {},second: {}'.format(first_data['YEAREND_DATE'], # second_data['YEAREND_DATE'])) SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float( first_data['VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN']) elif first_date_obj.year == second_date_obj.year and ( first_date_obj.month - second_date_obj.month) == 3: # 6月- 3月 9月 - 6月,或12月 - 9月,直接将数据做减法 # print('month相差3个月,则做减法输出 first: {},second: {}'.format(first_data['YEAREND_DATE'], # second_data['YEAREND_DATE'])) try: SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float( first_data[ 'VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'] ) - float(second_data[ 'VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN']) except ValueError: print('净利润数据为:--,无法计算,则忽略') SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = '' else: print('未上市的财报不需要处理') # print('有问题的数据 first:{},second:{}'.format(first_data['YEAREND_DATE'], second_data['YEAREND_DATE'])) SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = '' except IndexError: first_data = lrb_data[i] # print('最后一条数据,不需要进行任何操作first: {}'.format(first_data['YEAREND_DATE'])) SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float( first_data['VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN']) lrb_data[i][ 'SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'] = SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, lrb_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.lrb', lrb_data) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': lrb_data[0]['YEAREND_DATE'], 'report': { 'lrb': lrb_data } })
def zcfzb(response, stock_code): ''' :param response: 资产负债表的数据 str :param stock_code: 股票代码 :return: ''' zd_list = [ "YEAREND_DATE", "CURRENCY_CAPITAL", "SETTLEMENT_RESERVE", "DEMOLITION_CAPITAL", "TRANSACTIONAL_ASS", "DERIVATIVE_ASS", "BILL_RECEIVABLE", "ACCOUNTS_RECEIVABLE", "ADVANCE_PAYMENT", "PREMIUMS_RECEIVABLE", "ACCOUNT_REINSURANCE_RECEIVABLE", "RESERVE_CONTRACT_REINSURANCE_REVEIVABLE", "INTEREST_DECIVABLE", "DIVIDEND_DECIVABLE", "OTHER_DECIVABLES", "EXPORT_REBATE_DECIVABLE", "SUBSIDYS_DECIVABLE", "CASH_DEPOSIT_AS_COLLATERAL_DECIVABLE", "INTERNAL_RECEIVABLE", "BUY_BACK_THE_SALE_OF_FINANCIAL_ASS", "STOCK", "DEFERRED_EXPENSES", "PENDING_CURRENT_ASSETS_PROFIT_LOSS", "NON_CURRENT_ASSETS_DUE_WITHIN_ONE_YEAR", "OTHER_CURRENT_ASSETS", "TOTAL_CURRENT_ASSETS", "LOANS_AND_ADVANCES", "FINANCIAL_ASSETS_AVAILABLE_FOR_SALE", "HOLDING_TO_MATURIY_INVESTMENT", "LONG_TERM_RECIVABLES", "LONG_TERM_EQUITY_INVESTMENT", "OTHER_LONG_TERM_INVESTMENT", "INVESTMENT_REAL_ESTATE", "ORIGINAL_VALUE_OF_FIXED_ASSETS", "ACCUMULATED_DEPRECIATION", "NET_VALUE_OF_FIXED_ASSETS", "FIXED_ASSETS_IMPAIRMENT_RESERVES", "FIXED_ASSETS", "CONSTRUCTION_IN_PROCESS", "ENGINEERING_MATERIALS", "CLEAR_OF_FIXED_ASSETS", "BIOLOGICAL_ASSETS", "PUBLIC_WELFARE_BIOLOGICAL_ASSETS", "OIL_AND_GAS_ASSETS", "IMMATERIAL_ASSETS", "DEVELOPMENT_AMOUNT_OF_EXPENDITURE", "GOODWILL", "LONG_TERM_PREPAID_EXPENSES", "RIGHT_OF_SPLIT_SHARE_CIRCULATION", "DEFERRED_TAX_ASSETS", "OTHER_NON_CURRENT_ASSETS", "TOTAL_NON_CURRENT_ASSETS", "TOTAL_ASSETS", "MONEY_BORROWED_FOR_SHORT_TIME", "BORROWING_FROM_THE_CENTRAL_BANK", "DEPOSIT_TAKING_AND_INTERBANK_DEPOSIT", "LOANS_FROM_OTHER_BANKS", "TRANSACTIONAL_FINANCIAL_LIABILTIES", "DERIVATIVE_FINANCIAL_LIABILTIES", "BILL_PAYABLE", "ACCOUNTS_PAYABLE", "DEPOSIT_RECEIVED", "FINANCIAL_ASSETS_SOLD_FOR_REPURCHASE", "HANDING_FEE_AND_COMMISSION", "SALARY_PAYABLE_TO_EMPLOYEES", "TAX_PAYABLE", "INTEREST_PAYABLE", "DIVIDENDS_PAYABLE", "OTHER_ACCOUNTS_PAYABLES", "MARGIN_PAYABLE", "INTERNAL_PAYABLES", "OTHER_PAYABLE", "ACCRUED_EXPENSES", "PROJECTED_CURRENT_LIABILITIES", "ACCOUNTS_PAYABLE_REINSURANCE", "INSURANCE_CONTRACT_RESERVES", "BUY_ANDSELL_SECURITIES_BY_PROXY", "ACTING_UNDERWEITING_SECURITIES", "INTERNATIONAL_TICKET_SETTLAEMENT", "DOMESTIC_TICKET_SETTLAEMENT", "DEFERRED_INCOME", "SHORT_TERM_BONDS_PAYABLE", "NON_CURRENT_LIABILITIES_DUE_WITHIN_ONE_YEAR", "OTHER_CURRENT_LIABILITIES", "TOTAL_CURRENT_LIABILITIES", "LONG_TERM_LOAN", "BONDS_PAYABLE", "LONG_TERM_PAYABLES", "ACCOUNT_PAYABLE_SPECIAL_FUNDS", "PROJECTED_NON)CURRENT_LIABILITIES", "LONG_TERM_DEFERRED_INCOME", "DEFERRED_TAX_LIABILITY", "OTHER_NON_CURRENT_LIABILTIES", "TOTAL_NON_CURRENT_LIABILTIES", "TOTAL_LIABILITIES", "PAID_IN_CAPITAL", "CAPITAL_SURPLUS", "REDUCE:STOCK_THIGH", "SPECIAL_RESERVE", "SURPLUS_PUBLIC_ACCUMULATION", "GENERAL_RISK_RESERVE", "UNCERTAIN_INVESTMENT_LOSS", "UNDISTRIBUTED_PROFIT", "QUASI_DISTRIBUTIVE_CASH)DIVIDEND", "CONVERSION_BALANCE_OF_FOREIGN_CURRENCY_STATEMENTS", "TOTAL_EQUITY_ATTRIBUTABLE_TO_SHAREHOLDERS_OF_THE_PARENT_COMPANY", "MINORITY_SHAREHOLDER_RIGHT_AND_INTERESTS", "OWNER_S_EQUITY", "LIABILITIES_AND_OWNER_S_EQUITY", ] zcfzb_data = [{j[0]: j[1] for j in i} for i in (zip(zd_list, it) for it in zip(*[ item.strip().split(",")[1:-1] for item in response.text.strip().split("\n") ]))] db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code, 'financial_report_date') if db_report_date: if date_turn_timestamp(db_report_date, zcfzb_data[0]['YEAREND_DATE']): LmInnerReportDBMgr.save_set_result('lm_stock_data', {'code': stock_code}, 'report.zcfzb', zcfzb_data) LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': zcfzb_data[0]['YEAREND_DATE'], }) else: LmInnerReportDBMgr.save_insert_result( 'lm_stock_data', { 'code': stock_code, 'financial_report_date': zcfzb_data[0]['YEAREND_DATE'], 'report': { 'zcfzb': zcfzb_data } })
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' Create : 2017/12/20 下午4:12 Author : Richard Chen File : test.py Software: IntelliJ IDEA ''' import xlrd from common.db_utils.stock_crawler_inner_db import LmInnerReportDBMgr data = xlrd.open_workbook('000016cons.xls') table = data.sheets()[0] cols_code = table.col_values(0) cols_name = table.col_values(1) for i in range(1, len(cols_code)): LmInnerReportDBMgr.save_push_result('lm_index_data', {'code': '000016'}, 'component_stock_dict.20170612', { 'code': cols_code[i], 'name': cols_name[i] }) if __name__ == '__main__': pass