Last active
August 29, 2015 14:04
-
-
Save clkao/b8236e2b5c4e23519790 to your computer and use it in GitHub Desktop.
parse ntuh live ER status board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require! <[cheerio request fs moment-timezone]> | |
mapping = do | |
等候掛號人數: \pending_register | |
等候看診人數: \pending_doctor | |
等候住院人數: \pending_ward | |
等候ICU人數: \pending_icu | |
等候推床人數: \pending_bed | |
data = {} | |
err, {body}? <- request 'https://reg.ntuh.gov.tw/EmgInfoBoard/NTUHEmgInfo.aspx' | |
throw err if err | |
$ = cheerio.load body | |
$('form#form1').find 'tr' .each -> | |
[key, val] = $(@).find \td .map -> $ @ .text! | |
if val | |
key -= /:/ | |
val -= /人/ | |
if mapping[key] | |
data[that] = +val | |
else | |
throw "unknownkey: #key" | |
else if key is /資料擷取時間/ | |
[_, year, month, day, ampm, hour, minute, second]:al = key.match // (\d+)/(\d+)/(\d+)\s*(上午|下午)\s*(\d+):(\d+):(\d+) // | |
hour = +hour + 12 if ampm is \下午 | |
data.update_time = moment-timezone.tz {year, month: month-1, day, hour, minute, second}, 'Asia/Taipei' .valueOf! /1000ms | |
console.log JSON.stringify data, null 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment