Skip to content

Instantly share code, notes, and snippets.

Last active Mar 1, 2016
What would you like to do?
#!/usr/bin/env python
import os
import re
import json
import requests
import time
os.environ['TZ'] = 'ROC'
output = {key: None for key in ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu', 'full_reported', 'update_time']}
output['hospital_sn'] = '1302050014'
html = requests.get('')
if html.status_code == 200:
for i, match in enumerate(re.finditer(u'<span .*?>\s*(?P<number>\d+)\s*</', html.text)):
for key, value in {'pending_doctor': 'WaitingVisit', 'pending_bed': 'WaitingBed', 'pending_ward': 'WaitingBeingInHospital', 'pending_icu': 'WaitingICUBed'}.items():
output[key] = int('number'))
if i > 3: break
match_report ='【滿載】|【未滿載】', html.text)
match_time ='>(\d+/\d+/\d+\s*(?:上|下)午\s*\d+:\d+)', html.text)
if match_report:
output['full_reported'] = True if == u'【滿載】' else False
if match_time:
update_time ='上午','AM') if u'上午' in else'下午','PM')
update_time = re.sub(u'\s', '', update_time)
output['update_time'] = int(time.mktime(time.strptime(update_time, "%Y/%m/%d%p%I:%M")))
print json.dumps(output, ensure_ascii=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment