Created
December 19, 2016 07:25
-
-
Save parkjinwoo/47b6ff2d7e7494dafbfc22bd4796df85 to your computer and use it in GitHub Desktop.
offdays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import datetime | |
import requests | |
def get_cal(yyyymm): | |
url = 'http://csearch.naver.com/content/apirender.nhn?where=nexearch&key=CalendarAnniversary' | |
payload = {'q': '{}월'.format(yyyymm)} | |
res = requests.get(url, params=payload) | |
return cal_to_list(res.json(), '{}'.format(yyyymm)) | |
def cal_to_list(cd, yyyymm): | |
return [d for d in cd['openCalendar']['daysList'] if d['solarDate'].startswith(yyyymm)] | |
def get_off_days(days): | |
return [day for day in days if day_off_filter(day['anniversaryList'])] | |
def day_off_filter(al): | |
return len([d for d in al if d['dayOff'] == 'true']) > 0 | |
def list_to_dict(days): | |
cd = {} | |
for d in days: | |
di = {"off":True, "names":[i['name'] for i in d['anniversaryList']]} | |
cd[d['solarDate']] = di | |
return cd | |
def yyyymm_list(): | |
dl = [] | |
dt = datetime.date.today() | |
for i in range(60): | |
dl.append(dt.strftime('%Y%m')) | |
dt = dt.replace(day=1) + datetime.timedelta(32) | |
return dl | |
res_cd = {} | |
for yyyymm in yyyymm_list(): | |
cd = list_to_dict(get_off_days(get_cal(yyyymm))) | |
res_cd.update(cd) | |
#print("""(function(factory) { | |
# if (typeof define === 'function' && define.amd) { | |
# define(['jquery'], factory); | |
# } else { | |
# factory(); | |
# } | |
#}(function () { | |
# var offdaysMap = %s; | |
# var Offdays = { | |
# isOffday: function(ymd) { | |
# return offdaysMap[ymd] && offdaysMap[ymd]['off']; | |
# }, | |
# isHoliday: function(y, m, d) { | |
# y = y + ''; | |
# m = m + ''; | |
# d = d + ''; | |
# mm = m.length === 2 ? m : '0' + m; | |
# dd = d.length === 2 ? d : '0' + d; | |
# yyyymmdd = y + mm + dd; | |
# return Offdays.isOffday(yyyymmdd); | |
# } | |
# }; | |
# return Offdays; | |
#}));""" % | |
print(json.dumps(res_cd, sort_keys=True)) | |
#) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment