-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
123 lines (96 loc) · 3.35 KB
/
run.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from configparser import ConfigParser
from src.display import TrafficProgress
import time
from typing import Dict
from rich.console import Console
from rich.live import Live
from rich.panel import Panel
from src.dataclass import *
from src.gitapi import APIRegister, RequestHandler
from src.record import Record
def main(args):
# * setup traffic
config = ConfigParser()
config.read_file(open(args.config))
username = config.get("github", "username")
token = config.get("github", "token")
instanceRecord = Record()
instanceRQ = RequestHandler(username=username, token=token, register=APIRegister())
# ! might display on header panel
userInfo = instanceRQ(
call="userInfo",
args={},
)
# * init from here
repos = instanceRQ(
call="repos",
args={"username": username},
)
assert isinstance(repos, list)
instanceConsole = TrafficProgress(
numRepos=len(repos),
follower=userInfo.followers, # type:ignore
following=userInfo.following, # type:ignore
)
instanceConsole.progressTotal.console.print(
Panel(
f"[bold blue] Github-Traffic v0.2.0",
border_style="violet",
padding=1,
),
)
# * start fetch
with Live(
instanceConsole.progressTable,
refresh_per_second=144,
console=Console(),
):
for repo in repos:
assert isinstance(repo, ntRepo)
instanceConsole.UpdateRepoDescription(repo.name)
# ? basic info
instanceConsole.UpdateStatDescription("info")
instanceRecord.info.update({repo.name: repo})
instanceConsole.StepTotal()
instanceConsole.StepStat()
# ? taks referrals
ret = instanceRQ(
call="referrers",
args={"repo": repo.name},
)
instanceConsole.UpdateStatDescription("referrers")
instanceRecord.referrals.update({repo.name: ret}) # type:ignore
instanceConsole.StepTotal()
instanceConsole.StepStat()
# ? taks paths
ret = instanceRQ(
call="paths",
args={"repo": repo.name},
)
instanceConsole.UpdateStatDescription("paths")
instanceRecord.paths.update({repo.name: ret}) # type:ignore
instanceConsole.StepTotal()
instanceConsole.StepStat()
# ? taks views
ret = instanceRQ(
call="views",
args={"repo": repo.name},
)
instanceConsole.UpdateStatDescription("views")
instanceRecord.views.update({repo.name: ret}) # type:ignore
instanceConsole.StepTotal()
instanceConsole.StepStat()
# ? taks clones
ret = instanceRQ(
call="clones",
args={"repo": repo.name},
)
instanceConsole.UpdateStatDescription("clones")
instanceRecord.clones.update({repo.name: ret}) # type:ignore
instanceConsole.StepTotal()
instanceConsole.StepStat()
instanceConsole.ResetStatProgress()
instanceConsole.StepRepo()
instanceConsole.UpdateRepoDescription("Fetched")
instanceConsole.CompleteStat()
Console().print(instanceRecord)