Skip to content

Instantly share code, notes, and snippets.

@lancetw
Created December 3, 2016 08:16
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/6a1e3ba23302bad6e576135861afe5a4 to your computer and use it in GitHub Desktop.
Save lancetw/6a1e3ba23302bad6e576135861afe5a4 to your computer and use it in GitHub Desktop.
Cathay general hospital Hsinchu branch ER board. (updated 20161203)
# !/usr/bin/env python
# coding:UTF-8
import requests, json, re
from datetime import datetime
html = requests.get('http://med.cgh.org.tw/unit/branch/Pharmacy/ebl/RealTimeInfoHC.html', verify=False)
keys = ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu']
pending0 = re.findall(r"<td(.*?)>(.+?)</td>", html.text)
pending1 = re.findall(r"<p(.*?)>(.+?)</p>", html.text)
values = [int(ele[1]) for ele in pending0[2::4][1:]]
report = {k: v for k, v in zip(keys, values)}
report['hospital_sn'] = "1112010528"
report['full_reported'] = True if u"是" in (pending0[2::4][0:][0][1]).encode('latin1', 'ignore').decode('big5') else False
upt = ':'.join(pending1[-1][1].encode('latin1', 'ignore').decode('big5').split(u":")[1:])
upt = upt.replace(upt[0:3], str(int(upt[0:3])+ 1911))
report['update_time'] = datetime.strptime(upt, '%Y/%m/%d %H:%M').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