mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Merge pull request 'Fetch latest XMRig release' (#2) from fetch-xmrig into master
Reviewed-on: https://git.wownero.com/feather/feather-ws/pulls/2
This commit is contained in:
commit
38e192ab5a
3 changed files with 67 additions and 1 deletions
|
@ -66,7 +66,7 @@ def create_app():
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
from fapi.fapi import FeatherApi
|
from fapi.fapi import FeatherApi
|
||||||
from fapi.utils import loopyloop, TxFiatDb
|
from fapi.utils import loopyloop, TxFiatDb, XmrRig
|
||||||
txfiatdb = TxFiatDb(settings.crypto_name, settings.crypto_block_date_start)
|
txfiatdb = TxFiatDb(settings.crypto_name, settings.crypto_block_date_start)
|
||||||
loop.create_task(loopyloop(20, FeatherApi.xmrto_rates, FeatherApi.after_xmrto))
|
loop.create_task(loopyloop(20, FeatherApi.xmrto_rates, FeatherApi.after_xmrto))
|
||||||
loop.create_task(loopyloop(120, FeatherApi.crypto_rates, FeatherApi.after_crypto))
|
loop.create_task(loopyloop(120, FeatherApi.crypto_rates, FeatherApi.after_crypto))
|
||||||
|
@ -76,6 +76,7 @@ def create_app():
|
||||||
loop.create_task(loopyloop(60, FeatherApi.blockheight, FeatherApi.after_blockheight))
|
loop.create_task(loopyloop(60, FeatherApi.blockheight, FeatherApi.after_blockheight))
|
||||||
loop.create_task(loopyloop(60, FeatherApi.check_nodes, FeatherApi.after_check_nodes))
|
loop.create_task(loopyloop(60, FeatherApi.check_nodes, FeatherApi.after_check_nodes))
|
||||||
loop.create_task(loopyloop(43200, txfiatdb.update))
|
loop.create_task(loopyloop(43200, txfiatdb.update))
|
||||||
|
loop.create_task(loopyloop(43200, XmrRig.releases, XmrRig.after_releases))
|
||||||
import fapi.routes
|
import fapi.routes
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
@ -12,6 +12,8 @@ from datetime import datetime
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
import settings
|
||||||
|
|
||||||
|
|
||||||
class BlockHeight:
|
class BlockHeight:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -161,3 +163,65 @@ class TxFiatDb:
|
||||||
self.data[_date.year][_date.month][_date.day] = v
|
self.data[_date.year][_date.month][_date.day] = v
|
||||||
|
|
||||||
self.write()
|
self.write()
|
||||||
|
|
||||||
|
|
||||||
|
class XmrRig:
|
||||||
|
@staticmethod
|
||||||
|
async def releases():
|
||||||
|
from fapi.factory import app, cache
|
||||||
|
from fapi.fapi import FeatherApi
|
||||||
|
|
||||||
|
blob = await FeatherApi.redis_get("xmrig_releases")
|
||||||
|
if blob and app.config["DEBUG"]:
|
||||||
|
return blob
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = await httpget(settings.urls["xmrig"])
|
||||||
|
if not isinstance(result, list):
|
||||||
|
raise Exception("JSON response was not a list")
|
||||||
|
if len(result) <= 1:
|
||||||
|
raise Exception("JSON response list was 1 or less")
|
||||||
|
result = result[0]
|
||||||
|
await cache.set("xmrig_releases", json.dumps(result))
|
||||||
|
blob = result
|
||||||
|
except Exception as ex:
|
||||||
|
app.logger.error(f"error parsing xmrig blob: {ex}")
|
||||||
|
if blob:
|
||||||
|
app.logger.warning(f"passing xmrig output from cache")
|
||||||
|
return blob
|
||||||
|
|
||||||
|
return blob
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def after_releases(data):
|
||||||
|
from fapi.factory import api_data
|
||||||
|
from dateutil.parser import parse
|
||||||
|
_data = []
|
||||||
|
for asset in data['assets']:
|
||||||
|
for expected in ["tar.gz", ".zip"]:
|
||||||
|
if asset["state"] != "uploaded":
|
||||||
|
continue
|
||||||
|
if asset["name"].endswith(expected):
|
||||||
|
_data.append(asset)
|
||||||
|
version = data['tag_name']
|
||||||
|
assets = {}
|
||||||
|
|
||||||
|
for asset in _data:
|
||||||
|
operating_system = "linux"
|
||||||
|
if "msvc" in asset['name'] or "win64" in asset['name']:
|
||||||
|
operating_system = "windows"
|
||||||
|
elif "macos" in asset["name"]:
|
||||||
|
operating_system = "macos"
|
||||||
|
|
||||||
|
assets.setdefault(operating_system, [])
|
||||||
|
assets[operating_system].append({
|
||||||
|
"name": asset["name"],
|
||||||
|
"created_at": parse(asset["created_at"]).strftime("%Y-%m-%d"),
|
||||||
|
"url": f"https://github.com/xmrig/xmrig/releases/download/{version}/{asset['name']}",
|
||||||
|
"download_count": int(asset["download_count"])
|
||||||
|
})
|
||||||
|
|
||||||
|
api_data["xmrig"] = {
|
||||||
|
"version": version,
|
||||||
|
"assets": assets
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ crypto_symbol = "xmr"
|
||||||
crypto_block_date_start = "20140418"
|
crypto_block_date_start = "20140418"
|
||||||
|
|
||||||
urls = {
|
urls = {
|
||||||
|
"xmrig": "https://api.github.com/repos/xmrig/xmrig/releases",
|
||||||
"reddit": "https://www.reddit.com/r/monero/top.json?limit=100",
|
"reddit": "https://www.reddit.com/r/monero/top.json?limit=100",
|
||||||
"ccs": "https://ccs.getmonero.org",
|
"ccs": "https://ccs.getmonero.org",
|
||||||
"fiat_rates": "https://api.exchangeratesapi.io/latest?base=USD",
|
"fiat_rates": "https://api.exchangeratesapi.io/latest?base=USD",
|
||||||
|
|
Loading…
Reference in a new issue