開放源碼香港天氣計劃 hk0weather
昨晚半夜終於第一次放 source code 上 github,hk0weather 是其中一個我打算拿出來 open source 的 projects。把 hk0weather 開放源碼的其中一個原因是,希望幫助打造香港的 Open Data 之類,實在忍不了香港某方那些所謂 (很爛的) Open Data 的格式。同時我也欣賞台灣的 g0v.tw 的工作,一直我也對一些政府或公共資料該如何公開 (open data) 有些意見 (提議),而由民間或社群來進行也是其中一個可取的方法,來帶動香港的 open data 發展。
https://github.com/sammyfung/hk0weather
第一個版本是把香港天文台的天氣報告,把各氣象站的溫度,以及香港天文台錄得的相對濕度,轉化以 json 資料或其他格式。基本上已足夠一般網站,從輸出 json 資料中取得香港氣溫來顯示。
hk0weather 是以 python 來編寫,利用 scrapy 作 web crawling 的 framework。以下是未經測試的使用例子。
$ virtualenv hk0weatherenv
$ source hk0weatherenv/bin/activate
$ pip install scrapy
$ git clone https://github.com/sammyfung/hk0weather.git
$ cd hk0weather
$ scrapy crawl currwx -t json -o testresult
以下是測試結果的 json 輸出。
[{"humidity": 80, "station": "hko", "temperture": 17, "time": 1360785720},
{"station": "kingspark", "temperture": 16, "time": 1360785720},
{"station": "wongchukhang", "temperture": 17, "time": 1360785720},
{"station": "takwuling", "temperture": 16, "time": 1360785720},
{"station": "laufaushan", "temperture": 15, "time": 1360785720},
{"station": "taipo", "temperture": 16, "time": 1360785720},
{"station": "shatin", "temperture": 17, "time": 1360785720},
{"station": "tuenmun", "temperture": 17, "time": 1360785720},
{"station": "tseungkwano", "temperture": 16, "time": 1360785720},
{"station": "saikung", "temperture": 16, "time": 1360785720},
{"station": "cheungchau", "temperture": 17, "time": 1360785720},
{"station": "cheungchau", "temperture": 17, "time": 1360785720},
{"station": "tsingyi", "temperture": 17, "time": 1360785720},
{"station": "shekkong", "temperture": 15, "time": 1360785720},
{"station": "tsuenwanhokoon", "temperture": 15, "time": 1360785720},
{"station": "tsuenwanshingmunvalley", "temperture": 17, "time": 1360785720},
{"station": "hongkongpark", "temperture": 17, "time": 1360785720},
{"station": "shaukeiwan", "temperture": 16, "time": 1360785720},
{"station": "kowlooncity", "temperture": 16, "time": 1360785720},
{"station": "happyvalley", "temperture": 18, "time": 1360785720},
{"station": "wongtaisin", "temperture": 17, "time": 1360785720},
{"station": "stanley", "temperture": 16, "time": 1360785720},
{"station": "kwuntong", "temperture": 15, "time": 1360785720},
{"station": "shamshuipo", "temperture": 17, "time": 1360785720}]
hk0weather 計劃未來除了會慢慢加入更多不同的氣象資料外,也打算跟一些比我更 pro 的氣象發燒友合作。而 hk0weather 這個 open source 版本是我另外重寫的,跟我在 twitter 的 @weatherhk 背後所運行的 python 程式有所不同。
Related posts
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.


would you want to add this under OpenDataHK organization? https://github.com/OpenDataHK