Last active
July 27, 2020 20:04
-
-
Save jhrmnn/0a7624279633c16ba109d41904a9b3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
# Any copyright is dedicated to the Public Domain. | |
# https://creativecommons.org/publicdomain/zero/1.0/ | |
from splinter import Browser | |
from subprocess import call | |
from time import time, sleep | |
limit = 20 | |
url = 'https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&anliegen[]=120686&dienstleisterlist=122210,327316,122217,122219,327312,327314,122227,327346,327423,327348,122252,327338,122260,327340,122262,122254,327278,327274,327276,327294,327290,327292,122291,327270,122285,327266,122286,327264,122296,327268,150230,327282,327286,327284,122312,122314,122304,327330,122311,327334,122309,327332,317869,324433,325341,324434,327352,324414,122283,327354,122276,327324,122274,327326,122267,327328,122246,327318,122251,327320,122257,327322,122208,327298,122226,327300' | |
def notify(title, msg): | |
call(['terminal-notifier', '-message', msg, '-title', title]) | |
class Session: | |
def __init__(self, browser='firefox'): | |
self.browser = Browser(browser) | |
self.last_reloaded = time() | |
self.browser.visit(url) | |
def reload(self): | |
while time()-self.last_reloaded < limit: | |
sleep(1) | |
self.last_reloaded = time() | |
self.browser.reload() | |
def search(self): | |
found = False | |
for table in self.browser.find_by_css('.calendar-month-table'): | |
month = table.find_by_css('th.month').text.strip() | |
for field in table.find_by_tag('td'): | |
cls = field['class'] | |
if cls and 'nichtbuchbar' not in cls: | |
day = int(field.find_by_tag('span').text) | |
if not ( | |
month == 'Oktober 2016' and day >= 17 and day <= 21 | |
): | |
continue | |
msg = '{} {} found!'.format(day, month) | |
notify('Anmelder', msg) | |
print(msg) | |
found = True | |
return found | |
if __name__ == '__main__': | |
session = Session() | |
while True: | |
if session.search(): | |
input() | |
session.reload() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment