Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Last active December 4, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lanfon72/e0a828dcb5df3d33cd2a to your computer and use it in GitHub Desktop.
Save lanfon72/e0a828dcb5df3d33cd2a to your computer and use it in GitHub Desktop.
NTU hospital hsin-chu branch ER board.
# !/usr/bin/env python
# coding:UTF-8
import re
import json
from datetime import datetime
import requests
requests.packages.urllib3.disable_warnings()
html = requests.get('https://www.hch.gov.tw/hch/Information/LatestNewsDetail.aspx?MNO=C025&ID=9791', verify=False)
keys = ['pending_doctor', 'pending_ward', 'pending_icu', 'pending_bed']
pending = re.findall(r"ng>(.+)?</str", html.text)
values = [int(ele.replace(u"人", '')) for ele in pending[1::2][1:-1]]
report = {k: v for k, v in zip(keys, values)}
report['hospital_sn'] = "0412040012"
report['full_reported'] = True if u"已通報" in pending[-1] else False
upt = pending[-2].split(u":")[-1].replace(r'&nbsp;', '')
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