mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Fetch latest posts from forum.wownero.com
This commit is contained in:
parent
ed952c1ec5
commit
8e1c33ff3e
4 changed files with 58 additions and 2 deletions
|
@ -59,7 +59,7 @@ async def _setup_tasks(app: Quart):
|
|||
from wowlet_backend.tasks import (
|
||||
BlockheightTask, HistoricalPriceTask, FundingProposalsTask,
|
||||
CryptoRatesTask, FiatRatesTask, RedditTask, RPCNodeCheckTask,
|
||||
XmrigTask, SuchWowTask, WowletReleasesTask)
|
||||
XmrigTask, SuchWowTask, WowletReleasesTask, ForumThreadsTask)
|
||||
|
||||
asyncio.create_task(BlockheightTask().start())
|
||||
asyncio.create_task(HistoricalPriceTask().start())
|
||||
|
@ -70,6 +70,7 @@ async def _setup_tasks(app: Quart):
|
|||
asyncio.create_task(XmrigTask().start())
|
||||
asyncio.create_task(SuchWowTask().start())
|
||||
asyncio.create_task(WowletReleasesTask().start())
|
||||
asyncio.create_task(ForumThreadsTask().start())
|
||||
|
||||
if settings.COIN_SYMBOL in ["xmr", "wow"]:
|
||||
asyncio.create_task(FundingProposalsTask().start())
|
||||
|
|
|
@ -167,3 +167,4 @@ from wowlet_backend.tasks.rpc_nodes import RPCNodeCheckTask
|
|||
from wowlet_backend.tasks.xmrig import XmrigTask
|
||||
from wowlet_backend.tasks.suchwow import SuchWowTask
|
||||
from wowlet_backend.tasks.wowlet import WowletReleasesTask
|
||||
from wowlet_backend.tasks.forum import ForumThreadsTask
|
54
wowlet_backend/tasks/forum.py
Normal file
54
wowlet_backend/tasks/forum.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright (c) 2020, The Monero Project.
|
||||
# Copyright (c) 2020, dsc@xmr.pm
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from typing import List
|
||||
from dateutil.parser import parse
|
||||
|
||||
import settings
|
||||
from wowlet_backend.utils import httpget
|
||||
from wowlet_backend.tasks import WowletTask
|
||||
|
||||
|
||||
class ForumThreadsTask(WowletTask):
|
||||
"""Fetch recent forum threads."""
|
||||
def __init__(self, interval: int = 300):
|
||||
from wowlet_backend.factory import app
|
||||
super(ForumThreadsTask, self).__init__(interval)
|
||||
|
||||
self._cache_key = "forum"
|
||||
self._cache_expiry = self.interval * 10
|
||||
|
||||
# url
|
||||
self._http_endpoint = "https://forum.wownero.com/latest.json"
|
||||
|
||||
self._websocket_cmd = "forum"
|
||||
|
||||
async def task(self):
|
||||
from wowlet_backend.factory import app
|
||||
|
||||
blob = await httpget(self._http_endpoint, json=True)
|
||||
|
||||
users = {z['id']: z for z in blob["users"]}
|
||||
|
||||
topics = []
|
||||
for topic in blob['topic_list']['topics']:
|
||||
if topic.get("pinned_globally", True):
|
||||
continue
|
||||
|
||||
try:
|
||||
u = next(z for z in topic["posters"] if "original poster" in z['description'].lower())['user_id']
|
||||
href = f"https://forum.wownero.com/t/{topic['slug']}"
|
||||
topics.append({
|
||||
"id": topic["id"],
|
||||
"title": topic["title"],
|
||||
"comments": topic["posts_count"] - 1,
|
||||
"created_at": parse(topic["created_at"]).strftime("%Y-%m-%d %H:%M"),
|
||||
"author": users[u]['username'],
|
||||
"permalink": href
|
||||
})
|
||||
except Exception as ex:
|
||||
app.logger.error(f"skipping a forum topic; {ex}")
|
||||
|
||||
return topics[:25]
|
|
@ -85,7 +85,7 @@ async def feather_data():
|
|||
data = json.loads(data)
|
||||
return data
|
||||
|
||||
keys = ["blockheights", "funding_proposals", "crypto_rates", "fiat_rates", "reddit", "rpc_nodes", "xmrig", "xmrto_rates", "suchwow"]
|
||||
keys = ["blockheights", "funding_proposals", "crypto_rates", "fiat_rates", "reddit", "rpc_nodes", "xmrig", "xmrto_rates", "suchwow", "forum"]
|
||||
data = {keys[i]: json.loads(val) if val else None for i, val in enumerate(await cache.mget(*keys))}
|
||||
|
||||
# @TODO: for backward-compat reasons we're including some legacy keys which can be removed after 1.0 release
|
||||
|
|
Loading…
Reference in a new issue