-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_config_from_issues.py
54 lines (41 loc) · 1.48 KB
/
update_config_from_issues.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import re
import json
import requests
from collections import OrderedDict
# Here's the documentation for the GitHub issues API:
# https://developer.github.com/v3/issues/#list-repository-issues
hashtag_re = re.compile(r"#([a-zA-Z0-9_]+)")
atname_re = re.compile(r"@([a-zA-Z0-9_]+)")
def add_game(atnames, hashtags, config):
for name in atnames:
name = name.lower()
if name not in config:
config[name] = []
for hashtag in hashtags:
hashtag = hashtag.lower()
if hashtag not in config[name]:
config[name].append(hashtag)
def get_issues():
return requests.get(
"https://api.github.com/repos/natbat/scicomm-calendar/issues"
).json()
def run():
issues = get_issues()
issues_to_add = [
issue
for issue in issues
if "game suggestion" in [l["name"] for l in issue["labels"]]
and issue["user"]["login"] == "natbat"
]
# load the config
config = json.load(open("config.json"), object_pairs_hook=OrderedDict)
for open_issue in issues_to_add:
issue_text = open_issue["title"] + " " + (open_issue["body"] or "")
issue_text = issue_text.replace("\u202a", "").replace("\u202c", "")
hashtags = hashtag_re.findall(issue_text)
atnames = atname_re.findall(issue_text)
add_game(atnames, hashtags, config)
# save the config
open("config.json", "w").write(json.dumps(config, indent=4))
if __name__ == "__main__":
run()