氣象開放資料平台 潮汐 to google calendar

I wish to make a google calendar for tidal info of certain location, so that I can open google calendar and have the time of high tie of several weekends.
for example: 淡水的 high tie 時間 this weekend.

There are few steps:

Getting data:
different sources comes with different numbers of data and different format.....(why?)
    1. method1: 政府資料開放平臺  it's a JSON file
      1. 潮汐預報-未來1個月潮汐預報https://data.gov.tw/dataset/7038
      2. 潮汐表-明年高低潮時潮高預報(every Oct)https://data.gov.tw/dataset/9205 
      3. this one contains less locations, for 2019 data, it's 42 locations.
    2.  中央氣象局開放資料平臺之資料擷取API: can be json or xml
      1. you need to first get an account and get a key(valid for a year.)
      2. 未來1個月潮汐預報 (no whole year one)
      3. it contain lot of locations,about 210 locations. location table is here: https://opendata.cwb.gov.tw/opendatadoc/MMC/A0021-001.pdf 
      4. I tried the key I found in 政府資料開放平台 some times it works fine...(rdec-key-123-45678-011121314)
Deal with JSON file

這兩種 data的包裝方法完全不同, 資料的密度也完全不同...
我先從氣象局的未來一個月的潮汐開始, 他有210個地點的潮汐資料,但是只有一個月, 所以我必須每個月抓一次資料...而且json file的結構有點混亂

這次使用 google的 Colaboratory 來做這件事, colab是google 的 ubuntu virtual machine, 有完整的 python2 or 3, 預先安裝了很多科學常用的library, 而且還有GPU/TPU可以用, 設計給 machine learning用,尤其是使用 tensorflow...
他的好處是不用去管library的安裝, 而且可以寫注解,單步執行, debug很好用
而且可以輕易的分享,共同建構...
這裏的分享,都可以自己另存新檔, 執行...
這個範例是從中央氣象局開放資料平臺 抓淡水得一個月潮汐資料,並且一層一層的去拆解資料,他真的很多層,很多我不需要的資料...
1_getting 氣象局 tidal_data_in_JSON_getinto_each_data

這個則是把我想要的資料取出,然後輸出CSV file, 這個CSV必須符合google calendar的ㄧ些格式: Import events to Google Calendar - Calendar Help

3_write 氣象局 one month tidal data to csv

測試ok後, 我只想在google calendar上show weekend的資料...

4_write 氣象局 one month_tidal_data_to_csv_weekend_only

辛苦的做了這麼久, 只能show一個月, 以後每個月都要run一次, 每個月的csv還會跟上個月有重複的問題, 這很麻煩, 因為google calendar可以用CSV批次匯入,但是沒有辦法用CSV做批次的刪除....


所以我轉向政府資料開放平臺
 https://data.gov.tw/dataset/9205 
潮汐表-明年高低潮時潮高預報
每年10月提供明年高低潮時潮高預報,地點、潮位、時間、潮高 about 25-26MB, 但是資料的格式非常不同,只是地點只有42個,每個都有一個ID...

一年份潮汐表內容的拆解,取淡水 ID 1102

只截取今天之後的weekend 放進csv










留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone