Skip to content

Instantly share code, notes, and snippets.

res ="http://opendata.cwb.gov.tw/opendataapi?dataid=F-D0047-093&authorizationkey=CWB-9C0DCD15-928D-4E3F-A51A-2107C32DB59D"
urllib.request.urlretrieve(res,"F-D0047-093.zip")
f = zipfile.ZipFile('F-D0047-093.zip')
import zipfile
import urllib.request
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
import datetime
import os
import sqlite3 as lite
import requests
today = str(datetime.date.today())
cwb_data = "cwb_weather_data"
if not os.path.exists(cwb_data):
os.mkdir(cwb_data)
#開啟壓縮檔,不解壓縮
f = zipfile.ZipFile('F-D0047-093.zip')
file = ['63_72hr_CH.xml','64_72hr_CH.xml','65_72hr_CH.xml','66_72hr_CH.xml','67_72hr_CH.xml','68_72hr_CH.xml',
'09007_72hr_CH.xml','09020_72hr_CH.xml','10002_72hr_CH.xml','10004_72hr_CH.xml','10005_72hr_CH.xml',
'10007_72hr_CH.xml','10008_72hr_CH.xml','10009_72hr_CH.xml','10010_72hr_CH.xml','10013_72hr_CH.xml',
'10014_72hr_CH.xml','10015_72hr_CH.xml','10016_72hr_CH.xml','10017_72hr_CH.xml','10018_72hr_CH.xml',
'10020_72hr_CH.xml']
CITY = []
DISTRICT = []
#轉成Dataframe格式
df = pd.concat([pd.DataFrame({"CITY":CITY}),pd.DataFrame({"DISTRICT":DISTRICT}),pd.DataFrame({"GEOCODE":GEOCODE}),
pd.DataFrame({"DAY" : DAY}),pd.DataFrame({"TIME" : TIME}),pd.DataFrame({"TEMP":TEMP}),
pd.DataFrame({"TD" : TD}),pd.DataFrame({"RH":RH}),pd.DataFrame({"WIND" : WIND}),pd.DataFrame({"WS" : WS}),
pd.DataFrame({"BF":BF}),pd.DataFrame({"AT" : AT}),pd.DataFrame({"Wx": Wx}),pd.DataFrame({"Wx_n":Wx_n}),
pd.DataFrame({"PoP6h" : PoP6h}),pd.DataFrame({"PoP12h" :PoP12h}),pd.DataFrame({"get_day":get_day})],axis=1)
#存成csv
file_path = os.getcwd()
save_name = "taiwan_cwb" + today + ".csv"
#轉成list
listdata = df.values.tolist()
#連結資料庫
conn = lite.connect("weatherapi.sqlite")
cur = conn.cursor()
cur.execute('create table if not exists weather(CITY text,DISTRICT text,GEOCODE integer,DAY timestamp,TIME timestamp,TEMP integer,TD integer,RH integer,WIND text,WS integer,BF text,AT integer,Wx text,Wx_n integer,PoP6h integer,PoP12h integer,get_day timestamp);')
sql = "insert into weather(CITY ,DISTRICT ,GEOCODE ,DAY ,TIME ,TEMP ,TD ,RH,WIND ,WS ,BF ,AT ,Wx ,Wx_n ,PoP6h ,PoP12h ,get_day) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
# Read more about setting it up
# https://medium.com/@ljmocic/deploying-react-application-to-aws-s3-using-github-actions-85addacaeace
on:
push:
tags:
- '*'
jobs:
build:
{
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "none",
"overrides": [
{
"files": ["*.json5"],
"options": {
@kurt-liao
kurt-liao / es13_person.js
Last active July 20, 2022 08:27
Javascript ES13 Features
class Person {
name = 'Kurt'
getName() {
return this.name
}
}
@kurt-liao
kurt-liao / es2015_person.js
Created July 20, 2022 08:27
es2015 class
class Person {
constructor() {
this.name = 'Kurt'
}
getName() {
return this.name
}
}