Last active
August 28, 2021 04:15
-
-
Save ryo-n/1b4149269c34ccb73afb330b97beae9c to your computer and use it in GitHub Desktop.
xbar clist plugin
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 python3 | |
import requests | |
import datetime | |
import json | |
USERNAME = "clist_username" | |
# コンテストサイトのリソースIDをカンマ区切りで記述 | |
# 各コンテストサイトのリソースIDは下記APIを呼べば一覧を取得することができる | |
# https://clist.by/api/v2/resrource/?username=ユーザ名&api_key=APIキー&limit=1000 | |
RESOURCE_IDS="1,93,109,103,102" | |
API_KEY = "clist_api_key" | |
headers = {'content-type': 'application/json'} | |
payload = {} | |
payload['resource_id__in'] = RESOURCE_IDS | |
payload['username'] = USERNAME | |
payload['api_key'] = API_KEY | |
payload['order_by'] = "start" | |
dt_now = datetime.datetime.now(datetime.timezone.utc) | |
now=dt_now.isoformat()[:19] | |
# 現在時刻で終了していないコンテスト一覧を取得 | |
payload['end__gt'] = now | |
api_url = "https://clist.by/api/v2/contest/" | |
response = requests.get(api_url, params=payload, headers=headers).json() | |
print("clist") | |
print("---") | |
for object in response['objects']: | |
dt = datetime.datetime.fromisoformat(object['start']) + datetime.timedelta(hours=9) | |
print(dt.isoformat()[5:-3] + " ", end="") | |
print("[" + dt.strftime("%a") + "] " + object['event'], end="") | |
print(f"|href={object['href']}", end="") | |
print(" font='SF Mono' size=12") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment