-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron-script.py
26 lines (21 loc) · 894 Bytes
/
cron-script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import random
from github import Github
with open('today.json', 'r', encoding="utf8") as obj:
newChar = json.load(obj)
with open('characters.json', 'r', encoding="utf8") as chars:
characters = json.load(chars)
output = characters[random.randint(0, len(characters) - 1)]
while output == newChar:
output = characters[random.randint(0, len(characters) - 1)]
with open('today.json', 'w', encoding='utf8') as today:
json.dump(output, today, ensure_ascii=False)
# GitHub
with open('tybwkeys.txt','r') as key:
githubKey = key.read()
g = Github(githubKey)
repo = g.get_user().get_repo("tybwardle.com-v2.0-PRODUCTION")
today = repo.get_contents('backend/json/today.json')
output_json = json.dumps(output, ensure_ascii=False)
# update json
repo.update_file(today.path, "Automatic update to today.json time span via GitHub API", output_json, today.sha, branch="main")