Compare commits

...

2 Commits

Author SHA1 Message Date
Gabriele De Rosa 91aab39b5f Minor 2021-01-30 14:57:31 +01:00
Gabriele De Rosa 6863ba9dc2 Fix
Fix after open dataset changes
2021-01-30 14:53:38 +01:00
1 changed files with 14 additions and 2 deletions

16
bot.py
View File

@ -65,17 +65,29 @@ db = client['bot']
# Function to get data
def download():
# Download from open data
r = requests.get(DATA_URL)
# Create dataframe from data
df = pd.read_csv(
io.StringIO(r.text),
index_col="data_somministrazione",
)
# Set date as index
df.index = pd.to_datetime(
df.index,
format="%Y-%m-%d",
)
df = df.loc[df["area"] == "ITA"]
# Sort value based on date
df.sort_values('data_somministrazione')
# Delete sum data if already exists
df = df[df["area"] != "ITA"]
# Set target counter to numeric
df["totale"] = pd.to_numeric(df["totale"])
# Group by day and sum counters
df = df.groupby(['data_somministrazione'])['totale'].sum().reset_index()
# Re-set date as ID in new dataframe
df = df.set_index('data_somministrazione')
# If there are current day data...
if dt.now() - df.index[-1] < td(days=1):
df = df[:-1] # Ignore the current day because it's often incomplete
@ -148,7 +160,7 @@ def help(update, context):
help_msg = "_Lista dei comandi_ \n\n"
help_msg += "/start - Avvia il bot \n"
help_msg += "/get - Ricevi i dati aggiornati \n"
help_msg += "/news `ON`/`OFF` - Attiva o Disattiva le notifiche giornaliere \n"
help_msg += "/news ON/OFF - Attiva o Disattiva le notifiche giornaliere \n"
help_msg += "/help - Messaggio di aiuto \n"
help_msg += "/info - Informazioni su questo bot \n"
help_msg += "/stop - Disattiva il bot \n"