-
-
Save t0mst0ne/f40aab166fb536ae3e1b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib2 | |
import re | |
import time | |
import json | |
import os | |
os.environ['TZ'] = 'ROC' | |
html = urllib2.urlopen("https://www.cgmh.org.tw/bed/erd/index.asp?loc=2").read().decode("Big5") | |
query_time = re.findall(u'更新時間: (.*)</td>', html) | |
update_time = int(time.mktime(time.strptime(query_time[0], "%Y/%m/%d %H:%M:%S"))) | |
pattern = ur'<img.*?<FONT.*?>(.*?)</td>' | |
results = re.findall(pattern, html) | |
if results[0] == u'是' : | |
full_reported = True | |
else: | |
full_reported = False | |
pending_doctor = int(results[1]) | |
pending_bed = int(results[2]) | |
pending_ward = int(results[3]) | |
pending_icu = int(results[4]) | |
hospital_sn = str(1111060015) | |
report = [{"full_reported":full_reported, "pending_doctor":pending_doctor, "pending_bed":pending_bed,"pending_ward":pending_ward, "pending_icu":pending_icu, "update_time":update_time, "hospital_sn":hospital_sn }] | |
print json.dumps(report, ensure_ascii=False) |
audreyt
commented
Aug 4, 2014
from datetime import datetime
t="2014/08/05"
print datetime.strptime(t, "%Y/%m/%d").strftime('%s')
1407168000
Another solution for your reference
!/usr/bin/env python
coding:UTF-8
import re
import json
import requests
from datetime import datetime
keys = ['pending_doctor', 'pending_bed', 'pending_ward', 'pending_icu', 'full_reported', 'update_time']
r = requests.get("https://www.cgmh.org.tw/bed/erd/index.asp?loc=2")
r.encoding = 'big5'
match = [int(value) for value in re.findall(u'>(\d+)', r.text)]
match_report = re.findall(u'>(是|否)', r.text)[0]
match_time = re.findall(u'更新時間:\s_(._)', r.text)[0]
match.append(True if match_report == u'是' else False)
match.append(datetime.strptime(match_time,'%Y/%m/%d %H:%M:%S').strftime('%s'))
print json.dumps(dict(zip(keys, match)), ensure_ascii=False)
import time
update_time = int(time.mktime(time.strptime(query_time[0], '%Y/%m/%d %H:%M:%S')))