Skip to content

Instantly share code, notes, and snippets.

@dzonesasaki
Last active January 4, 2023 02:13
Show Gist options
  • Save dzonesasaki/1ebe05724b17a9328fd11e1f44d8c00b to your computer and use it in GitHub Desktop.
Save dzonesasaki/1ebe05724b17a9328fd11e1f44d8c00b to your computer and use it in GitHub Desktop.
converting holiday list from syukujitsu.csv to date tsv only this year
import datetime
import os
mojico=['shift_jis','cp932','utf-8']
myurl='https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv'
fnameL='syukujitsu.csv'
# forlat: Y/M/D,name
if os.path.exists(fnameL):
with open(fnameL, 'rt',encoding=mojico[0]) as fid:
txtorg = fid.read()
else:
import requests
txtorg = requests.session().get(myurl).text
thisyear = datetime.datetime.now().year
holidaystsv = ''
for oneline in txtorg.split('\n'):
if str(thisyear) in oneline:
strdate,holidayname = oneline.split(',')
holidaystsv += strdate.replace('/','\t') + '\n'
# print(holidaystsv)
fnames='holidaylist_'+str(thisyear)+'.csv'
with open(fnames,'wt') as fid:
fid.write(holidaystsv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment