云中客

梦想有多大,就能走多远

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

注册Google账号

Google Calendar API服务有效化

https://console.cloud.google.com/apis/dashboard

获取APIkey,并设置权限

Python代码获取数据

GOOGLE_API_KEY='xxxxxx'
 
# API URL
url = "https://www.googleapis.com/calendar/v3/calendars/%s/events?key=%s&timeMin=%s&timeMax=%s&orderBy=startTime&singleEvents=true" % (
    'japanese__ja@holiday.calendar.google.com',
    GOOGLE_API_KEY,
    '2022-01-01T00:00:00Z',
    '2022-12-31T00:00:00Z')
 
rp = requests.get(url=url)
if rp.status_code == 200:
    result = rp.json()
    if result:
        items = result.get("items")
        for data in items:
            print(data['summary']+":"+data["description"]+":"+data["start"]["date"])

执行结果如下:

元日:祝日:2022-01-01
成人の日:祝日:2022-01-10
建国記念の日:祝日:2022-02-11
天皇誕生日:祝日:2022-02-23
春分の日:祝日:2022-03-21
昭和の日:祝日:2022-04-29
憲法記念日:祝日:2022-05-03
みどりの日:祝日:2022-05-04
こどもの日:祝日:2022-05-05
海の日:祝日:2022-07-18
山の日:祝日:2022-08-11
敬老の日:祝日:2022-09-19
秋分の日:祝日:2022-09-23
スポーツの日:祝日:2022-10-10
文化の日:祝日:2022-11-03
勤労感謝の日:祝日:2022-11-23
posted on 2022-08-26 15:16  走遍江湖  阅读(98)  评论(0编辑  收藏  举报