Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Last active March 3, 2017 06:25
Show Gist options
  • Save lanfon72/7a43aedc8e8f7f63ca0a to your computer and use it in GitHub Desktop.
Save lanfon72/7a43aedc8e8f7f63ca0a to your computer and use it in GitHub Desktop.
prase mmh(TamShui) live ER status board
#!/usr/bin/env python
#coding:UTF-8
import requests, re, json, os
from datetime import datetime
os.environ['TZ'] = 'ROC'
headers = {"Accept": "*/*", "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "User-Agent": " Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36"}
data = {'RadioButtonList1': '2', '__EVENTARGUMENT': '', '__EVENTTARGET': 'RadioButtonList1$1', '__EVENTVALIDATION': '/wEWBQKuhbKKAwL444i9AQL544i9AQL3jKLTDQKM54rGBiyOzv44KJOw6BT65+syY0+hyJGU', '__LASTFOCUS': '', '__VIEWSTATE': '/wEPDwUKLTg4MTI3NDI5MQ9kFgICAw9kFgQCBQ8QZGQWAWZkAgcPPCsADQEADxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50AgZkFgJmD2QWDgIBD2QWBGYPDxYCHgRUZXh0BQ/oqIrmga/mmYLplpPvvJpkZAIBDw8WAh8CBRUyMDE3LzMvMyDkuIvljYggMDI6MDlkZAICD2QWBGYPDxYCHwIFIeW3suWQkTExOemAmuWgsea7v+W6iu+8iOi8ie+8ie+8mmRkAgEPDxYCHwIFA+WQpmRkAgMPZBYEZg8PFgIfAgUV562J5b6F55yL6Ki65Lq65pW477yaZGQCAQ8PFgIfAgUBNWRkAgQPZBYEZg8PFgIfAgUV562J5b6F5o6o5bqK5Lq65pW477yaZGQCAQ8PFgIfAgUBMGRkAgUPZBYEZg8PFgIfAgUV562J5b6F5L2P6Zmi5Lq65pW477yaZGQCAQ8PFgIfAgUCNTFkZAIGD2QWBGYPDxYCHwIFG+etieW+heWKoOitt+eXheaIv+S6uuaVuO+8mmRkAgEPDxYCHwIFATBkZAIHDw8WAh4HVmlzaWJsZWhkZBgBBQlHcmlkVmlldzIPPCsACgEIAgFkVpgUKVV8qUCkLvZ05BLfSgcX9PM=', '__VIEWSTATEGENERATOR': '35A9B5C0'}
html = requests.post('https://wapps.mmh.org.tw/WebEMR/WebEMR/Default.aspx', headers=headers, data=data)
pending = re.findall(u':</td><td>(.+?)</td>',html.text)
#parse like ['2014/8/6 上午 01:40', '否', '6', '0', '18', '0']
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) }
update_time = pending[0].replace(u'上午','am') if u'上午' in pending[0] else pending[0].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').strftime('%s')
print ( json.dumps(report, ensure_ascii=False) )
@lanfon72
Copy link
Author

lanfon72 commented Aug 5, 2014

print like [{"pending_bed": 0, "full_reported": false, "pending_ICU": 0, "Hosptial_SN": "1131100010", "update_time": 1407262320.0, "pending_ward": 18, "pending_d
octor": 6}]

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