Created
March 27, 2019 20:55
-
-
Save gelldur/e85da81c3c9ac7bc132826c33e7a08e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/python3 | |
import urllib.request | |
import time | |
import datetime | |
import subprocess | |
from html.parser import HTMLParser | |
from pprint import pprint | |
class MyHTMLParser(HTMLParser): | |
def __init__(self): | |
HTMLParser.__init__(self) | |
self.found = False | |
self.current_number = None | |
self.waiting_people = None | |
def handle_data(self, data): | |
data = data.strip() | |
#print("Encountered some data :", data) | |
if self.found and len(data) > 0: | |
if self.current_number is None: | |
self.current_number = data | |
elif self.waiting_people is None: | |
self.waiting_people = int(data.strip()) | |
if data == "Składanie wniosków o paszport": | |
self.found = True | |
def sendmessage(message): | |
subprocess.Popen(['notify-send', message]) | |
return | |
people_per_hour = 0 | |
people_per_hour_count = 0 | |
people_per_hour_start = datetime.datetime.now() | |
previous_waiting = None | |
while True: | |
contents = urllib.request.urlopen( | |
"http://rejestracjapoznan.poznan.uw.gov.pl/queueInfo").read().decode('utf-8') | |
parser = MyHTMLParser() | |
parser.feed(contents) | |
print("Current number: {}".format(parser.current_number)) | |
print("Waiting people: {}".format(parser.waiting_people)) | |
current_number = int(parser.current_number[1:]) | |
if previous_waiting is not None: | |
diff = current_number - previous_waiting | |
# Sometimes numbers can jump | |
if diff < 0: | |
diff = 1 | |
people_per_hour_count += diff | |
people_per_hour = people_per_hour_count / \ | |
((datetime.datetime.now() - people_per_hour_start).total_seconds()/60/60) | |
previous_waiting = current_number | |
print("Queue speed: {}".format(people_per_hour)) | |
if current_number > 100: | |
sendmessage("Hey current number: {}".format(parser.current_number)) | |
time.sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment