def retrieveToken(self, code, url, service): data = { "grant_type": "authorization_code", "client_id": client(service)["id"], "client_secret": client(service)["secret"], "redirect_uri": cfg["redirect_uri"], "code": code } log.info("Requesting token") token = requests.post(url, data) log.info(f"Request returned: {token}") print(f"Token Data: {token.text} - {token}") cfg[f"{service}_token"] = json.loads(token.text)["access_token"] if cfg["pb_token"] != "" and cfg["sl_token"] != "": log.info("Saving tokens to settings.json") configurator.CFG().save("settings.json", cfg) log.info("Stopping server") raise StopServer()
import sys, json, asyncio import configurator log = configurator.LOG.get() cfg = configurator.CFG().load("settings.json") class Alerts(): def __init__(self): modules = ("websockets", "requests") # Check if required modules are imported for module in modules: if module not in sys.modules or module not in globals(): log.info(f"Importing modules: {modules}") global websockets, requests import websockets, requests break async def startReceiving(self): if "json" not in sys.modules: global json import json log.info("Connecting to Pushbullet WSS stream") async with websockets.connect( f"wss://stream.pushbullet.com/websocket/{cfg['pb_token']}" ) as websocket: while True: data = await websocket.recv()
def save(self, values): cfg["language"] = values["_COMBO_LANG_"] cfg["default_name"] = values["_INPUT_NAME_"] cfg["default_msg"] = values["_INPUT_MSG_"] configurator.CFG().save("settings.json", cfg)
def resetConfig(self): log.info("Resetting config!") configurator.CFG().reset("settings.json")
import os, subprocess import PySimpleGUIQt as sg import configurator, authentication, qr log = configurator.LOG.get() cfg = configurator.CFG().load("settings.json") lang = configurator.CFG().load("language.json") text = configurator.CFG().load("language.json")[cfg["language"].lower()] for key, value in lang["common"].items(): text[key] = value class GUI(): def __init__(self): self.WINDOW_TITLE = "MobilePayAlerts" self.event_combiner = {"_BTN_GENQR_": qr.generate} tab_1 = sg.Tab(text["tab_1"]["text"], [[ sg.HorizontalSeparator() ], [ sg.Button("Start", key="_BTN_START_", size=(250, 40), visible=True) ], [ sg.HorizontalSeparator() ], [ sg.Button("Stop", key="_BTN_STOP_", size=(250, 40), visible=False) ], [ sg.HorizontalSeparator() ], [sg.Button("Test", key="_BTN_TEST_", size=(250, 40), visible=True)], [sg.HorizontalSeparator()]])