-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_generator.py
83 lines (68 loc) · 3.28 KB
/
message_generator.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
71
72
73
74
75
76
77
78
79
80
81
82
83
import locale
from datetime import datetime
from settings import DATA_FILE, INPUT_DATA
from data_updater import DataUpdater
total_population = 6.036e7 # 60.36 milion
# total_population = 54006504 # platea updated 21-06-2021
locale.setlocale(locale.LC_ALL, 'it_IT.UTF-8')
class MessageGenerator:
def __init__(self) -> None:
self.du = DataUpdater(INPUT_DATA, DATA_FILE)
self.message = "No data"
# return the actual message
def get_message(self) -> str:
if self.message == "No data":
self.generate()
return self.message
# generate the message
def generate(self) -> None:
# retrive data from local file
data = self.du.get_data()
# compute values
today_first_dose = int(data[0])
today_second_dose = int(data[1])
today_third_dose = int(data[2])
yesterday_first_dose = int(data[3])
yesterday_second_dose = int(data[4])
yesterday_third_dose = int(data[5])
increment_first_dose = today_first_dose - yesterday_first_dose
increment_second_dose = today_second_dose - yesterday_second_dose
increment_third_dose = today_third_dose - yesterday_third_dose
percent_first_dose = round(today_first_dose/total_population * 100, 2)
percent_second_dose = round(today_second_dose/total_population * 100, 2)
percent_third_dose = round(today_third_dose/total_population * 100, 2)
total_doses = today_first_dose + today_second_dose + today_third_dose
total_daily_doses = increment_first_dose + increment_second_dose + increment_third_dose
# generate the message
message = f'*Report Vaccini {self.parse_date()}*\n'
message += f'\n'
message += f'*Prima Dose*\n'
message += f'Totale vaccinati fino ad oggi: *{today_first_dose:n}*\n'
message += f'Incremento giornaliero: *{increment_first_dose:n}*\n'
message += f'È stato vaccinato il *{percent_first_dose:n}*% della popolazione\n'
message += f'\n'
message += f'*Seconda Dose*\n'
message += f'Totale vaccinati fino ad oggi: *{today_second_dose:n}*\n'
message += f'Incremento giornaliero: *{increment_second_dose:n}*\n'
message += f'È stato vaccinato il *{percent_second_dose:n}*% della popolazione\n'
message += f'\n'
message += f'*Terza Dose*\n'
message += f'Totale vaccinati fino ad oggi: *{today_third_dose:n}*\n'
message += f'Incremento giornaliero: *{increment_third_dose:n}*\n'
message += f'È stato vaccinato il *{percent_third_dose:n}*% della popolazione\n'
message += f'\n'
message += f'Totale dosi: *{total_doses:n}* \n'
message += f'Totale dosi giornaliere: *{total_daily_doses:n}*'
self.message = message
# update the message
def update(self) -> None:
if self.du.update_data():
self.generate()
# parse the date in italian format
def parse_date(self) -> str:
months = ['', 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre']
today = datetime.today()
year = today.year
month = today.month
day = today.day
return f'{day} {months[month]} {year}'