Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Last active September 23, 2016 06:45
Show Gist options
  • Save qinshulei/4d6322f2a2f582fe4e37075e7ae0d4e4 to your computer and use it in GitHub Desktop.
Save qinshulei/4d6322f2a2f582fe4e37075e7ae0d4e4 to your computer and use it in GitHub Desktop.
get holiday
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from urllib import urlencode
#----------------------------------
# 万年历调用示例代码 - 聚合数据
# 在线接口文档:https://www.juhe.cn/docs/api/id/177
#----------------------------------
def main():
#配置您申请的APPKey
appkey = "abb97b1676f78669a47e9addfdf93b79"
#3.获取当年的假期列表
request3(2015, appkey,"GET")
request3(2016, appkey,"GET")
#获取当年的假期列表
def request3(year, appkey, m="GET"):
url = "http://japi.juhe.cn/calendar/year"
params = {
"key" : appkey, #您申请的appKey
"year" : year, #指定年份,格式为YYYY,如:2015
}
params = urlencode(params)
if m =="GET":
f = urllib.urlopen("%s?%s" % (url, params))
else:
f = urllib.urlopen(url, params)
content = f.read()
res = json.loads(content)
if res:
error_code = res["error_code"]
if error_code == 0:
#成功请求
holidaylist = json.loads(res["result"]["data"]["holidaylist"])
for i in holidaylist:
print i["startday"]
else:
print "%s:%s" % (res["error_code"],res["reason"])
else:
print "request api error"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment