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

Commit

Permalink
fix: flake8 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sibalzer committed May 25, 2021
1 parent 8207f11 commit ea80a0b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/alerts.py
Expand Up @@ -7,7 +7,7 @@
import settings


appointment_url = f"https://www.impfportal-niedersachsen.de/portal/#/appointment/public"
appointment_url = r"https://www.impfportal-niedersachsen.de/portal/#/appointment/public"


log = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions src/api_wrapper.py
Expand Up @@ -15,7 +15,7 @@

def fetch_api(plz: int, birthdate_timestamp: int = None, max_retries: int = 10, sleep_after_error: int = 30, sleep_after_shadowban: int = 300) -> any:
url = f"https://www.impfportal-niedersachsen.de/portal/rest/appointments/findVaccinationCenterListFree/{plz}"
if birthdate_timestamp != None:
if birthdate_timestamp is not None:
url += f"?stiko=&count=1&birthdate={int(birthdate_timestamp)*1000}"
fail_counter = 0

Expand All @@ -24,7 +24,7 @@ def fetch_api(plz: int, birthdate_timestamp: int = None, max_retries: int = 10,
session = Session()
with session.get(url=url, headers=headers, timeout=10) as data:
return data.json()["resultList"]
except Exception as e:
except Exception:
if fail_counter > max_retries:
log.error(
f"Couldn't fetch api. (Shadowbanned IP?) Sleeping for {sleep_after_shadowban}min")
Expand Down
11 changes: 6 additions & 5 deletions src/impfbot.py
Expand Up @@ -2,7 +2,7 @@
import settings
import api_wrapper
import alerts
from datetime import timedelta, datetime
from datetime import datetime

from common import sleep, sleep_until, is_night

Expand All @@ -11,8 +11,9 @@ def check_for_slot() -> None:
try:
result = api_wrapper.fetch_api(
plz=settings.ZIP,
birthdate_timestamp=int(datetime.now().timestamp() - (datetime.now() -
settings.BIRTHDATE).total_seconds()),
birthdate_timestamp=int(
datetime.now().timestamp() -
(datetime.now() - settings.BIRTHDATE).total_seconds()),
max_retries=5,
sleep_after_error=settings.SLEEP_BETWEEN_FAILED_REQUESTS_IN_S,
sleep_after_shadowban=settings.SLEEP_AFTER_DETECTED_SHADOWBAN_IN_MIN
Expand All @@ -27,7 +28,7 @@ def check_for_slot() -> None:

sleep(60*15, 15)
else:
log.info(f"No free slot.")
log.info("No free slot.")
except Exception as e:
log.error(f"Something went wrong ({e})")

Expand All @@ -36,7 +37,7 @@ def check_for_slot() -> None:
try:
while True:
if is_night() and settings.SLEEP_AT_NIGHT:
log.info(f"It's night. Sleeping until 7am")
log.info("It's night. Sleeping until 7am")
sleep_until(hour=7, minute=0)

check_for_slot()
Expand Down
32 changes: 16 additions & 16 deletions src/settings.py
Expand Up @@ -18,9 +18,9 @@

try:
SEND_EMAIL = True if config["EMAIL"]["enable"].lower() == "true" else False
except KeyError as e:
except KeyError:
log.warning(
f"[EMAIL] 'enable' is missing in Config. Set False")
"[EMAIL] 'enable' is missing in Config. Set False")
SEND_EMAIL = False

try:
Expand All @@ -39,50 +39,50 @@
try:
OPEN_BROWSER = True if config["WEBBROWSER"]["open_browser"].lower(
) == "true" else False
except KeyError as e:
except KeyError:
log.warning(
f"'open_browser' is missing in Config. Set False")
"'open_browser' is missing in Config. Set False")
OPEN_BROWSER = False

try:
SLEEP_BETWEEN_REQUESTS_IN_S = int(
config["ADVANCED"]["sleep_between_requests_in_s"])
except KeyError as e:
except KeyError:
log.warning(
f"'sleep_between_requests_in_s' is missing in Config. Set 5min")
"'sleep_between_requests_in_s' is missing in Config. Set 5min")
SLEEP_BETWEEN_REQUESTS_IN_S = 300

try:
SLEEP_BETWEEN_FAILED_REQUESTS_IN_S = int(
config["ADVANCED"]["sleep_between_failed_requests_in_s"])
except KeyError as e:
except KeyError:
log.warning(
f"'sleep_between_failed_requests_in_s' is missing in Config. Set 30s")
"'sleep_between_failed_requests_in_s' is missing in Config. Set 30s")
SLEEP_BETWEEN_FAILED_REQUESTS_IN_S = 30

try:
SLEEP_AFTER_DETECTED_SHADOWBAN_IN_MIN = int(
config["ADVANCED"]["sleep_after_ipban_in_min"])*60
except KeyError as e:
log.warning(f"'sleep_after_ipban_in_min' is missing in Config. Set 3h")
except KeyError:
log.warning("'sleep_after_ipban_in_min' is missing in Config. Set 3h")
SLEEP_AFTER_DETECTED_SHADOWBAN_IN_MIN = 60*180

try:
JITTER = int(
config["ADVANCED"]["jitter"])
except KeyError as e:
log.warning(f"'jitter' is missing in Config. Set 15")
except KeyError:
log.warning("'jitter' is missing in Config. Set 15")
JITTER = 15

try:
SLEEP_AT_NIGHT = True if config["ADVANCED"]["sleep_at_night"].lower(
) == "true" else False
except KeyError as e:
log.warning(f"'sleep_at_night' is missing in Config. Set True")
except KeyError:
log.warning("'sleep_at_night' is missing in Config. Set True")
SLEEP_AT_NIGHT = True

try:
USER_AGENT = config["ADVANCED"]["user_agent"]
except KeyError as e:
log.warning(f"'user_agent' is missing in config. set impfbot")
except KeyError:
log.warning("'user_agent' is missing in config. set impfbot")
USER_AGENT = 'impfbot'

0 comments on commit ea80a0b

Please sign in to comment.