implement a maximum time delta for appointment notification
This commit is contained in:
parent
4468ecf271
commit
4cf6f48a6f
|
@ -50,6 +50,14 @@ def parse_arguments() -> dict:
|
|||
help="Locations to check",
|
||||
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(
|
||||
"--config-file",
|
||||
action="store",
|
||||
|
@ -92,6 +100,7 @@ def update_config_with_args(config: dict, args: dict) -> dict:
|
|||
update_config = {
|
||||
"services": args.get("services"),
|
||||
"locations": args.get("locations"),
|
||||
"max_timedelta": args.get("max_timedelta"),
|
||||
"csv_path": args.get("csv_file"),
|
||||
}
|
||||
for key, value in update_config.items():
|
||||
|
@ -257,6 +266,7 @@ def main():
|
|||
url = config.get("url")
|
||||
services = config.get("services")
|
||||
check_locations = config.get("locations")
|
||||
max_timedelta = config.get("max_timedelta")
|
||||
csv_name = config.get("csv_name", "cgn-appointments.csv")
|
||||
csv_path = define_csv_path(config.get("csv_path"), csv_name)
|
||||
date_regex = config.get("date_regex")
|
||||
|
@ -382,17 +392,31 @@ def main():
|
|||
if new_date and new_date != previous_date:
|
||||
logger.info(f"New appointment found for {name}: {new_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)))
|
||||
ntfy(
|
||||
ntfy_server,
|
||||
ntfy_topic,
|
||||
ntfy_title,
|
||||
ntfy_message % (name, new_date),
|
||||
session_url,
|
||||
ntfy_tags,
|
||||
ntfy_priority,
|
||||
)
|
||||
|
||||
# Send notification if new date is within timedelta or
|
||||
# timedelta is not set
|
||||
time_delta = (new_date - datetime.now()).days if max_timedelta > 0 else False
|
||||
if time_delta == False or time_delta <= max_timedelta:
|
||||
logger.info(f"Sending notification for new appointment.",
|
||||
extra={"location": name, "new_date": new_date,
|
||||
"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:
|
||||
lines.append((name, previous_date.strftime(date_format)))
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ locations:
|
|||
- Ehrenfeld
|
||||
- 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
|
||||
# csv_path: ~/Termine.csv
|
||||
|
||||
|
|
Loading…
Reference in a new issue