mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
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
This commit is contained in:
commit
98b36d0c6f
4 changed files with 26 additions and 23 deletions
|
@ -10,4 +10,3 @@ psutil
|
||||||
psutil
|
psutil
|
||||||
pillow-simd
|
pillow-simd
|
||||||
python-magic
|
python-magic
|
||||||
semver
|
|
|
@ -2,11 +2,13 @@
|
||||||
# Copyright (c) 2020, The Monero Project.
|
# Copyright (c) 2020, The Monero Project.
|
||||||
# Copyright (c) 2020, dsc@xmr.pm
|
# Copyright (c) 2020, dsc@xmr.pm
|
||||||
|
|
||||||
|
import json
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
from wowlet_backend.utils import httpget
|
from wowlet_backend.utils import httpget
|
||||||
from wowlet_backend.tasks import WowletTask
|
from wowlet_backend.tasks import WowletTask
|
||||||
|
from wowlet_backend.factory import cache
|
||||||
|
|
||||||
|
|
||||||
class CryptoRatesTask(WowletTask):
|
class CryptoRatesTask(WowletTask):
|
||||||
|
@ -69,6 +71,16 @@ class CryptoRatesTask(WowletTask):
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
app.logger.error(f"extra coin: {coin}; {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:
|
try:
|
||||||
# additional call to fetch 24h pct change
|
# 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"
|
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
|
pass
|
||||||
|
|
||||||
rates.append(obj)
|
rates.append(obj)
|
||||||
|
|
||||||
return rates
|
return rates
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# Copyright (c) 2020, The Monero Project.
|
# Copyright (c) 2020, The Monero Project.
|
||||||
# Copyright (c) 2020, dsc@xmr.pm
|
# Copyright (c) 2020, dsc@xmr.pm
|
||||||
|
|
||||||
import semver
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
@ -16,7 +15,7 @@ class WowletReleasesTask(WowletTask):
|
||||||
super(WowletReleasesTask, self).__init__(interval)
|
super(WowletReleasesTask, self).__init__(interval)
|
||||||
|
|
||||||
self._cache_key = "wowlet_releases"
|
self._cache_key = "wowlet_releases"
|
||||||
self._cache_expiry = self.interval * 10
|
self._cache_expiry = self.interval
|
||||||
|
|
||||||
self._websocket_cmd = "wowlet_releases"
|
self._websocket_cmd = "wowlet_releases"
|
||||||
|
|
||||||
|
@ -45,25 +44,19 @@ class WowletReleasesTask(WowletTask):
|
||||||
"size": asset['size']
|
"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 {
|
return {
|
||||||
"assets": data,
|
"assets": data,
|
||||||
"body": blob['body'],
|
"body": blob['body'],
|
||||||
"version": {
|
"version": tag
|
||||||
"major": _semver.major,
|
|
||||||
"minor": _semver.minor,
|
|
||||||
"patch": _semver.patch
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]}")
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ async def feather_data():
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
return 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))}
|
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
|
# @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