-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
62 lines (50 loc) · 1.48 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
import json
import click
import httpx
import yaml
GH_INFO = {
"desc": "description",
"forks": None,
"issues": "open_issues_count",
"stars": "stargazers_count",
"watching": "subscribers_count",
}
@click.command()
@click.argument('kv')
def main(kv):
op = []
with open("repos.yml", "r") as f:
RYML = yaml.safe_load(f)
clfa = RYML["clf"]
for k, v in RYML["repos"].items():
repo = f'https://github.com/{v["user"]}/{k}'
rl = v.get("links", {})
links = {"repo": repo, **rl}
resp = httpx.get(f'https://api.github.com/repos/{v["user"]}/{k}').json()
clf = []
info = {}
for ghk, ghv in GH_INFO.items():
info[ghk] = resp[ghv if ghv else ghk]
if rl:
dll = rl.get("dl")
if dll:
links["dl"] = dll
else:
if v["release"]:
links["dl"] = f'{repo}/releases'
rclf = v.get("clf")
if rclf:
for ck, cv in rclf.items():
for cvi in cv:
clf.append(clfa[ck][cvi])
lt = [i.lower() for i in clf]
op.append({
"name": k,
"links": links,
"clf": clf,
"tags": [i for i in v.get("topics", []) + resp["topics"] if i.lower() not in lt],
**info
})
httpx.post(f'https://{kv}.whi-ne.workers.dev', json={"pirate_kings": json.dumps(op, indent=None)})
if __name__ == '__main__':
main()