Skip to content

Instantly share code, notes, and snippets.

@lancetw
Last active December 4, 2016 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lancetw/8e2f2c03e087938c1f9b6031d63558e1 to your computer and use it in GitHub Desktop.
Save lancetw/8e2f2c03e087938c1f9b6031d63558e1 to your computer and use it in GitHub Desktop.
NTU hospital hsin-chu branch ER board. (updated 20161203)
# !/usr/bin/env python
# coding:UTF-8
import requests, json, re
from datetime import datetime
html = requests.get('http://reg.ntuh.gov.tw/EmgInfoBoard/NTUHEmgInfoT4.aspx', verify=False)
keys = ['pending_doctor', 'pending_ward', 'pending_icu', 'pending_bed']
pending0 = re.findall(r"<td(.*?)>(.+?)</td>", html.text)
pending1 = re.findall(r"<div(.*?)>(.+?)</div>", html.text)
values = [int(ele[1].replace(u"人", '')) for ele in pending0[1::2][1:]]
report = {k: v for k, v in zip(keys, values)}
report['hospital_sn'] = "0412040012"
report['full_reported'] = False if u"未通報" in pending1[1][1] else True
upt = pending0[-1][1].split(u":")[-1]
upt = upt.replace(u" 上午 ", 'am') if u"上午" in upt else upt.replace(u" 下午 ", 'pm')
report['update_time'] = datetime.strptime(upt, '%Y/%m/%d%p%I:%M:%S').strftime("%s")
print(json.dumps(report, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment