【时间处理】获取官方节假日数据的api接口,获取指定日期的节假日数据


获取指定日期的节假日信息

1、接口地址:http://api.goseek.cn/Tools/holiday?date=数字日期
2、返回数据:正常工作日对应结果为 0, 法定节假日对应结果为 1, 节假日调休补班对应的结果为 2,休息日对应结果为 3 
3、节假日数据说明:本接口包含2017年起的中国法定节假日数据,数据来源国务院发布的公告,每年更新1次,确保数据最新
4、示例:
http://api.goseek.cn/Tools/holiday?date=20170528 
返回数据:

{"code":10000,"data":1}     


免费节假日API 开源了,可以离线调用, 可以集成到自己系统中

功能

  • 检查具体日期是否为节假日,工作日对应结果为 0, 休息日对应结果为 1, 节假日对应的结果为 2;(对应支付工资比例分别为 100%, 200% 和 300%,以方便程序计算。计算方法:基本工资* (1+结果数值))
  • 获取具体月份下的节假日情况,只返回休息日或者节假日数据;
  • 可同时传递一个或者多个日期(月份);
  • 支持 2009 年起至 2019 年中国法定节假日,以国务院发布的公告为准,随时调整及增加:http://www.gov.cn/zfwj/bgtfd.htm或http://www.gov.cn/zhengce/xxgkzl.htm

注:当结果为数组时默认返回数据为 json 格式。

开源说明

注:原百度节假日API即为本人提供,后百度apistore禁止个人开发者所以才有此独立接口。鉴于免费版访问量过大对于服务器压力过大现将免费版开源供大家离线调用。

开源的功能为最核心的内容.大家可自行根据需要进行二次开发。

仅有php版本,其它语言可以参考代码自行开发

使用说明

  1. 下载源码部署到到系统中直接调用?d=日期
  2. 离线调用方法
 include('include/dateapi.class.php');
 $api= new dateapi();
 $result= $api->getday($date);


实现代码:

import calendar
from  urllib import request
from random import randrange
import json
import time



year = 2020
data_list = []
for month in range(1,13):
    week_list = calendar.monthcalendar(year,month)
    for i in week_list:
        for j in i:
            if j!=0:
                # 法定节假日信息
                # target_url = "http://www.easybots.cn/api/holiday.php?d=%s%02d%02d"% + current_date
                current_date = "%s%02d%02d"%(year,month,j)
                target_url = "http://api.goseek.cn/Tools/holiday?date=" + current_date
                # target_url = "http://tool.bitefu.net/jiari?date=%s%02d%02d" + current_date
                print(target_url)
                headers = [
                    ("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"),
                    ("Accept-Encoding", "gzip, deflate"),
                    ("Accept-Language", "zh-CN,zh;q=0.9"),
                    ("Connection", "keep-alive"),
                    ("Host", "api.goseek.cn"),
                    ("Upgrade-Insecure-Requests", 1),
                    ("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36")
                ]

                opener = request.build_opener()
                opener.addheaders = headers
                resp = opener.open(target_url).read()
                # resp = request.urlopen(url=target_url).read()
                print(resp)
                res = json.loads(resp)
                res["date"] = current_date
                print(res)
                # resp = str(resp)[2:-1].replace("\"","'")
                data_list.append(res)
                time.sleep(randrange(2,10))

data = json.dumps(data_list)
with open("{}cla.json".format(year),"w",encoding="utf-8") as fp:
    fp.write(data)


with open("{}cla.json".format(year),"r",encoding="utf-8") as fp:
    a = fp.read()
    b = json.loads(a)
    print(a)

for i in b:
    print(i)

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值