-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathgithub_loader.py
More file actions
56 lines (47 loc) · 1.73 KB
/
github_loader.py
File metadata and controls
56 lines (47 loc) · 1.73 KB
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
from threading import Thread
import requests
from github_poster.html_parser import GitHubParser
from github_poster.loader.base_loader import BaseLoader, LoadError
from github_poster.loader.config import GITHUB_CONTRIBUCTIONS_URL
class GitHubLoader(BaseLoader):
track_color = "#9BE9A8"
unit = "cons"
def __init__(self, from_year, to_year, _type, **kwargs):
super().__init__(from_year, to_year, _type)
self.user_name = kwargs.get("github_user_name", "")
@classmethod
def add_loader_arguments(cls, parser, optional):
parser.add_argument(
"--github_user_name",
dest="github_user_name",
type=str,
required=optional,
help="",
)
def _make_one_year(self, y):
p = GitHubParser()
try:
r = requests.get(
GITHUB_CONTRIBUCTIONS_URL.format(
user_name=self.user_name,
start_day=f"{y}-01-01",
end_day=f"{y}-12-31",
)
)
self.number_by_date_dict.update(p.make_contribution_dict(r.text))
except Exception as e:
raise LoadError(f"Can not get GitHub contributions error: {str(e)}")
def make_track_dict(self):
thread_list = []
for y in self.year_list:
thread_list.append(Thread(target=self._make_one_year, args=(y,)))
for t in thread_list:
t.start()
for t in thread_list:
t.join()
for _, v in self.number_by_date_dict.items():
self.number_list.append(v)
def get_all_track_data(self):
self.make_track_dict()
self.make_special_number()
return self.number_by_date_dict, self.year_list