Skip to content

Commit

Permalink
Separate tweets for vaccination
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitor Magán committed May 23, 2021
1 parent f7b6918 commit 0b9a093
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 39 deletions.
40 changes: 13 additions & 27 deletions helpers/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,29 @@
from helpers.spain_geography import CCAA_POPULATION, CCAA_ADMITTED_BEDS, CCAA_ICU_BEDS


def get_spain_vaccination_report(accumulated_doses_data, today_doses_data,
accumulated_completed_vaccination_data, today_completed_vaccination_data,
accumulated_first_dose_data, today_first_dose_data):
def get_vaccination_report(ccaa, accumulated_doses_data, today_doses_data,
accumulated_completed_vaccination_data, today_completed_vaccination_data,
accumulated_first_dose_data, today_first_dose_data):

tweet = get_vaccination_sentence("Dosis", accumulated_doses_data[SPAIN],
today_doses_data[SPAIN]) + "\n"
tweet += get_completed_vaccination_sentence("Personas 1 dosis", accumulated_first_dose_data[SPAIN],
today_first_dose_data[SPAIN]) + "\n"
tweet += get_completed_vaccination_sentence("Pautas completas", accumulated_completed_vaccination_data[SPAIN],
today_completed_vaccination_data[SPAIN])
tweet = get_vaccination_sentence("Dosis", accumulated_doses_data[ccaa],
today_doses_data[ccaa]) + "\n"
tweet += get_completed_vaccination_sentence(ccaa, "Personas 1 dosis", accumulated_first_dose_data[ccaa],
today_first_dose_data[ccaa]) + "\n"
tweet += get_completed_vaccination_sentence(ccaa, "Pautas completas", accumulated_completed_vaccination_data[ccaa],
today_completed_vaccination_data[ccaa])

return tweet


def get_vaccination_report(accumulated_data, today_data, percentage):
sentences = []
sentence_generator = {
True: get_completed_vaccination_sentence,
False: get_vaccination_sentence
}[percentage]
def get_vaccination_sentence(stat, accumulated, today_total):
return "- {0}: {1} 🔺{2}".format(stat, _format_number(accumulated), _format_number(today_total))

for ccaa in filter(lambda x: x in CCAA_POPULATION.keys(), accumulated_data.keys()):
sentences.append(sentence_generator(ccaa, accumulated_data[ccaa], today_data[ccaa]))

return sentences


def get_vaccination_sentence(territorial_unit, accumulated, today_total):
return "- {0}: {1} 🔺{2}".format(territorial_unit, _format_number(accumulated),
_format_number(today_total))


def get_completed_vaccination_sentence(territorial_unit, accumulated, today_total):
def get_completed_vaccination_sentence(territorial_unit, stat, accumulated, today_total):
population = CCAA_POPULATION[territorial_unit] if territorial_unit in CCAA_POPULATION \
else sum(CCAA_POPULATION.values())
percentage_population = accumulated / population * 100
return "- {0}: {1} ({2}%) 🔺{3}".format(territorial_unit, _format_number(accumulated),
return "- {0}: {1} ({2}%) 🔺{3}".format(stat, _format_number(accumulated),
_format_number(percentage_population),
_format_number(today_total))

Expand Down
25 changes: 13 additions & 12 deletions main_vaccination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from helpers.db import Influx, Measurement
from helpers.ministry_report import VaccinesMinistryReport
from main_daily import update_stat
from helpers.reports import get_vaccination_report, get_spain_vaccination_report, get_graph_url
from helpers.reports import get_vaccination_report, get_graph_url
from helpers.spain_geography import CCAA_POPULATION
from constants import VACCINE_IMAGE_PATH, ARMY, SPAIN

Expand Down Expand Up @@ -80,22 +80,23 @@ def publish_report(today):
accumulated_first_doses = influx.get_stat_accumulated_until_day(Measurement.FIRST_DOSE_VACCINATIONS, today)

today_str = today.strftime("%d/%m/%Y")
spain_tweet = get_spain_vaccination_report(accumulated_vaccinations, today_vaccinations,
accumulated_completed_vaccinations, today_completed_vaccinations,
accumulated_first_doses, today_first_doses)
spain_tweet = get_vaccination_report(SPAIN, accumulated_vaccinations, today_vaccinations,
accumulated_completed_vaccinations, today_completed_vaccinations,
accumulated_first_doses, today_first_doses)
interactive_graph_sentence = "➡️ Gráfico Interactivo: https://home.aitormagan.es/d/TeEplNgRk/covid-vacunas-espana?orgId=1"
spain_tweet = f"🇪🇸 España - Estado vacunación a {today_str}:\n\n{spain_tweet}\n\n{interactive_graph_sentence}"
spain_tweet = f"🇪🇸 España - Vacunación a {today_str}:\n\n{spain_tweet}\n\n{interactive_graph_sentence}"
graph_url = get_graph_url(datetime(2021, 1, 1), today, graph_path=VACCINE_IMAGE_PATH)
last_tweet = twitter.publish_tweet_with_media(spain_tweet, graph_url)
ccaa_tweets = []

sentences_vaccination = get_vaccination_report(accumulated_vaccinations, today_vaccinations, False)
last_tweet = twitter.publish_sentences_in_tweets(sentences_vaccination, f"💉 Total Dosis a {today_str}",
last_tweet=last_tweet)
for ccaa in filter(lambda x: x in CCAA_POPULATION.keys(), accumulated_vaccinations.keys()):
ccaa_tweet = get_vaccination_report(ccaa, accumulated_vaccinations, today_vaccinations,
accumulated_completed_vaccinations,
today_completed_vaccinations,
accumulated_first_doses, today_first_doses)
ccaa_tweets.append(f"{ccaa} - Vacunación a {today_str}:\n\n{ccaa_tweet}")

sentences_completed_vaccination = get_vaccination_report(accumulated_completed_vaccinations,
today_completed_vaccinations, True)
twitter.publish_sentences_in_tweets(sentences_completed_vaccination, f"💉 Total Pautas Completas a {today_str}",
last_tweet=last_tweet)
twitter.publish_tweets(ccaa_tweets, last_tweet)


if __name__ == "__main__":
Expand Down

0 comments on commit 0b9a093

Please sign in to comment.