-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_daily.py
84 lines (71 loc) · 2.57 KB
/
get_daily.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import argparse
from github import Github
from daily.config import (
LABEL_DAILY_DICT,
)
from daily.utils import replace_readme_comments
from daily import MY_STATUS_DICT_FROM_API, MY_STATUS_DICT_FROM_COMMENTS
MY_NUMBER_STAT_HEAD = (
"| Name | Status | Streak | Today? | \n | ---- | ---- | ---- | ---- |\n"
)
MY_NUMBER_STAT_TEMPLATE = "| {name} | {total} | {streak} | {today} |\n"
# this is a tricky -> [a, b][False] => [a] [a, b][True] => [b]
NO_OR_YES_LIST = ["NO", "YES"]
def make_stat_str(name, total_str, streak, today_check):
# format
return MY_NUMBER_STAT_TEMPLATE.format(
name=name,
total=total_str,
streak=streak,
today=NO_OR_YES_LIST[today_check],
)
def main(
login_dict,
github_token,
repo_name,
):
my_num_stat_str = MY_NUMBER_STAT_HEAD
# API STAT STR
for name, value_dict in MY_STATUS_DICT_FROM_API.items():
url = value_dict.get("url")
md_name = f"[{name}]({url})"
# maybe a better way?
total_data, streak, today_check = value_dict.get("daily_func")(
*login_dict.get(name, tuple())
)
total_data_str = str(total_data) + value_dict.get("unit_str", "")
my_num_stat_str += make_stat_str(md_name, total_data_str, streak, today_check)
u = Github(github_token)
# COMMENTS STAT STR
for name, value_dict in MY_STATUS_DICT_FROM_COMMENTS.items():
try:
labels, map_func, reduce_func = LABEL_DAILY_DICT.get(name)
except:
# tricky for mine
continue
func = value_dict.get("daily_func")
if not func:
break
total_data, streak, today_check, url = func(
u, repo_name, labels, map_func, reduce_func
)
name = f"[{name}]({url})"
total_data_str = str(total_data) + value_dict.get("unit_str", "")
my_num_stat_str += make_stat_str(name, total_data_str, streak, today_check)
replace_readme_comments("README.md", my_num_stat_str, "my_number")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("duolingo_user_name", help="duolingo_user_name")
parser.add_argument("duolingo_password", help="duolingo_password")
parser.add_argument("github_token", help="github_token")
parser.add_argument("repo_name", help="repo_name")
options = parser.parse_args()
# add more login auth info here
login_auth_dict = {
"多邻国": (options.duolingo_user_name, options.duolingo_password),
}
main(
login_auth_dict,
options.github_token,
options.repo_name,
)