Compare commits
2 commits
e0ad20e48d
...
be6aa6383b
Author | SHA1 | Date | |
---|---|---|---|
Marc | be6aa6383b | ||
Marc | 25cb4b6a01 |
|
@ -1,4 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2024-present Marc Koch <marc-koch@posteo.de>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "1.0.3"
|
||||
__version__ = "1.1.0"
|
|
@ -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,8 +392,17 @@ 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)))
|
||||
|
||||
# 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,
|
||||
|
@ -393,6 +412,11 @@ def main():
|
|||
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