Compare commits

...

4 Commits
1.0.2 ... main

Author SHA1 Message Date
Marc Koch a762812922 🚀 release version 1.1.0 2024-09-17 22:49:27 +02:00
Marc Koch c085a3ee10 implement a maximum time delta for appointment notification 2024-09-17 22:49:27 +02:00
Marc Koch 15bb2e32f8 🚀 release version 1.0.3 2024-09-17 22:25:51 +02:00
Marc Koch 4ddc28e774 fix regex
The regex in config.yaml doesn't need to be escaped twice.
2024-09-17 22:25:45 +02:00
5 changed files with 50 additions and 13 deletions

View File

@ -4,6 +4,7 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.venv" /> <excludeFolder url="file://$MODULE_DIR$/.venv" />
<excludeFolder url="file://$MODULE_DIR$/dist" />
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.12 (.venv)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.12 (.venv)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

View File

@ -34,6 +34,10 @@ services:
locations: 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 \

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-present Marc Koch <marc-koch@posteo.de> # SPDX-FileCopyrightText: 2024-present Marc Koch <marc-koch@posteo.de>
# #
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
__version__ = "1.0.2" __version__ = "1.1.0"

View File

@ -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)))

View File

@ -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
@ -18,7 +22,7 @@ locations:
csv_name: 'appointments.csv' csv_name: 'appointments.csv'
# Regex to extract the date from the website # Regex to extract the date from the website
date_regex: '(\\d{2}\\.\\d{2}\\.\\d{4}\\s\\d{2}:\\d{2})' date_regex: '(\d{2}\.\d{2}\.\d{4}\s\d{2}:\d{2})'
# Date format to store the date in the CSV file (should match the date_regex) # Date format to store the date in the CSV file (should match the date_regex)
date_format: '%d.%m.%Y %H:%M' date_format: '%d.%m.%Y %H:%M'