From f15c4cdcd9a7db994da9e921ab8747740260c7bf Mon Sep 17 00:00:00 2001 From: Blallo Date: Thu, 25 Aug 2022 22:38:40 +0200 Subject: [PATCH] Retrieve yesterday's data --- latecomers/notifier.py | 6 +++--- latecomers/retrieve.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/latecomers/notifier.py b/latecomers/notifier.py index 5df1c2a..46aaaf9 100644 --- a/latecomers/notifier.py +++ b/latecomers/notifier.py @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- from contextlib import contextmanager -from datetime import datetime +from datetime import datetime, timedelta from email import encoders from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart @@ -58,7 +58,7 @@ class Notifier(object): @retry_and_log(logger, RETRIES) def send_result(self, to: T.List[T.Text], result: bytes) -> None: - date = datetime.now().strftime("%Y-%m-%d") + date = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d") body = f"Resoconto dei voli dal sito di AdR per l'aereoporto di Ciampino in data {date}" # noqa: E501 message = MIMEMultipart() @@ -84,7 +84,7 @@ class Notifier(object): @retry_and_log(logger, RETRIES) def send_no_data(self, to: T.List[T.Text]) -> None: - date = datetime.now().strftime("%Y-%m-%d") + date = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d") body = f"""Attenzione Nessun dato รจ stato trovato per i voli in data {date} dal sito di AdR per diff --git a/latecomers/retrieve.py b/latecomers/retrieve.py index e0babcd..dd5349a 100644 --- a/latecomers/retrieve.py +++ b/latecomers/retrieve.py @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +from datetime import datetime, timedelta import logging import typing as T @@ -8,13 +9,22 @@ import requests HOW_MANY = 200 -URL = f"https://www.adr.it/pax-cia-voli-in-tempo-reale?p_p_id=3_WAR_realtimeflightsportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_3_WAR_realtimeflightsportlet_tab=arrival&_3_WAR_realtimeflightsportlet_delta={HOW_MANY}&_3_WAR_realtimeflightsportlet_airport=&_3_WAR_realtimeflightsportlet_carrier=&_3_WAR_realtimeflightsportlet_codNat=&_3_WAR_realtimeflightsportlet_codScaOpe=&_3_WAR_realtimeflightsportlet_codVet=&_3_WAR_realtimeflightsportlet_date=&_3_WAR_realtimeflightsportlet_dataNumVol=&_3_WAR_realtimeflightsportlet_numVol=&_3_WAR_realtimeflightsportlet_rouIata=&_3_WAR_realtimeflightsportlet_orario=&_3_WAR_realtimeflightsportlet_searchType=completeSmall&_3_WAR_realtimeflightsportlet_orderByCol=comparationTime&_3_WAR_realtimeflightsportlet_orderByType=asc&_3_WAR_realtimeflightsportlet_resetCur=false&_3_WAR_realtimeflightsportlet_cur=1" # noqa: E501 + logger = logging.getLogger(__name__) +def remote() -> T.Text: + """ + Returns the url to use to retrieve yesterday's data. + """ + yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d") + url = f"https://www.adr.it/pax-cia-voli-in-tempo-reale?p_p_id=3_WAR_realtimeflightsportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_3_WAR_realtimeflightsportlet_tab=departure&_3_WAR_realtimeflightsportlet_codScaOpe=CIA&_3_WAR_realtimeflightsportlet_rouIata=&_3_WAR_realtimeflightsportlet_searchType=standard&_3_WAR_realtimeflightsportlet_airport=&_3_WAR_realtimeflightsportlet_date={yesterday}&_3_WAR_realtimeflightsportlet_orario=00:00-24:00&_3_WAR_realtimeflightsportlet_codVet=&_3_WAR_realtimeflightsportlet_carrier=&_3_WAR_realtimeflightsportlet_rtFlightsSearchContainerPrimaryKeys=&_3_WAR_realtimeflightsportlet_delta={HOW_MANY}" # noqa: E501 + return url + + @logit(logger) def retrieve() -> T.Text: """This function retrieves the body from the website page""" - r = requests.get(URL) + r = requests.get(remote()) return r.text