Browse Source

Merge pull request 'version format and coingecko caching' (#13) from semver-and-cache into master

Reviewed-on: https://git.wownero.com/wownero/wowlet-backend/pulls/13
master
wowario 1 month ago
parent
commit
98b36d0c6f
  1. 3
      requirements.txt
  2. 13
      wowlet_backend/tasks/rates_crypto.py
  3. 31
      wowlet_backend/tasks/wowlet.py
  4. 2
      wowlet_backend/utils.py

3
requirements.txt

@ -9,5 +9,4 @@ python-dateutil
psutil
psutil
pillow-simd
python-magic
semver
python-magic

13
wowlet_backend/tasks/rates_crypto.py

@ -2,11 +2,13 @@
# Copyright (c) 2020, The Monero Project.
# Copyright (c) 2020, dsc@xmr.pm
import json
from typing import List, Union
import settings
from wowlet_backend.utils import httpget
from wowlet_backend.tasks import WowletTask
from wowlet_backend.factory import cache
class CryptoRatesTask(WowletTask):
@ -69,6 +71,16 @@ class CryptoRatesTask(WowletTask):
except Exception as ex:
app.logger.error(f"extra coin: {coin}; {ex}")
# use cache if present
data = await cache.get(self._cache_key)
if data:
data = json.loads(data)
extra_coin = [e for e in data if e['symbol'] == symbol]
if extra_coin:
app.logger.warning(f"using cache for extra coin: {coin}")
rates.append(extra_coin[0])
continue
try:
# additional call to fetch 24h pct change
url = f"{self._http_api_gecko}/coins/{coin}?tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"
@ -78,5 +90,4 @@ class CryptoRatesTask(WowletTask):
pass
rates.append(obj)
return rates

31
wowlet_backend/tasks/wowlet.py

@ -2,7 +2,6 @@
# Copyright (c) 2020, The Monero Project.
# Copyright (c) 2020, dsc@xmr.pm
import semver
from dateutil.parser import parse
import settings
@ -16,7 +15,7 @@ class WowletReleasesTask(WowletTask):
super(WowletReleasesTask, self).__init__(interval)
self._cache_key = "wowlet_releases"
self._cache_expiry = self.interval * 10
self._cache_expiry = self.interval
self._websocket_cmd = "wowlet_releases"
@ -45,25 +44,19 @@ class WowletReleasesTask(WowletTask):
"size": asset['size']
}
_semver = self.parse_semver(blob)
tag = blob['tag_name']
if tag.startswith("v"):
tag = tag[1:]
try:
t = [int(z) for z in tag.split(".")]
if len(t) != 3:
raise Exception()
except:
raise Exception(f"invalid tag: {tag}")
return {
"assets": data,
"body": blob['body'],
"version": {
"major": _semver.major,
"minor": _semver.minor,
"patch": _semver.patch
}
"version": tag
}
def parse_semver(self, blob):
tag = blob['tag_name'] # valid tag name example: v0.2.0.0
if tag.startswith("v"):
tag = tag[1:]
tag = tag.split(".")
tag = [t for t in tag if t.isdigit()]
if tag[0] == '0':
tag = tag[1:]
return semver.VersionInfo.parse(f"{tag[0]}.{tag[1]}.{tag[2]}")

2
wowlet_backend/utils.py

@ -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", "forum"]
keys = ["blockheights", "funding_proposals", "crypto_rates", "fiat_rates", "reddit", "rpc_nodes", "xmrig", "xmrto_rates", "suchwow", "forum", "wowlet_releases"]
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…
Cancel
Save