Пример #1
0
 def download_tick(self, response):
     content_type_header = response.headers.get('content-type', None)
     if content_type_header.decode(
             "utf-8"
     ) == 'application/vnd.ms-excel' or "当天没有数据" in response.body.decode(
             'GB2312'):
         trading_date = response.meta['trading_date']
         security_item = response.meta['item']
         if content_type_header.decode(
                 "utf-8") == 'application/vnd.ms-excel':
             content = response.body
         else:
             kdata_df = get_kdata(security_item, the_date=trading_date)
             if trading_date in kdata_df.index:
                 json_data = kdata_df.loc[trading_date, :]
                 content = kdata_to_tick(json_data)
                 self.logger.info(
                     "{} {} generate tick from kdata {}".format(
                         security_item['code'], trading_date, content))
                 content = content.encode('GB2312')
         sina_tick_to_csv(security_item, io.BytesIO(content), trading_date)
     else:
         self.logger.exception(
             "get tick error:url={} content type={} body={}".format(
                 response.url, content_type_header, response.body))
Пример #2
0
 def download_tick(self, response):
     content_type_header = response.headers.get('content-type', None)
     if content_type_header.decode("utf-8") == 'application/vnd.ms-excel' or "当天没有数据" in response.body.decode(
             'GB2312'):
         trading_date = response.meta['trading_date']
         security_item = response.meta['item']
         if content_type_header.decode("utf-8") == 'application/vnd.ms-excel':
             content = response.body
         else:
             kdata_json = get_kdata(security_item, trading_date).to_json()
             content = kdata_to_tick(kdata_json)
             self.logger.info("{} {} generate tick from kdata {}", security_item['code'], trading_date, content)
             content = content.encode('GB2312')
         sina_tick_to_csv(security_item, io.BytesIO(content), trading_date)
     else:
         self.logger.error(
             "get tick error:url={} content type={} body={}".format(response.url, content_type_header,
                                                                    response.body))