Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save lanfon72/637b2e86dc063ea12eed to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/637b2e86dc063ea12eed to your computer and use it in GitHub Desktop.
prase sltung live ER status board
#!/usr/bin/env ptyhon
#coding:UTF-8
import requests, json, os, re
from datetime import datetime
os.environ['TZ'] = 'ROC'
html = requests.get('http://hmc.sltung.com.tw:4935/BED/bed.php')
html.encoding='big5'
pending = re.findall(u':(.+?)',html.text)
# prase like [u'\u5426', u'1', u'0', u'1', u'0']
values = [ int(ele) for ele in pending[1:] ]
keys = ['pending_doctor','pending_bed', 'pending_ward', 'pending_icu']
update_time = re.findall(u': (\d+-\d+-\d+ \d+:\d+:\d+)',html.text)[0]
#update_time = update_time.replace(update_time[0:3], str(int(update_time[0:3])+1911))
report = { key:value for value, key in zip(values, keys) }
report["hospital_sn"] = '0936060016'
report['full_reported'] = False if u'否' in pending[0] else True
report["update_time"] = datetime.strptime(update_time, '%Y-%m-%d %H:%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