-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
70 lines (57 loc) · 2.22 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import requests
import datetime
import pandas as pd
import streamlit as st
import matplotlib.pyplot as plt
from datetime import date, timedelta
txt = 'Token ' + str(st.secrets.DB_TOKEN)
dt_obj = date.today() - timedelta(days=1)
dt = str(dt_obj)
tup = (str(dt_obj.day), str(dt_obj.month), str(dt_obj.year))
dt_trans = '-'.join(tup)
try:
url = f'https://data.gov.gr/api/v1/query/admie_dailyenergybalanceanalysis?date_from={dt}&date_to={dt}'
headers = {'Authorization': txt}
response = requests.get(url, headers=headers)
df = pd.DataFrame.from_dict(response.json(),
orient='columns',
dtype=None,
columns=None)
df.drop(df[df.fuel == 'ΣΥΝΟΛΟ'].index, inplace = True)
explode = [0, 0, 0, 0, 0]
explode[df.percentage.argmax()] = 0.1
explode = tuple(explode)
fig, ax = plt.subplots(figsize=(12, 12))
fig.subplots_adjust(0.3,0,1,1)
plt.title('Ενεργειακό Ισοζύγιο στις ' + dt_trans, bbox={'facecolor':'0.8', 'pad':5})
plt.pie(df.percentage,
labels=df.fuel,
explode=explode,
autopct='%1.1f%%',
shadow=True);
st.pyplot(fig)
except:
dt_obj = date.today() - timedelta(days=2)
dt = str(dt_obj)
tup = (str(dt_obj.day), str(dt_obj.month), str(dt_obj.year))
dt_trans = '-'.join(tup)
url = f'https://data.gov.gr/api/v1/query/admie_dailyenergybalanceanalysis?date_from={dt}&date_to={dt}'
headers = {'Authorization': txt}
response = requests.get(url, headers=headers)
df = pd.DataFrame.from_dict(response.json(),
orient='columns',
dtype=None,
columns=None)
df.drop(df[df.fuel == 'ΣΥΝΟΛΟ'].index, inplace = True)
explode = [0, 0, 0, 0, 0]
explode[df.percentage.argmax()] = 0.1
explode = tuple(explode)
fig, ax = plt.subplots(figsize=(12, 12))
fig.subplots_adjust(0.3,0,1,1)
plt.title('Ενεργειακό Ισοζύγιο στις ' + dt_trans, bbox={'facecolor':'0.8', 'pad':5})
plt.pie(df.percentage,
labels=df.fuel,
explode=explode,
autopct='%1.1f%%',
shadow=True);
st.pyplot(fig)