Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Last active August 29, 2015 14:04
Show Gist options
  • Save lanfon72/954b5d96ddf0e365f22f to your computer and use it in GitHub Desktop.
Save lanfon72/954b5d96ddf0e365f22f to your computer and use it in GitHub Desktop.
parse wanfangh live ER status board
#!/usr/bin/env python
#coding:UTF-8
import requests, re, json, os
from datetime import datetime
os.environ['TZ'] = 'ROC'
html = requests.get('http://www.wanfang.gov.tw/p11_information.aspx')
update_time = re.findall(u"日期:(.+?)</div",html.text)[0]
pending = re.findall(u"\'>(.+?)</div",html.text)[:-1]
# prase like ["<div class='p11_con'><div class='p11_icon05'>否", '1', '0', '16', '1']
pending[0] = pending[0][-1] #take "否" or "是"
values = [int(ele) for ele in pending[1:]]
keys = ['pending_doctor','pending_bed', 'pending_ward', 'pending_icu']
report = { key:value for value, key in zip(values, keys) }
report["hospital_sn"] = '1301200010'
report['full_reported'] = False if pending[0]==u'否' else True
report["update_time"] = datetime.strptime(update_time, '%Y/%m/%d %H:%M').strftime('%s')
#using .timestamp() if py3 else .strftime('%s')
print ( json.dumps(report, ensure_ascii=False) )
#[{"update_time": "1407225600", "pending_ICU": 2, "pending_bed": 0, "full_reported": false, "Hosptial_SN": "1301200010", "pending_doctor": 2, "pending_ward": 19}]
@lanfon72
Copy link
Author

lanfon72 commented Aug 5, 2014

fix int value, strftime()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment