From 46083bbaa92ac5d16a046f4d32496adaeabdb5d4 Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Sun, 16 May 2021 08:34:35 +0530 Subject: [PATCH] active count feature created --- fishy/__main__.py | 4 ++++ fishy/helper/active_poll.py | 23 +++++++++++++++++++++++ fishy/web/urls.py | 1 + fishy/web/web.py | 6 ++++++ 4 files changed, 34 insertions(+) create mode 100644 fishy/helper/active_poll.py diff --git a/fishy/__main__.py b/fishy/__main__.py index 738bf9a..3a05c9a 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -13,6 +13,7 @@ from fishy.constants import chalutier, lam2 from fishy.engine.common.event_handler import EngineEventHandler from fishy.gui import GUI, splash, update_dialog from fishy.helper import hotkey +from fishy.helper.active_poll import active from fishy.helper.config import config @@ -67,6 +68,7 @@ def initialize(window_to_hide): def main(): + active.init() config.init() splash.start() print("launching please wait...") @@ -88,9 +90,11 @@ def main(): initialize(window_to_hide) gui_window.start() + active.start() bot.start_event_handler() config.stop() + active.stop() if __name__ == "__main__": diff --git a/fishy/helper/active_poll.py b/fishy/helper/active_poll.py new file mode 100644 index 0000000..6807b80 --- /dev/null +++ b/fishy/helper/active_poll.py @@ -0,0 +1,23 @@ +from event_scheduler import EventScheduler +from fishy.web import web + + +# noinspection PyPep8Naming +class active: + _scheduler: EventScheduler = None + + @staticmethod + def init(): + if active._scheduler: + return + + active._scheduler = EventScheduler() + active._scheduler.start() + + @staticmethod + def start(): + active._scheduler.enter_recurring(60, 1, web.ping) + + @staticmethod + def stop(): + active._scheduler.stop(hard_stop=True) diff --git a/fishy/web/urls.py b/fishy/web/urls.py index 21ea4a9..6c5d012 100644 --- a/fishy/web/urls.py +++ b/fishy/web/urls.py @@ -15,6 +15,7 @@ session = domain + "/api/session" terms = domain + "/terms.html" discord = domain + "/api/discord" beta = domain + "/api/beta" +ping = domain + "/api/ping" def get_notification_page(uid): diff --git a/fishy/web/web.py b/fishy/web/web.py index 12ae97a..83da91a 100644 --- a/fishy/web/web.py +++ b/fishy/web/web.py @@ -141,3 +141,9 @@ def has_beta(): return False return response.json()["beta"] + + +@fallback(None) +def ping(): + body = {"uid": config.get("uid"), "apiversion": apiversion} + requests.post(urls.ping, params=body)