-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.py
66 lines (56 loc) · 2.03 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
import argparse
from datetime import datetime
from github import Github
from github_daily.config import LABEL_DICT, MY_BLOG_REPO
from github_daily.utils import (
make_base_issues_comments_str,
make_blog_issues_str,
make_cook_issue_table,
replace_readme_comments,
)
def get_me(user):
return user.get_user().login
def login(token):
return Github(token)
def main(github_token, repo_name, issue_number, issue_label_name):
# issue_number for future use
u = login(github_token)
me = get_me(u)
if issue_number:
labels = LABEL_DICT.get(issue_label_name)
if not labels:
return
issues = u.get_repo(repo_name).get_issues(labels=labels.get("label_list", []))
parse_func = make_base_issues_comments_str
# only Cook now, if one more, refactor it
if issue_label_name == "Cook":
parse_func = make_cook_issue_table
comment_str = parse_func(me, issues)
comments_name = labels.get("comment_name", "")
else:
# from 2021 just for me(yihong0618), if you want to use you can delete the lines below
# if you are not me change here
now_year = datetime.now().year
since = datetime(now_year, 1, 1)
issues = u.get_repo(MY_BLOG_REPO).get_issues(since=since, creator=me)
comment_str = make_blog_issues_str(since, issues)
comments_name = "my_blog"
replace_readme_comments("README.md", comment_str, comments_name)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("github_token", help="github_token")
parser.add_argument("repo_name", help="repo_name")
parser.add_argument(
"--issue_number", help="issue_number", default=None, required=False
)
parser.add_argument(
"--issue_label_name", help="issue_label_name", default=None, required=False
)
options = parser.parse_args()
main(
options.github_token,
options.repo_name,
options.issue_number,
options.issue_label_name,
)