Skip to content

Instantly share code, notes, and snippets.

@t0mst0ne
Last active August 29, 2015 14:04
Show Gist options
  • Save t0mst0ne/fba18dcfd89b5ac69b9e to your computer and use it in GitHub Desktop.
Save t0mst0ne/fba18dcfd89b5ac69b9e to your computer and use it in GitHub Desktop.
馬偕醫院
#!/usr/bin/env python
#coding:UTF-8
# 馬偕 by t0mst0ne
import os
import re
import json
import requests
os.environ['TZ'] = 'ROC'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36', 'Content-Type': 'application/x-www-form-urlencoded', 'Referer': 'https://trns.mmh.org.tw/WebEMR/Default.aspx', 'Accept-Encoding': 'gzip,deflate,sdch', 'Accept-Language': 'zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2', 'Cookie': 'ASPSESSIONIDQSRRSRQC=DNKDKBEAFLNDPCLLIMHDNMEG' }
data = {'RadioButtonList1':'1', '__EVENTTARGET':'', '__EVENTARGUMENT':'', '__LASTFOCUS':'', '__VIEWSTATE':'/wEPDwUKLTg4MTI3NDI5MQ9kFgICAw9kFgQCBQ8QZGQWAQIBZAIHDzwrAA0BAA8WBB4LXyFEYXRhQm91bmRnHgtfIUl0ZW1Db3VudAIGZBYCZg9kFg4CAQ9kFgRmDw8WAh4EVGV4dAUP6KiK5oGv5pmC6ZaT77yaZGQCAQ8PFgIfAgUVMjAxNC84LzYg5LiK5Y2IIDAxOjM0ZGQCAg9kFgRmDw8WAh8CBSHlt7LlkJExMTnpgJrloLHmu7/luorvvIjovInvvInvvJpkZAIBDw8WAh8CBQPlkKZkZAIDD2QWBGYPDxYCHwIFFeetieW+heeci+iouuS6uuaVuO+8mmRkAgEPDxYCHwIFATZkZAIED2QWBGYPDxYCHwIFFeetieW+heaOqOW6iuS6uuaVuO+8mmRkAgEPDxYCHwIFATBkZAIFD2QWBGYPDxYCHwIFFeetieW+heS9j+mZouS6uuaVuO+8mmRkAgEPDxYCHwIFAjE4ZGQCBg9kFgRmDw8WAh8CBRvnrYnlvoXliqDorbfnl4XmiL/kurrmlbjvvJpkZAIBDw8WAh8CBQEwZGQCBw8PFgIeB1Zpc2libGVoZGQYAQUJR3JpZFZpZXcyDzwrAAkBCAIBZMHdxgUlbCwhEhGv7jcy/vdDPM4Q', 'Button1':u'查詢', '__EVENTVALIDATION':'/wEWBQKMpZfvBAL444i9AQL544i9AQL3jKLTDQKM54rGBga9OHdzNiFVAluD8E3DE64vEWO9' }
hospital_sn = str(1101100011)
requests.packages.urllib3.disable_warnings()
html = requests.post('https://trns.mmh.org.tw/WebEMR/Default.aspx', verify=False, headers=headers, data=data)
pending_doctor = int(re.findall(ur'等待看診人數.+>(\d+)</td>', html.text)[0])
pending_bed = int(re.findall(ur'等待推床人數.+>(\d+)</td>', html.text)[0])
pending_ward = int(re.findall(ur'等待住院人數.+>(\d+)</td>', html.text)[0])
pending_icu = int(re.findall(ur'等待加護病房人數.+>(\d+)</td>', html.text)[0])
query_time = re.findall(ur'訊息時間.+>(.+)</td>', html.text)[0]
reported = re.findall(ur'已向119通報滿床.+>(.+)</td>', html.text)[0]
query_time = query_time.split()
if u'下午' in query_time:
P = 'PM'
else:
P = 'AM'
from datetime import datetime
update_time = datetime.strptime(str(query_time[0] +P+query_time[2]),'%Y/%m/%d%p%I:%M').strftime('%s')
if u'reported' == u'是' :
full_reported = True
else:
full_reported = False
report = [{"hospital_sn":hospital_sn, "update_time":update_time, "full_reported":full_reported, "pending_doctor":pending_doctor, "pending_bed":pending_bed, "pending_ward":pending_ward, "pending_icu":pending_icu }]
print ( json.dumps(report, ensure_ascii=False) )
@t0mst0ne
Copy link
Author

output looks like:
[{"update_time": "1408938600", "pending_bed": 24, "pending_icu": 0, "hospital_sn": "1101100011", "full_reported": false, "pending_doctor": 3, "pending_ward": 39}]

@t0mst0ne
Copy link
Author

error
if query_time[1] == u'下午' :
P = 'PM'
else:
P = 'AM'

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