From a0770015038dd59000a3b731f91e2515dc20a6e0 Mon Sep 17 00:00:00 2001 From: Gabriele De Rosa Date: Thu, 7 Jan 2021 23:57:48 +0100 Subject: [PATCH] Improvements --- bot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 47781ec..10e0fdd 100644 --- a/bot.py +++ b/bot.py @@ -10,7 +10,7 @@ from telegram.ext import CommandHandler from pymongo import MongoClient import io -from datetime import timedelta as td +from datetime import datetime as dt, timedelta as td import matplotlib.dates as mdates import matplotlib.pyplot as plt @@ -76,11 +76,13 @@ def download(): ) df = df.loc[df["area"] == "ITA"] df["totale"] = pd.to_numeric(df["totale"]) - # df = df[:-1] # Ignore the last day because it's often incomplete + if dt.now() - df.index[-1] < td(days=1): + df = df[:-1] # Ignore the current day because it's often incomplete + totalVaccines = sum(df["totale"]) lastWeekData = df.loc[df.index > df.index[-1] - td(days=7)] vaccinesPerDayAverage = sum(lastWeekData["totale"]) / 7 - remainingDays = HIT / vaccinesPerDayAverage + remainingDays = (HIT - totalVaccines) / vaccinesPerDayAverage hitDate = df.index[-1] + td(days=remainingDays) # Generate plot @@ -108,7 +110,7 @@ def download(): with open('out/' + webpage_filename, 'w+') as wf: for line in f.read().splitlines(): if "" in line: - line = f"{sum(df['totale'])}" + line = f"{totalVaccines}" elif "" in line: line = f"{int(vaccinesPerDayAverage*7)}" elif "" in line: