Remove progress bars

This commit is contained in:
Gabriele De Rosa 2021-05-21 15:51:10 +02:00
parent 6ea9453626
commit e74e671ff6
2 changed files with 12 additions and 42 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. 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.

52
bot.py
View File

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