From f9612c9cc2aafa29d270ba4cb28703c4d9be7ab1 Mon Sep 17 00:00:00 2001 From: pengtao Date: Fri, 20 Sep 2019 15:43:24 +0800 Subject: [PATCH] =?UTF-8?q?jc=5Fshow=20=E6=97=A5=E5=BF=97=E6=8B=86?= =?UTF-8?q?=E5=88=86=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_new_user.py | 1 + jc_show_rewrite.py | 115 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 jc_show_rewrite.py diff --git a/get_new_user.py b/get_new_user.py index 0f8f566..56c9d33 100644 --- a/get_new_user.py +++ b/get_new_user.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# http://mp.kingsome.cn/api/open/ad-uid?gameid=8002&channelid=6001 from ops.mtga import FromTga, GetTgaConfig from ops.plog import define_logger import logging diff --git a/jc_show_rewrite.py b/jc_show_rewrite.py new file mode 100644 index 0000000..a1ac390 --- /dev/null +++ b/jc_show_rewrite.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +# http://mp.kingsome.cn/api/open/ad-uid?gameid=8002&channelid=6001 +from ops.mtga import FromTga, GetTgaConfig +from ops.plog import define_logger +import logging +import datetime +import json +import pdb + +define_logger("/data/logs/jc_show_split.log") +log = logging.getLogger(__name__) + + +# DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'} + +class JcShowInit: + def __init__(self, kwargs): + self.time = kwargs.get('time') + 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 = 99 + # 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) + self.event_type = "jc_show" + + def get_data(self): + sql = f"""SELECT + "#account_id", + button_param + FROM + v_event_{self.suffix} + where + gameid='{self.gameid}' + and channel={self.channelid} + and "$part_event"='event_11_31' + and "button_name" ='jc_show' + and "$part_date"={self.time} + """ + data = self.tga.get_data(sql) + all = list() + if data: + for line in data: + if line: + all.append(line) + return all + + def write_tga_files(self, data): + try: + tga_data = {} + tga_data['ad_channel'] = data['ad_channel'] + tga_data['account_id'] = data['account_id'] + tga_data['gameid'] = self.gameid + tga_data['channelid'] = self.channelid + tga_data['location'] = data['location'] + self.tga.put_event_data(tga_data, f'rep_{self.event_type}') + except Exception: + log.error(f"write 2 tga failed!,context={data}", exc_info=True) + + def split_event19(self, data): + """6001_1004_oQmL74ij2oq3SyvO6QriuD0EJSjE + {"ad_id":["1039","1035","1037","1036","1038","1040"],"pos":"1,0,5,0,0","ad_channel":["wxdb103a128e118619","wxf4b70c770560c2fe","wx7d84fae7fe8796d7","wx1dd2f605f4f8496b","wx2f6ebc0586e24d61","wx0e14c9f4c4a06870"]}""" + for line in data: + account, data_dict = line + temp = {} + temp['account_id'] = account + temp['location'] = data_dict['pos'] + if data_dict['ad_channel']: + for ad_channel in data_dict['ad_channel']: + temp['ad_channel'] = ad_channel + self.write_tga_files(temp) + del temp + + + def split_event22(self, data): + """{"pos":3,"channelid":6001,"ad_channel":["9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","9b4c1yxtv5","yx2nyabgm8","yx2nyabgm8","yx2nyabgm8","yx2nyabgm8","yx2nyabgm8","yx2nyabgm8","9f97o1xz44","9f97o1xz44","9f97o1xz44","9f97o1xz44","s4fxu9w1yb","s4fxu9w1yb","s4fxu9w1yb","s4fxu9w1yb","49nnealk3i","49nnealk3i"]}""" + for line in data: + account, data_dict = line + temp = {} + temp['account_id'] = account + temp['location'] = data_dict['pos'] + if data_dict['ad_channel']: + for ad_channel in data_dict['ad_channel']: + temp['ad_channel'] = ad_channel + self.write_tga_files(temp) + del temp + + def run(self): + data = self.get_data() + if data: + if self.suffix == 19: + self.split_event19(data) + elif self.suffix == 22: + self.split_event22(data) + else: + log.error(f"{self.gameid} {self.channelid} not found in define!") + raise Exception(f"{self.gameid} {self.channelid} not found in define!") + + +def main(): + kwargs = {} + kwargs['time'] = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d') + kwargs['gameid'] = 2001 + kwargs['channelid'] = 6001 + jc = JcShowInit(kwargs) + jc.run() + + +if __name__ == "__main__": + main()