Skip to content

Instantly share code, notes, and snippets.

@Ray901
Last active January 14, 2025 05:45
Show Gist options
  • Select an option

  • Save Ray901/0e100cf81de97773c6f11edb25a8d088 to your computer and use it in GitHub Desktop.

Select an option

Save Ray901/0e100cf81de97773c6f11edb25a8d088 to your computer and use it in GitHub Desktop.
Get Taiwan Calendar from API
import requests
import pandas as pd
import pyodbc
accountfile = 'Text.txt'
with open(accountfile) as data:
accounts = data.readlines()
BIDW = list(filter(lambda x:'DB_USER' in x, accounts))
DBPW = BIDW[0].split('/')[1]
proxies = {
'https': 'x.x.x.x:port'
}
url = "https://data.ntpc.gov.tw/api/datasets/308dcd75-6434-45bc-a95f-584da4fed251/json?page=0&size=2000"
resp = requests.get(url, proxies=proxies, verify=False)
data = resp.json()
df = pd.DataFrame(data)
df = df[['date','name','isholiday','holidaycategory','description']]
df['date'] = pd.to_datetime(df['date'])
conn=pyodbc.connect('DRIVER={Oracle Driver};Dbq='X'; Uid='DB_USER'; Pwd='+DBPW)
SQLCommand = ("""
INSERT INTO BI_DIM_HOLIDAY (DATEID, DATE_NAME, IS_HOLIDAY, HOLIDAY_CATEGORY, HOLIDAY_DESC)
VALUES (?, ?, ?, ?, ?)
""")
rows = [tuple(x) for x in df.values]
cursor = conn.cursor()
SQLTruncateTable = (
"""
TRUNCATE TABLE HOLIDAY_TABLE
""")
cursor.execute(SQLTruncateTable)
for row in rows:
cursor.execute(SQLCommand, row)
conn.commit()
cursor.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment