Skip to content

Instantly share code, notes, and snippets.

@pinebright
Created September 22, 2019 03:24
Show Gist options
  • Save pinebright/59c0efe0f1bcbca8edb5177e42d81ec0 to your computer and use it in GitHub Desktop.
Save pinebright/59c0efe0f1bcbca8edb5177e42d81ec0 to your computer and use it in GitHub Desktop.
番組名と話数から放送日時を調べるコード (refs しょぼいカレンダー http://cal.syoboi.jp)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import json
import urllib.request
from datetime import datetime, timezone, timedelta
def get_tid(title):
url = 'http://cal.syoboi.jp/json' + '?Req=TitleMedium'
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as res:
body = json.load(res)
for item in body['Titles'].values():
if item['Title'] == title:
return item['TID']
def get_schedule(tid, episode):
url = 'http://cal.syoboi.jp/json' + '?Req=ProgramByCount&TID=' + tid + '&Count=' + episode
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as res:
body = json.load(res)
JST = timezone(timedelta(hours=+9), 'JST')
for item in body["Programs"].values():
print(datetime.fromtimestamp(int(item["StTime"]), JST), item["ChName"])
def main():
parser = argparse.ArgumentParser()
parser.add_argument('title', help="title of program")
parser.add_argument('episode', help="episode number")
args = parser.parse_args()
get_schedule(get_tid(args.title), args.episode)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment