-
Notifications
You must be signed in to change notification settings - Fork 18
/
gen_recently_commented.py
48 lines (40 loc) · 1.39 KB
/
gen_recently_commented.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
# -*- coding: UTF-8 -*-
from github import Github
import json
import sys
courses_json = "./courses.json"
grade_urls = [
"/courses/grade-1/", "/courses/grade-2/",
"/courses/grade-3/", "/courses/grade-4/"
]
grade_dirs = ["." + x for x in grade_urls]
with open(courses_json, encoding="utf8") as f:
courses = json.load(f)
course2file = {}
for i in range(4):
grade_courses, grade_dir, grade_url = courses[i], grade_dirs[i], grade_urls[i]
for course_id in grade_courses:
course2file[course_id] = grade_url + course_id
if __name__ == "__main__":
if len(sys.argv) < 2:
print("plz provide a Github access token")
exit(1)
access_token = sys.argv[1]
g = Github(access_token)
repo = g.get_repo("sjtu-ieee/ieee.icu")
print("# 最新评论\n")
issues = repo.get_issues(sort="updated")
date_courses = {}
for issue in issues:
if issue.comments == 0:
continue
title = issue.title
if title.split()[0] not in course2file:
continue
date = str(issue.updated_at).split()[0]
course_id, course_name = title.split()[:2]
date_courses.setdefault(date, []).append("[{} {}]({})".format(
course_id, course_name, course2file[course_id]))
for date in sorted(date_courses.keys(), reverse=True):
print("- {}: ".format(date) + ", ".join(sorted(date_courses[date])))
print()