mirror of
https://github.com/NovaOSS/nova-web.git
synced 2024-11-25 19:03:57 +01:00
Added financial info
This commit is contained in:
parent
569d40161b
commit
02c41e71b7
|
@ -20,9 +20,11 @@ def create_app() -> flask.Flask:
|
||||||
|
|
||||||
import tos
|
import tos
|
||||||
import account
|
import account
|
||||||
|
import finances
|
||||||
|
|
||||||
tos.register(app)
|
tos.register(app)
|
||||||
account.register(app)
|
account.register(app)
|
||||||
|
finances.register(app)
|
||||||
|
|
||||||
# max 100 MB
|
# max 100 MB
|
||||||
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024
|
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024
|
||||||
|
|
52
web/finances.py
Executable file
52
web/finances.py
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import flask
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
def get_finances():
|
||||||
|
return requests.get(
|
||||||
|
url=f'{os.environ["CORE_API_URL"]}/finances',
|
||||||
|
headers={
|
||||||
|
'Authorization': f'{os.environ["CORE_API_KEY"]}'
|
||||||
|
},
|
||||||
|
timeout=5
|
||||||
|
).json()
|
||||||
|
|
||||||
|
|
||||||
|
def register(app):
|
||||||
|
@app.route('/finances')
|
||||||
|
def finances_view():
|
||||||
|
data = get_finances()
|
||||||
|
finances = {
|
||||||
|
'donations_total': round(sum([i['amount_usd'] for i in data['donations']])),
|
||||||
|
'donations_num': len(data['donations']),
|
||||||
|
'donations_avg': round(sum([i['amount_usd'] for i in data['donations']]) / len(data['donations']), 2),
|
||||||
|
'donations_max': round(max([i['amount_usd'] for i in data['donations']])),
|
||||||
|
'most_used_donation_currency': max(data['donations'], key=lambda x: x['amount_usd'])['currency'],
|
||||||
|
|
||||||
|
'expenses_total': round(sum([i['amount_usd'] for i in data['expenses']])),
|
||||||
|
'expenses_wages': round(sum([i['amount_usd'] for i in data['expenses'] if i['type'] == 'wage'])),
|
||||||
|
'most_used_expense_currency': max(data['expenses'], key=lambda x: x['amount_usd'])['currency'],
|
||||||
|
}
|
||||||
|
|
||||||
|
return flask.render_template('finances.html', finances=finances)
|
||||||
|
|
||||||
|
@app.route('/finances/json')
|
||||||
|
def finances_download():
|
||||||
|
virtual_file = io.StringIO()
|
||||||
|
json.dump(get_finances(), virtual_file, indent=4)
|
||||||
|
name = f'finances-{time.strftime("%Y-%m-%d")}.json'
|
||||||
|
virtual_file.seek(0)
|
||||||
|
|
||||||
|
return flask.send_file(
|
||||||
|
io.BytesIO(virtual_file.read().encode('utf-8')),
|
||||||
|
mimetype='application/json',
|
||||||
|
as_attachment=True,
|
||||||
|
download_name=name
|
||||||
|
)
|
|
@ -124,10 +124,11 @@ h6 {
|
||||||
}
|
}
|
||||||
|
|
||||||
.box {
|
.box {
|
||||||
|
margin-bottom: 1rem;
|
||||||
background: rgba(204, 154, 247, 0.1411764706);
|
background: rgba(204, 154, 247, 0.1411764706);
|
||||||
border: 2px solid rgba(204, 154, 247, 0.1411764706);
|
border: 2px solid rgba(204, 154, 247, 0.1411764706);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
padding: 1rem 2rem;
|
padding: 0rem 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -110,10 +110,11 @@ h6
|
||||||
-webkit-text-fill-color: transparent
|
-webkit-text-fill-color: transparent
|
||||||
|
|
||||||
.box
|
.box
|
||||||
|
margin-bottom: 1rem
|
||||||
background: $primary-soft
|
background: $primary-soft
|
||||||
border: 2px solid $primary-soft
|
border: 2px solid $primary-soft
|
||||||
border-radius: $edge
|
border-radius: $edge
|
||||||
padding: 1rem 2rem
|
padding: 0rem 1rem
|
||||||
|
|
||||||
@media (max-width: 900px)
|
@media (max-width: 900px)
|
||||||
body
|
body
|
||||||
|
|
|
@ -10,6 +10,7 @@ header h1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
div.featured__facts {
|
div.featured__facts {
|
||||||
|
padding: 1.5rem;
|
||||||
margin-block: 2rem;
|
margin-block: 2rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
@ -37,6 +38,7 @@ div.featured__facts h2 span {
|
||||||
}
|
}
|
||||||
|
|
||||||
div.user-quotes div.user-quote__field {
|
div.user-quotes div.user-quote__field {
|
||||||
|
padding: 1.5rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-block: 2rem;
|
margin-block: 2rem;
|
||||||
background: rgba(204, 154, 247, 0.1411764706);
|
background: rgba(204, 154, 247, 0.1411764706);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -10,6 +10,7 @@ header
|
||||||
line-height: 4rem
|
line-height: 4rem
|
||||||
|
|
||||||
div.featured__facts
|
div.featured__facts
|
||||||
|
padding: 1.5rem
|
||||||
margin-block: 2rem
|
margin-block: 2rem
|
||||||
display: flex
|
display: flex
|
||||||
vertical-align: middle
|
vertical-align: middle
|
||||||
|
@ -40,6 +41,7 @@ div.user-quotes
|
||||||
// grid-gap: 2rem
|
// grid-gap: 2rem
|
||||||
|
|
||||||
div.user-quote__field
|
div.user-quote__field
|
||||||
|
padding: 1.5rem
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
margin-block: 2rem
|
margin-block: 2rem
|
||||||
background: $primary-soft
|
background: $primary-soft
|
||||||
|
|
33
web/templates/finances.html
Normal file
33
web/templates/finances.html
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{% include 'common/begin.html' %}
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<h1>Our finances - transparency is key!</h1>
|
||||||
|
<p>
|
||||||
|
<b>Warning</b> - no guarantees can be made that this information is 100% accurate. Crypto currency prices are updated once every hour.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a href="/finances/json" target="_blank">
|
||||||
|
<button class="special">
|
||||||
|
<i class="bi bi-file-earmark-arrow-down"></i>
|
||||||
|
Download entire database
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<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>From donations, we received a total of <b>{{ finances.donations_total }} USD</b>.</p></div>
|
||||||
|
<div class="featured__facts box"><p>The average donations has an amount of <b>{{ finances.donations_avg }} USD</b>.
|
||||||
|
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>
|
||||||
|
|
||||||
|
<!-- <img src="{{ finances.donations_chart_url }} alt="Donations chart"> -->
|
||||||
|
|
||||||
|
<h2>Expenses</h2>
|
||||||
|
<div class="featured__facts box"><p>We have spent <b>{{ finances.expenses_total }} USD</b> so far.</p></div>
|
||||||
|
<div class="featured__facts box"><p>We paid our developers <b>{{ finances.expenses_wages }} USD</b> so far.</p></div>
|
||||||
|
<div class="featured__facts box"><p>We usually pay in <b>{{ finances.most_used_expense_currency }}</b>.</p></div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
{% include 'common/end.html' %}
|
Loading…
Reference in a new issue