from handlers.HandlerBase import BaseHandler
from model.DataBaseUtils import MysqlUtils
import json
import requests
from model.DataBaseUtils import MysqlUtils


class WxGameApiHandler(BaseHandler):

    def get(self):
        import base64
        print(self.request.query_arguments)
        print(base64.b64encode(str(self.request.query_arguments).encode('utf-8')))
        wx_info=base64.b64encode(str(self.request.query_arguments).encode('utf-8')).decode('utf-8')
        print('微信游戏get',self.request.body.decode(encoding='utf-8'))

        sql=f'''replace into wx_game(wx_info) values ('{wx_info}')  '''
        print(sql)
        MysqlUtils().quchen_text.execute(sql)
        print("入库成功")
        self.write(json.dumps({"code":200,"msg":"ok"}))

    def post(self):

        print('微信游戏post',self.request.body.decode(encoding='utf-8'))
        # path=self.get_args()["path"]
        # task_id=self.get_args()["taskId"]
        # print(path)
        # MysqlUtils().quchen_text.execute(f"update yangguang_path set path='{path}' where task_id='{task_id}'")
        self.write(json.dumps({"code":200,"msg":"ok"}))


class YgApiHandler(BaseHandler):

    def post(self):
        print(self.get_args())
        path=self.get_args()["path"]
        task_id=self.get_args()["taskId"]
        print(path)
        MysqlUtils().quchen_text.execute(f"update yangguang_path set path='{path}' where task_id='{task_id}'")
        self.write(json.dumps({"code":200,"msg":"ok"}))


class TtApiHandler(BaseHandler):

    def get(self):
        print('今日头条',self.request.body.decode(encoding='utf-8'))
        print(self.get_args())
        path=self.get_args()["path"]
        task_id=self.get_args()["taskId"]
        print(path)
        # MysqlUtils().quchen_text.execute(f"update yangguang_path set path='{path}' where task_id='{task_id}'")
        self.write(json.dumps({"code":200,"msg":"ok"}))

    def post(self):
        print('今日头条',self.request.body.decode(encoding='utf-8'))
        print(self.get_args())
        path=self.get_args()["path"]
        task_id=self.get_args()["taskId"]
        print(path)
        # MysqlUtils().quchen_text.execute(f"update yangguang_path set path='{path}' where task_id='{task_id}'")
        self.write(json.dumps({"code":200,"msg":"ok"}))