From 891baaff711f64130cd45b9c9c4618170311baa8 Mon Sep 17 00:00:00 2001 From: dsc Date: Mon, 3 May 2021 00:36:44 +0200 Subject: [PATCH] Introduce websocket cmd for SuchWow so that it can dynamically add/update new images and change FeatherTask to WowletTask --- wowlet_backend/tasks/__init__.py | 2 +- wowlet_backend/tasks/blockheight.py | 4 ++-- wowlet_backend/tasks/historical_prices.py | 4 ++-- wowlet_backend/tasks/proposals.py | 4 ++-- wowlet_backend/tasks/rates_crypto.py | 4 ++-- wowlet_backend/tasks/rates_fiat.py | 4 ++-- wowlet_backend/tasks/reddit.py | 4 ++-- wowlet_backend/tasks/rpc_nodes.py | 4 ++-- wowlet_backend/tasks/suchwow.py | 11 ++++++----- wowlet_backend/tasks/xmrig.py | 4 ++-- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/wowlet_backend/tasks/__init__.py b/wowlet_backend/tasks/__init__.py index 2bff2c4..c8e7071 100644 --- a/wowlet_backend/tasks/__init__.py +++ b/wowlet_backend/tasks/__init__.py @@ -8,7 +8,7 @@ import random from typing import Union -class FeatherTask: +class WowletTask: """ The base class of many recurring tasks for this project. This abstracts away some functionality: diff --git a/wowlet_backend/tasks/blockheight.py b/wowlet_backend/tasks/blockheight.py index f0798aa..0e3f50b 100644 --- a/wowlet_backend/tasks/blockheight.py +++ b/wowlet_backend/tasks/blockheight.py @@ -9,10 +9,10 @@ from functools import partial import settings from wowlet_backend.utils import httpget, popularity_contest -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class BlockheightTask(FeatherTask): +class BlockheightTask(WowletTask): """ Fetch latest blockheight using webcrawling. We pick the most popular height from a list of websites. Arguably this approach has benefits diff --git a/wowlet_backend/tasks/historical_prices.py b/wowlet_backend/tasks/historical_prices.py index fdd6061..1ed0e44 100644 --- a/wowlet_backend/tasks/historical_prices.py +++ b/wowlet_backend/tasks/historical_prices.py @@ -12,10 +12,10 @@ import aiofiles import settings from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class HistoricalPriceTask(FeatherTask): +class HistoricalPriceTask(WowletTask): """ This class manages a historical price (USD) database, saved in a textfile at `self._path`. A Feather wallet instance will ask diff --git a/wowlet_backend/tasks/proposals.py b/wowlet_backend/tasks/proposals.py index 1bd30ae..b7d5aed 100644 --- a/wowlet_backend/tasks/proposals.py +++ b/wowlet_backend/tasks/proposals.py @@ -7,10 +7,10 @@ from typing import List import settings from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class FundingProposalsTask(FeatherTask): +class FundingProposalsTask(WowletTask): """Fetch funding proposals made by the community.""" def __init__(self, interval: int = 600): from wowlet_backend.factory import app diff --git a/wowlet_backend/tasks/rates_crypto.py b/wowlet_backend/tasks/rates_crypto.py index 3c0cb44..2e60130 100644 --- a/wowlet_backend/tasks/rates_crypto.py +++ b/wowlet_backend/tasks/rates_crypto.py @@ -6,10 +6,10 @@ from typing import List, Union import settings from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class CryptoRatesTask(FeatherTask): +class CryptoRatesTask(WowletTask): def __init__(self, interval: int = 180): super(CryptoRatesTask, self).__init__(interval) diff --git a/wowlet_backend/tasks/rates_fiat.py b/wowlet_backend/tasks/rates_fiat.py index 260fb7c..3aae5df 100644 --- a/wowlet_backend/tasks/rates_fiat.py +++ b/wowlet_backend/tasks/rates_fiat.py @@ -6,10 +6,10 @@ from datetime import datetime, timedelta import re from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class FiatRatesTask(FeatherTask): +class FiatRatesTask(WowletTask): def __init__(self, interval: int = 43200): super(FiatRatesTask, self).__init__(interval) diff --git a/wowlet_backend/tasks/reddit.py b/wowlet_backend/tasks/reddit.py index 992f505..11bceee 100644 --- a/wowlet_backend/tasks/reddit.py +++ b/wowlet_backend/tasks/reddit.py @@ -5,10 +5,10 @@ import html import settings from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class RedditTask(FeatherTask): +class RedditTask(WowletTask): def __init__(self, interval: int = 900): from wowlet_backend.factory import app super(RedditTask, self).__init__(interval) diff --git a/wowlet_backend/tasks/rpc_nodes.py b/wowlet_backend/tasks/rpc_nodes.py index df46334..bdee002 100644 --- a/wowlet_backend/tasks/rpc_nodes.py +++ b/wowlet_backend/tasks/rpc_nodes.py @@ -7,10 +7,10 @@ from typing import List import settings from wowlet_backend.utils import httpget, popularity_contest -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class RPCNodeCheckTask(FeatherTask): +class RPCNodeCheckTask(WowletTask): def __init__(self, interval: int = 60): super(RPCNodeCheckTask, self).__init__(interval) diff --git a/wowlet_backend/tasks/suchwow.py b/wowlet_backend/tasks/suchwow.py index b09a511..03346b3 100644 --- a/wowlet_backend/tasks/suchwow.py +++ b/wowlet_backend/tasks/suchwow.py @@ -14,11 +14,11 @@ from bs4 import BeautifulSoup import settings from wowlet_backend.utils import httpget, image_resize -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class SuchWowTask(FeatherTask): - def __init__(self, interval: int = 600): +class SuchWowTask(WowletTask): + def __init__(self, interval: int = 300): """ This task is specifically for Wownero - fetching a listing of recent SuchWow submissions. @@ -31,15 +31,16 @@ class SuchWowTask(FeatherTask): self._http_endpoint = "https://suchwow.xyz/" self._tmp_dir = os.path.join(settings.cwd, "data", "suchwow") + self._websocket_cmd = "suchwow" + if not os.path.exists(self._tmp_dir): os.mkdir(self._tmp_dir) async def task(self): from wowlet_backend.factory import app - result = await httpget(f"{self._http_endpoint}api/list", json=True) + result = await httpget(f"{self._http_endpoint}api/list?limit=15&offset=0", json=True) result = list(sorted(result, key=lambda k: k['id'], reverse=True)) - result = result[:15] for post in result: post_id = int(post['id']) diff --git a/wowlet_backend/tasks/xmrig.py b/wowlet_backend/tasks/xmrig.py index a5533af..c274fe8 100644 --- a/wowlet_backend/tasks/xmrig.py +++ b/wowlet_backend/tasks/xmrig.py @@ -6,10 +6,10 @@ from dateutil.parser import parse import settings from wowlet_backend.utils import httpget -from wowlet_backend.tasks import FeatherTask +from wowlet_backend.tasks import WowletTask -class XmrigTask(FeatherTask): +class XmrigTask(WowletTask): """Fetches the latest XMRig releases using Github's API""" def __init__(self, interval: int = 43200): super(XmrigTask, self).__init__(interval)