Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

http://timor.tech/api/holiday/info/2023-05-01这个网站可以判断是否工作日,返回值type为0时即为工作日,请用python写一个函数判…

  1. User
  2. Assistant

    您可以使用requests库来发送API请求并检查返回值。首先,确保您已安装requests库。 如果没有,可以使用以下命令安装:

    pip install requests
    

    然后,您可以编写以下Python函数来检查给定日期是否为工作日:

    import requests
    
    def is_workday(date: str) -> bool:
        url = f'http://timor.tech/api/holiday/info/{date}'
        response = requests.get(url)
        data = response.json()
        
        if data['type'] == 0:
            return True
        else:
            return False
    
    date_to_check = '2023-05-01'
    print(is_workday(date_to_check))
    

    将date_to_check替换为您要检查的日期,并运行函数。函数返回True时表示工作日,False时表示非工作日。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.