1
1
mirror of https://github.com/derogab/ITAvsCOVIDbot synced 2024-12-28 00:11:00 +01:00

Merge pull request #2 from derogab/dev

Minor Improvements
This commit is contained in:
Gabriele De Rosa 2021-05-21 15:57:35 +02:00 committed by GitHub
commit bfc8ff46b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 43 deletions

View File

@ -23,4 +23,4 @@ Il bot è stato sviluppato da [@derogab](https://github.com/derogab) e il codice
I dati mostrati sono scaricati dagli [Open Data ufficiali](https://github.com/italia/covid19-opendata-vaccini) sui vaccini in Italia.
Fino alla [v1.0.0](https://github.com/derogab/ITAvsCOVIDbot/releases/tag/v1.0.0) i grafici sono automaticamente generati mediante il codice della [repository pubblica](https://github.com/MarcoBuster/quanto-manca) di [@MarcoBuster](https://github.com/MarcoBuster). Dalla [v2.0.0](https://github.com/derogab/ITAvsCOVIDbot/releases/tag/v2.0.0) sono invece utilizzati dei grafici differenti costruiti sulla base dei precedenti.
Fino alla [v1.0.0](https://github.com/derogab/ITAvsCOVIDbot/releases/tag/v1.0.0) i grafici sono automaticamente generati mediante il codice della [repository pubblica](https://github.com/MarcoBuster/quanto-manca) di [@MarcoBuster](https://github.com/MarcoBuster). La [v2.0.0](https://github.com/derogab/ITAvsCOVIDbot/releases/tag/v2.0.0) introduce invece un aggiornamento di questi grafici.

View File

@ -26,10 +26,13 @@
padding-top: 0px !important;
margin-bottom: 5px;
}
#content {
padding: 15px 35px;
}
</style>
</head>
<body>
<div class="container mt-2 pt-2 px-xl-5">
<div class="container mt-2 pt-2 px-xl-5" id="content">
<h1>Quando torneremo alla normalità?</h1>
<p>
La domanda non ha una risposta precisa.

52
bot.py
View File

@ -62,37 +62,7 @@ db = client['bot']
def progress(first, second, total = ITALIAN_POPULATION):
progress_length = 20
# first : total = x : 100
first_perc = (first * 100) / total
# second : total = x : 100
second_perc = (second * 100) / total
# first_perc : x = 100 : progress_length
first_cycle = int(first_perc / (100 / progress_length))
# second_perc : x = 100 : progress_length
second_cycle = int(second_perc / (100 / progress_length))
# first progress
first_progress = ''
for i in range(0, first_cycle):
first_progress = first_progress + ''
for i in range(0, progress_length - first_cycle):
first_progress = first_progress + ''
# second progress
second_progress = ''
for i in range(0, second_cycle):
second_progress = second_progress + ''
for i in range(0, progress_length - second_cycle):
second_progress = second_progress + ''
return first_progress, second_progress
# Function to generate images from templates
def generate(df, target, template):
# Get data from df
@ -161,6 +131,7 @@ def generate(df, target, template):
}
# Function to get data
def download():
@ -201,10 +172,7 @@ def download():
plot1 = generate(df_first, 'prima_dose', 'assets/templates/plot.html')
plot2 = generate(df_second, 'seconda_dose', 'assets/templates/plot.html')
# Generate progression
progression = [sum(df_first['prima_dose']), sum(df_second['seconda_dose'])]
return intro, plot1, plot2, progression
return intro, plot1, plot2
@ -225,7 +193,6 @@ def help(update, context):
# Info command
def info(update, context):
@ -239,6 +206,7 @@ def info(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=info_msg, parse_mode='Markdown', disable_web_page_preview=True)
# Start command
def start(update, context):
global db
@ -271,6 +239,7 @@ def start(update, context):
info(update, context)
# Stop command
def stop(update, context):
global db
@ -293,6 +262,8 @@ def stop(update, context):
# Send welcome message
context.bot.send_message(chat_id=update.effective_chat.id, text=stop_msg, parse_mode='Markdown')
# News command
def news(update, context):
global db
@ -333,21 +304,20 @@ def news(update, context):
# Send welcome message
context.bot.send_message(chat_id=update.effective_chat.id, text=set_msg, parse_mode='Markdown')
# Get data
def get(update, context):
# Download data
intro, plot1, plot2, progression = download()
intro, plot1, plot2 = download()
# Send photos
p1 = open(intro['results'], 'rb')
p2 = open(plot1['results'], 'rb')
p3 = open(plot2['results'], 'rb')
first, second = progress(progression[0], progression[1])
caption = 'Prima Dose\n' + first + '\nSeconda Dose\n' + second
p1 = InputMediaPhoto(media=p1, caption=caption)
p1 = InputMediaPhoto(media=p1)
p2 = InputMediaPhoto(media=p2)
p3 = InputMediaPhoto(media=p3)