-
-
Save globalundo/b0e8f88f110cc54fdb71 to your computer and use it in GitHub Desktop.
Termin catcher
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
#!/usr/bin/python2 | |
# -*- coding: utf-8 -*- | |
import BeautifulSoup | |
import urllib | |
import re | |
from time import sleep | |
import webbrowser | |
import sys | |
SLEEP = 30 | |
def main(url): | |
days_prev = [] | |
while True: | |
html = BeautifulSoup.BeautifulSoup(urllib.urlopen(url)) | |
months = html.findAll('div', | |
{'class': 'calendar-month-table span6'}) | |
days = [] | |
for m in months: | |
days += [x.a['href'] for x in m.findAll('td', | |
{'class': 'buchbar '})] | |
print 'Found {0} days with termins'.format(len(days)) | |
if not days: | |
print 'No termins are avaliable in your timerange. Skipping sanity check..' | |
elif not days_prev: | |
print '''TEST: I will open an earliest termin now. | |
Please check your browser in {0} seconds'''.format(SLEEP) | |
days.pop(0) | |
days_prev = days | |
new_termins = set(days) - set(days_prev) | |
if new_termins: | |
for t in new_termins: | |
webbrowser.open_new('''http://service.berlin.de/ | |
terminvereinbarung/termin/{0}'''.format(t)) | |
days_prev = days | |
sleep(SLEEP) | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
url = raw_input('Enter termin url (http://service.berlin.de/...): ') | |
else: | |
url = sys.argv[1] | |
main(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment