Last active
November 21, 2017 07:39
-
-
Save juhovh/beebd46e740c6612e13cffd9327963b2 to your computer and use it in GitHub Desktop.
MRoom queue status fetcher
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
import sys | |
import json | |
from time import sleep | |
try: | |
# For Python 3.0 and later | |
from urllib.request import urlopen, Request | |
from urllib.error import HTTPError | |
except ImportError: | |
from urllib2 import urlopen, Request, HTTPError | |
class SlugNotFoundException(Exception): | |
pass | |
def get_data(): | |
try: | |
res = urlopen('https://mroom.com/content/themes/propaganda/proxywithcountries.php') | |
return json.loads(res.read().decode('utf-8')) | |
except HTTPError as e: | |
print('Error fetching data %s' % e) | |
def get_location_strings(): | |
return map(lambda x: '%s - %s' % (x['slug'], x['name']), get_data()) | |
def print_availability(slug): | |
data = get_data() | |
loc = next(iter(filter(lambda x: x['slug'] == slug, data)), None) | |
if not loc: | |
raise SlugNotFoundException('Could not find the store you asked for: %s' % slug) | |
args = (loc['name'], loc['start'], loc['end'], loc['queue']['employees'], loc['queue']['count']) | |
print('Location %s opens at %s and closes at %s, has currently %d employees and %d people in queue' % args) | |
if len(sys.argv) < 2: | |
locs = get_location_strings() | |
print('Please give one of the locations as an argument') | |
for loc in locs: | |
print(loc) | |
exit(1) | |
slug = sys.argv[1] | |
try: | |
while True: | |
print_availability(slug) | |
sleep(10) | |
except SlugNotFoundException: | |
print('Given location id invalid: %s' % slug) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment