mirror of
https://github.com/NovaOSS/nova-web.git
synced 2024-11-25 16:13:58 +01:00
Added last update
This commit is contained in:
parent
cb3175d149
commit
25cbdb233e
|
@ -9,6 +9,8 @@ from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
# cache get_finances() for 5 minutes
|
||||||
|
|
||||||
def get_finances():
|
def get_finances():
|
||||||
return requests.get(
|
return requests.get(
|
||||||
url=f'{os.environ["CORE_API_URL"]}/finances',
|
url=f'{os.environ["CORE_API_URL"]}/finances',
|
||||||
|
@ -18,7 +20,6 @@ def get_finances():
|
||||||
timeout=5
|
timeout=5
|
||||||
).json()
|
).json()
|
||||||
|
|
||||||
|
|
||||||
def register(app):
|
def register(app):
|
||||||
@app.route('/finances')
|
@app.route('/finances')
|
||||||
def finances_view():
|
def finances_view():
|
||||||
|
@ -28,6 +29,7 @@ def register(app):
|
||||||
return flask.Response('Error fetching finances from database. This might be cause the data is still being processed. Sorry.', status=500)
|
return flask.Response('Error fetching finances from database. This might be cause the data is still being processed. Sorry.', status=500)
|
||||||
|
|
||||||
finances = {
|
finances = {
|
||||||
|
'last_update': data['timestamp'],
|
||||||
'donations_total': round(sum([i['amount_usd'] for i in data['donations']])),
|
'donations_total': round(sum([i['amount_usd'] for i in data['donations']])),
|
||||||
'donations_num': len(data['donations']),
|
'donations_num': len(data['donations']),
|
||||||
'donations_avg': round(sum([i['amount_usd'] for i in data['donations']]) / len(data['donations']), 2),
|
'donations_avg': round(sum([i['amount_usd'] for i in data['donations']]) / len(data['donations']), 2),
|
||||||
|
@ -43,8 +45,13 @@ def register(app):
|
||||||
|
|
||||||
@app.route('/finances/json')
|
@app.route('/finances/json')
|
||||||
def finances_download():
|
def finances_download():
|
||||||
|
try:
|
||||||
|
data = get_finances()
|
||||||
|
except Exception:
|
||||||
|
return flask.Response('Error fetching finances from database. This might be cause the data is still being processed. Sorry.', status=500)
|
||||||
|
|
||||||
virtual_file = io.StringIO()
|
virtual_file = io.StringIO()
|
||||||
json.dump(get_finances(), virtual_file, indent=4)
|
json.dump(data, virtual_file, indent=4)
|
||||||
name = f'finances-{time.strftime("%Y-%m-%d")}.json'
|
name = f'finances-{time.strftime("%Y-%m-%d")}.json'
|
||||||
virtual_file.seek(0)
|
virtual_file.seek(0)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,14 @@
|
||||||
<main>
|
<main>
|
||||||
<h1>Our finances - transparency is key!</h1>
|
<h1>Our finances - transparency is key!</h1>
|
||||||
<p>
|
<p>
|
||||||
<b>Warning</b> - no guarantees can be made that this information is 100% accurate. Crypto currency prices are updated once every hour.
|
<b>Warning</b> - no guarantees can be made that this information is 100% accurate.
|
||||||
|
Crypto currency prices are updated once every hour.
|
||||||
|
<br>
|
||||||
|
<b>As of: </b> <span id="as-of">Loading...</span>
|
||||||
|
<script>
|
||||||
|
const unix_timestamp = {{ finances.last_update }};
|
||||||
|
document.getElementById("as-of").innerHTML = new Date(unix_timestamp * 1000).toLocaleString();
|
||||||
|
</script>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<a href="/finances/json" target="_blank">
|
<a href="/finances/json" target="_blank">
|
||||||
|
@ -15,8 +22,8 @@
|
||||||
|
|
||||||
<h2>Donations</h2>
|
<h2>Donations</h2>
|
||||||
|
|
||||||
<div class="featured__facts box"><p>We have received <b>{{ finances.donations_num }} donations</b> so far.</p></div>
|
<div class="featured__facts box"><p>We have received <b>{{ finances.donations_num }} donations</b> so far, totaling <b>{{ finances.donations_total }} USD</p></div>
|
||||||
<div class="featured__facts box"><p>From donations, we received a total of <b>{{ finances.donations_total }} USD</b>.</p></div>
|
<div class="featured__facts box"><p>From donations, we received a total of</b>.</p></div>
|
||||||
<div class="featured__facts box"><p>The average donation has an amount of <b>{{ finances.donations_avg }} USD</b>.
|
<div class="featured__facts box"><p>The average donation has an amount of <b>{{ finances.donations_avg }} USD</b>.
|
||||||
The largest donation is <b>{{ finances.donations_max }} USD</b>.</div>
|
The largest donation is <b>{{ finances.donations_max }} USD</b>.</div>
|
||||||
<div class="featured__facts box"><p>Most people donated in <b>{{ finances.most_used_donation_currency }}</b>.</p></div>
|
<div class="featured__facts box"><p>Most people donated in <b>{{ finances.most_used_donation_currency }}</b>.</p></div>
|
||||||
|
|
Loading…
Reference in a new issue