self.national_debt_path = base_path + 'national_debt/' def download_bond_excel(self, year): try: r = requests.get(self.national_debt_url, stream=True, params={ "year": year }) if r.status_code == requests.codes.ok: output = open(self.national_debt_path + str(year) + '_national_debt.xls', 'wb') output.write(r.content) output.close() except (IOError, RuntimeError): logging.exception('save national debt excel file failed') return False return True if __name__ == '__main__': jsonpickle.set_encoder_options('simplejson', sort_keys=True, indent=4) my_props = PropertiesReader.get_properties() bond_path = my_props['MktDataLoader.Bond'] national_debt_path = my_props['MktDataLoader.Bond.national.debt'] log_path = bond_path + "log/log_" + time.strftime("%Y%m%d_%H_%M_%S", time.localtime()) + ".txt" logging.basicConfig(filename=log_path, level=logging.INFO) manager = BondManager(bond_path) cmd_string = 'download_national_debt' if cmd_string == 'download_national_debt': manager.download_bond_excel(date.today().year) print 'download class info finished'
if is_first_year: quarter = quarter_from is_first_year = False else: quarter = 1 last_quarter = 4 if year == year_to: last_quarter = quarter_to while quarter <= last_quarter: print '\ndownload reports: ', year, '-', quarter, '\n' download_report_info(file_path, year, quarter) download_profit_data(file_path, year, quarter) download_operation_data(file_path, year, quarter) download_growth_data(file_path, year, quarter) download_debtpaying_data(file_path, year, quarter) download_cashflow_data(file_path, year, quarter) quarter += 1 year += 1 print 'download report_data finished\n' if __name__ == '__main__': my_props = PropertiesReader.get_properties() get_basic_info( my_props['MktDataLoader.Fundamental.Class.stock_basics']) # 沪深上市公司基本情况 get_report_info(my_props['MktDataLoader.Fundamental.reports'], 1993, 1, 2015, 4) print 'download class info finished'