Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
feat: add appointment date to message (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibalzer committed Jun 13, 2021
1 parent b6f61e1 commit 022cc03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/impfbot.py
@@ -1,5 +1,6 @@
"""Notification bot for the lower saxony vaccination portal"""
import argparse
from datetime import datetime, timezone, timedelta
import sys

from alerts import alert
Expand All @@ -13,7 +14,7 @@
def check_for_slot() -> None:
"""checks if a slot is available"""
try:
if hasattr(settings,"COMMON_BIRTHDATE"):
if hasattr(settings, "COMMON_BIRTHDATE"):
birthdate_timestamp = datetime2timestamp(settings.COMMON_BIRTHDATE)
result = fetch_api(
zip_code=settings.COMMON_ZIP_CODE,
Expand All @@ -36,13 +37,19 @@ def check_for_slot() -> None:
log.error("Result is emtpy. (Invalid ZIP Code (PLZ)?)")
for elem in result:
if not elem['outOfStock']:
local_timezone = timezone(timedelta(hours=2))

free_slots = elem['freeSlotSizeOnline']
vaccine_name = elem['vaccineName']
vaccine_type = elem['vaccineType']
first_appoinment_date = datetime.fromtimestamp(
elem['firstAppoinmentDateSorterOnline'] /
1000, local_timezone
).strftime("%d.%m.%Y")

log.info(
f"Free slot! ({free_slots}) {vaccine_name}/{vaccine_type}")
msg = f"Freier Impfslot ({free_slots})! {vaccine_name}/{vaccine_type}"
f"Free slot! ({free_slots}) {vaccine_name}/{vaccine_type} Appointment date: {first_appoinment_date}")
msg = f"Freier Impfslot ({free_slots})! {vaccine_name}/{vaccine_type} verfügbar ab dem {first_appoinment_date}"

alert(msg)
sleep(settings.COOLDOWN_AFTER_SUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_impfbot.py
Expand Up @@ -93,9 +93,9 @@ def test_check_for_slot_in_stock(log_info_mock,
impfbot.check_for_slot()

alert_mock.assert_called_once_with(
"Freier Impfslot (253)! AstraZeneca/Vector")
"Freier Impfslot (253)! AstraZeneca/Vector verfügbar ab dem 31.05.2021")
log_info_mock.assert_called_once_with(
"Free slot! (253) AstraZeneca/Vector")
"Free slot! (253) AstraZeneca/Vector Appointment date: 31.05.2021")
log_warning_mock.assert_not_called()
log_error_mock.assert_not_called()

Expand Down

0 comments on commit 022cc03

Please sign in to comment.