def publish_report(today):
    today_vaccinations = influx.get_stat_group_by_day(Measurement.VACCINATIONS, today)
    today_completed_vaccinations = influx.get_stat_group_by_day(Measurement.COMPLETED_VACCINATIONS, today)
    accumulated_vaccinations = influx.get_stat_accumulated_until_day(Measurement.VACCINATIONS, today)
    accumulated_completed_vaccinations = influx.get_stat_accumulated_until_day(Measurement.COMPLETED_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)
    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}"
    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)

    army_string = "Fuerzas Armadas"
    today_vaccinations.pop(army_string)
    today_completed_vaccinations.pop(army_string)
    accumulated_vaccinations.pop(army_string)
    accumulated_completed_vaccinations.pop(army_string)

    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)

    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)
Example #2
0
 def test_given_start_and_end_when_get_graph_url_then_from_and_to_included_url_returned(
         self):
     date1 = datetime(2020, 8, 6)
     date2 = datetime(2020, 8, 12)
     self.assertEqual(
         DEFAULT_GRAPH_IMAGE_URL + "&from=" +
         str(int(date1.strftime("%s")) * 1000) + "&to=" +
         str(int(date2.strftime("%s")) * 1000), get_graph_url(date1, date2))
Example #3
0
 def test_given_start_end_and_var_when_get_graph_url_then_from_to_and_var_included_url_returned(
         self):
     date1 = datetime(2020, 8, 6)
     date2 = datetime(2020, 8, 12)
     var_name = "group_by"
     var_value = "1w,4d"
     self.assertEqual(
         DEFAULT_GRAPH_IMAGE_URL + "&from=" +
         str(int(date1.strftime("%s")) * 1000) + "&to=" +
         str(int(date2.strftime("%s")) * 1000) +
         f"&var-{var_name}={var_value}",
         get_graph_url(date1, date2, {var_name: var_value}))
Example #4
0
def publish_report(today, yesterday):

    today_data = influx.get_all_stats_group_by_day(today)
    yesterday_data = influx.get_all_stats_group_by_day(yesterday)
    accumulated_today = influx.get_all_stats_accumulated_until_day(today)
    date_header = get_date_header(today, yesterday)

    spain_report = get_global_report(date_header, today_data, yesterday_data,
                                     accumulated_today)
    graph_url = get_graph_url(today - timedelta(31), today)
    last_id = twitter.publish_tweet_with_media(spain_report, graph_url)

    tweets = get_report_by_ccaa(date_header, today_data, yesterday_data,
                                accumulated_today)
    last_id = twitter.publish_tweets(tweets, last_id)
    twitter.publish_tweet(get_final_tweet(), last_id)

    logging.info("Tweets published correctly!")
Example #5
0
def main():
    date = datetime.now()

    today_data = delete_pcrs24h(influx.get_all_stats_group_by_week(date))
    last_week_data = delete_pcrs24h(
        influx.get_all_stats_group_by_week(date - timedelta(7)))
    accumulated_today = delete_pcrs24h(
        influx.get_all_stats_accumulated_until_day(date))
    date_header = get_date_header(date)

    spain_report = get_global_report(date_header, today_data, last_week_data,
                                     accumulated_today)
    graph_url = get_graph_url(additional_vars={"group_by": "1w,4d"})
    last_id = twitter.publish_tweet_with_media(spain_report, graph_url)

    tweets = get_report_by_ccaa(date_header, today_data, last_week_data,
                                accumulated_today)
    last_id = twitter.publish_tweets(tweets, last_id)
    twitter.publish_tweet(get_final_tweet(), last_id)
def publish_report(today):
    today_vaccinations = influx.get_stat_group_by_day(Measurement.VACCINATIONS,
                                                      today)
    today_completed_vaccinations = influx.get_stat_group_by_day(
        Measurement.COMPLETED_VACCINATIONS, today)
    today_first_doses = influx.get_stat_group_by_day(
        Measurement.FIRST_DOSE_VACCINATIONS, today)
    accumulated_vaccinations = influx.get_stat_accumulated_until_day(
        Measurement.VACCINATIONS, today)
    accumulated_completed_vaccinations = influx.get_stat_accumulated_until_day(
        Measurement.COMPLETED_VACCINATIONS, 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_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 - 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 = []

    for ccaa in filter(lambda x: x in CCAA_POPULATION.keys(),
                       sorted(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}")

    twitter.publish_tweets(ccaa_tweets, last_tweet)
Example #7
0
 def test_given_end_when_get_graph_url_then_to_included_url_returned(self):
     date = datetime(2020, 8, 6)
     self.assertEqual(
         DEFAULT_GRAPH_IMAGE_URL + "&to=" +
         str(int(date.strftime("%s")) * 1000), get_graph_url(end=date))
Example #8
0
 def test_given_custom_grafana_server_without_final_slash_when_get_graph_url_then_separator_slash_included(
         self):
     self.assertEqual("http://grafana-server.com/" + GRAPH_IMAGE_PATH,
                      get_graph_url())
Example #9
0
 def test_given_custom_grafana_server_when_get_graph_url_then_custom_server_used_returned(
         self):
     self.assertEqual("http://grafana-server.com/" + GRAPH_IMAGE_PATH,
                      get_graph_url())
Example #10
0
 def test_given_no_dates_when_get_graph_url_then_base_url_returned(self):
     self.assertEqual(DEFAULT_GRAPH_IMAGE_URL, get_graph_url())