implement a maximum time delta for appointment notification
This commit is contained in:
parent
15bb2e32f8
commit
c085a3ee10
10
README.md
10
README.md
|
@ -35,6 +35,10 @@ locations:
|
||||||
- Ehrenfeld
|
- Ehrenfeld
|
||||||
- Kalk
|
- Kalk
|
||||||
|
|
||||||
|
# Max time between today and a new appointment to notify about the new
|
||||||
|
# appointment. Set to -1 to notify about all new appointments.
|
||||||
|
max_timedelta: 14
|
||||||
|
|
||||||
# Path to the CSV file to store the scraped appointments
|
# Path to the CSV file to store the scraped appointments
|
||||||
# csv_path: ~/Termine.csv
|
# csv_path: ~/Termine.csv
|
||||||
|
|
||||||
|
@ -118,7 +122,7 @@ service name if it contains spaces.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
usage: cgn-appointments [-h] [-s SERVICES [SERVICES ...]]
|
usage: cgn-appointments [-h] [-s SERVICES [SERVICES ...]]
|
||||||
[-l LOCATIONS [LOCATIONS ...]]
|
[-l LOCATIONS [LOCATIONS ...]] [-t MAX_TIMEDELTA]
|
||||||
[--config-file CONFIG_FILE] [--csv-file CSV_FILE]
|
[--config-file CONFIG_FILE] [--csv-file CSV_FILE]
|
||||||
[--log-file LOG_FILE]
|
[--log-file LOG_FILE]
|
||||||
[--log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}]
|
[--log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}]
|
||||||
|
@ -132,6 +136,9 @@ options:
|
||||||
Services to check
|
Services to check
|
||||||
-l LOCATIONS [LOCATIONS ...], --locations LOCATIONS [LOCATIONS ...]
|
-l LOCATIONS [LOCATIONS ...], --locations LOCATIONS [LOCATIONS ...]
|
||||||
Locations to check
|
Locations to check
|
||||||
|
-t MAX_TIMEDELTA, --max-timedelta MAX_TIMEDELTA
|
||||||
|
Maximum timedelta in days to notify about new
|
||||||
|
appointments
|
||||||
--config-file CONFIG_FILE
|
--config-file CONFIG_FILE
|
||||||
Path to the configuration file
|
Path to the configuration file
|
||||||
--csv-file CSV_FILE Path to the csv file, which stores the last fetched
|
--csv-file CSV_FILE Path to the csv file, which stores the last fetched
|
||||||
|
@ -147,6 +154,7 @@ options:
|
||||||
cgn-apppointments \
|
cgn-apppointments \
|
||||||
--services "Personalausweis - Antrag" "Reisepass - Antrag (seit 01.01.2024 auch für Kinder unter 12 Jahren)" \
|
--services "Personalausweis - Antrag" "Reisepass - Antrag (seit 01.01.2024 auch für Kinder unter 12 Jahren)" \
|
||||||
--locations Ehrenfeld Kalk \
|
--locations Ehrenfeld Kalk \
|
||||||
|
--max-timedelta 7 \
|
||||||
--config-file /path/to/config.yaml \
|
--config-file /path/to/config.yaml \
|
||||||
--csv-file /path/to/csvfile.csv \
|
--csv-file /path/to/csvfile.csv \
|
||||||
--log-file /path/to/logfile.log \
|
--log-file /path/to/logfile.log \
|
||||||
|
|
|
@ -50,6 +50,14 @@ def parse_arguments() -> dict:
|
||||||
help="Locations to check",
|
help="Locations to check",
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
argparser.add_argument(
|
||||||
|
"-t",
|
||||||
|
"--max-timedelta",
|
||||||
|
action="store",
|
||||||
|
type=int,
|
||||||
|
help="Maximum timedelta in days to notify about new appointments",
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--config-file",
|
"--config-file",
|
||||||
action="store",
|
action="store",
|
||||||
|
@ -92,6 +100,7 @@ def update_config_with_args(config: dict, args: dict) -> dict:
|
||||||
update_config = {
|
update_config = {
|
||||||
"services": args.get("services"),
|
"services": args.get("services"),
|
||||||
"locations": args.get("locations"),
|
"locations": args.get("locations"),
|
||||||
|
"max_timedelta": args.get("max_timedelta"),
|
||||||
"csv_path": args.get("csv_file"),
|
"csv_path": args.get("csv_file"),
|
||||||
}
|
}
|
||||||
for key, value in update_config.items():
|
for key, value in update_config.items():
|
||||||
|
@ -257,6 +266,7 @@ def main():
|
||||||
url = config.get("url")
|
url = config.get("url")
|
||||||
services = config.get("services")
|
services = config.get("services")
|
||||||
check_locations = config.get("locations")
|
check_locations = config.get("locations")
|
||||||
|
max_timedelta = config.get("max_timedelta")
|
||||||
csv_name = config.get("csv_name", "cgn-appointments.csv")
|
csv_name = config.get("csv_name", "cgn-appointments.csv")
|
||||||
csv_path = define_csv_path(config.get("csv_path"), csv_name)
|
csv_path = define_csv_path(config.get("csv_path"), csv_name)
|
||||||
date_regex = config.get("date_regex")
|
date_regex = config.get("date_regex")
|
||||||
|
@ -382,17 +392,31 @@ def main():
|
||||||
if new_date and new_date != previous_date:
|
if new_date and new_date != previous_date:
|
||||||
logger.info(f"New appointment found for {name}: {new_date}",
|
logger.info(f"New appointment found for {name}: {new_date}",
|
||||||
extra={"location": name, "previous_date": previous_date,
|
extra={"location": name, "previous_date": previous_date,
|
||||||
"new_date": new_date})
|
"new_date": new_date, "max_timedelta": max_timedelta})
|
||||||
lines.append((name, new_date.strftime(date_format)))
|
lines.append((name, new_date.strftime(date_format)))
|
||||||
ntfy(
|
|
||||||
ntfy_server,
|
# Send notification if new date is within timedelta or
|
||||||
ntfy_topic,
|
# timedelta is not set
|
||||||
ntfy_title,
|
time_delta = (new_date - datetime.now()).days if max_timedelta > 0 else False
|
||||||
ntfy_message % (name, new_date),
|
if time_delta == False or time_delta <= max_timedelta:
|
||||||
session_url,
|
logger.info(f"Sending notification for new appointment.",
|
||||||
ntfy_tags,
|
extra={"location": name, "new_date": new_date,
|
||||||
ntfy_priority,
|
"time_delta": time_delta,
|
||||||
)
|
"max_timedelta": max_timedelta})
|
||||||
|
ntfy(
|
||||||
|
ntfy_server,
|
||||||
|
ntfy_topic,
|
||||||
|
ntfy_title,
|
||||||
|
ntfy_message % (name, new_date),
|
||||||
|
session_url,
|
||||||
|
ntfy_tags,
|
||||||
|
ntfy_priority,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.info(f"New appointment is not within timedelta.",
|
||||||
|
extra={"location": name, "new_date": new_date,
|
||||||
|
"time_delta": time_delta,
|
||||||
|
"max_timedelta": max_timedelta})
|
||||||
elif previous_date is not None:
|
elif previous_date is not None:
|
||||||
lines.append((name, previous_date.strftime(date_format)))
|
lines.append((name, previous_date.strftime(date_format)))
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ locations:
|
||||||
- Ehrenfeld
|
- Ehrenfeld
|
||||||
- Kalk
|
- Kalk
|
||||||
|
|
||||||
|
# Max time between today and a new appointment to notify about the new
|
||||||
|
# appointment. Set to -1 to notify about all new appointments.
|
||||||
|
max_timedelta: 14
|
||||||
|
|
||||||
# Path to the CSV file to store the scraped appointments
|
# Path to the CSV file to store the scraped appointments
|
||||||
# csv_path: ~/Termine.csv
|
# csv_path: ~/Termine.csv
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue