# -*- coding: utf-8 -*- from ops.mtga import FromTga, GetTgaConfig from ops.plog import define_logger import logging import requests import json from config.config import is_debug, adv_id_state, ad_type define_logger("/data/logs/reports.log") log = logging.getLogger(__name__) class GetFromTga: def __init__(self, **kwargs): # log.info("begin collect gameid={},times={}!".format(kwargs.get('gameid'), kwargs.get('date'))) self.date = kwargs.get('date') self.gameid = kwargs.get('gameid') self.channelid = kwargs.get('channelid') g = GetTgaConfig() item = g.get_api_key(self.gameid) self.url = item['url'] self.tgaid = item['tgaid'] self.suffix = item.get('suffix', 0) self.api_key = item.get('api_key', None) self.tga = FromTga(self.url, self.api_key) self.tga.init_tga_write(self.tgaid) def write_tga_files(self, event_type, data): try: tga_tap = {} tga_tap['result'] = json.dumps(data, ensure_ascii=False) tga_tap['account_id'] = f"{self.gameid}_{self.channelid}" tga_tap['gameid'] = self.gameid tga_tap['channelid'] = self.channelid tga_tap['date'] = self.date if data: self.tga.put_event_data(tga_tap, f'rep_{event_type}') else: log.error(f"write {data} 2 tga!,event_type=f{event_type}", exc_info=True) except Exception: log.error(f"write 2 tga failed!", exc_info=True)