From 6122c05311e54c96d7485f67edc7b5ae0168db1a Mon Sep 17 00:00:00 2001 From: pengtao Date: Wed, 16 Oct 2019 11:34:01 +0800 Subject: [PATCH] =?UTF-8?q?tap=20order=20=20=E6=95=B0=E6=8D=AE=E5=86=99?= =?UTF-8?q?=E5=85=A5mysql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- taptap/taptap_report.py | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 taptap/taptap_report.py diff --git a/taptap/taptap_report.py b/taptap/taptap_report.py new file mode 100644 index 0000000..c663138 --- /dev/null +++ b/taptap/taptap_report.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +from ops.mtga import FromTga +from ops.plog import define_logger +from ops.mmysql import MysqlBase +import logging +import datetime +import sys +from bson.objectid import ObjectId +import json + +define_logger("/data/logs/ops/taptap_report.log") +log = logging.getLogger(__name__) + + +class TapTapReport: + def __init__(self, day): + self.db_conf = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'external_data'} + self.url = "http://10.10.3.17:8992/querySql" + self.api_secret = "n9H4R32ZcjtSeN89ljCY6ESzTmOlnwwnOB3r4YsggnP5M1AXLtKtiS4sS1KKLOEQ" + self.tga = FromTga(url=self.url, token=self.api_secret) + self.day = day + + + def build_report(self): + pass + + def get_order(self): + sql = f""" + SELECT + gameid, + catename, + "order" + FROM + v_event_25 + WHERE + "$part_date"='{self.day}' + + """ + data = self.tga.get_data(sql) + if data: + self.order2mysql(data) + return True + else: + return False + + def order2mysql(self, data): + mydb = MysqlBase(**self.db_conf) + table_name = "external_data" + for line in data: + temp = {} + try: + temp["gameid"], temp["catename"], temp["order"] = line + mydb.insert(table_name, temp) + except Exception: + log.error(f"instert {line} 2 db failed", exc_info=True) + + +def main(): + day = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d') + tap = TapTapReport(day) + tap.get_order() + + +if __name__ == "__main__": + main()