Added financial info

This commit is contained in:
nsde 2023-09-22 01:00:00 +02:00
parent 569d40161b
commit 02c41e71b7
9 changed files with 97 additions and 4 deletions

View file

@ -20,9 +20,11 @@ def create_app() -> flask.Flask:
import tos
import account
import finances
tos.register(app)
account.register(app)
finances.register(app)
# max 100 MB
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024

52
web/finances.py Executable file
View 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
)

View file

@ -124,10 +124,11 @@ h6 {
}
.box {
margin-bottom: 1rem;
background: rgba(204, 154, 247, 0.1411764706);
border: 2px solid rgba(204, 154, 247, 0.1411764706);
border-radius: 5px;
padding: 1rem 2rem;
padding: 0rem 1rem;
}
@media (max-width: 900px) {

File diff suppressed because one or more lines are too long

View file

@ -110,10 +110,11 @@ h6
-webkit-text-fill-color: transparent
.box
margin-bottom: 1rem
background: $primary-soft
border: 2px solid $primary-soft
border-radius: $edge
padding: 1rem 2rem
padding: 0rem 1rem
@media (max-width: 900px)
body

View file

@ -10,6 +10,7 @@ header h1 {
}
div.featured__facts {
padding: 1.5rem;
margin-block: 2rem;
display: flex;
vertical-align: middle;
@ -37,6 +38,7 @@ div.featured__facts h2 span {
}
div.user-quotes div.user-quote__field {
padding: 1.5rem;
cursor: pointer;
margin-block: 2rem;
background: rgba(204, 154, 247, 0.1411764706);

File diff suppressed because one or more lines are too long

View file

@ -10,6 +10,7 @@ header
line-height: 4rem
div.featured__facts
padding: 1.5rem
margin-block: 2rem
display: flex
vertical-align: middle
@ -40,6 +41,7 @@ div.user-quotes
// grid-gap: 2rem
div.user-quote__field
padding: 1.5rem
cursor: pointer
margin-block: 2rem
background: $primary-soft

View 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' %}