Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Created March 3, 2017 14:39
Show Gist options
  • Select an option

  • Save lanfon72/377feb93f92db059f9347acceff12e19 to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/377feb93f92db059f9347acceff12e19 to your computer and use it in GitHub Desktop.
parse cmuh live ER status board.
#!/usr/bin/env python
# coding:UTF-8
import re
import os
import json
from datetime import datetime
import requests
os.environ['TZ'] = 'ROC'
html = requests.post(r"http://61.66.117.28/EmrCount/Default.aspx")
pending = re.findall(r'"Black".+>(.+)</font>', html.text, re.UNICODE)
values = [int(ele) for ele in pending[2:]]
keys = ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu']
report = {key: value for value, key in zip(values, keys)}
upt = re.search(r'1">(.+)</s', html.text).group(1)
update_time = upt.replace(u'上午', 'am') if u'上午' in upt else upt.replace(u'下午', 'pm')
report["hospital_sn"] = '1131100010'
report['full_reported'] = False if u'否' in pending[1] else True
report["update_time"] = datetime.strptime(update_time, '%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