-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
executable file
·82 lines (66 loc) · 1.86 KB
/
generate.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
#!/usr/bin/env python
from datetime import datetime
import requests
import yaml
API_URL = "https://api.github.com/orgs/esp-rs/repos"
INDEX_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Repo activity digests for esp-rs</title>
<style>
body {
font-family: sans-serif;
max-width: 60em;
margin: auto;
}
ul {
padding-left: 0;
list-style-type: none;
}
li {
margin-top: 0.5em;
}
a {
color: inherit;
}
a:hover {
text-decoration: none;
color: #0969da;
}
</style>
</head>
<body>
<h1>Repo activity digests for esp-rs</h1>
<ul>%s</ul>
</body>
</html>
"""
def main():
def query_org_repos():
r = requests.get(API_URL, params={"per_page": 100})
urls = [
j["html_url"] for j in r.json() if not j["private"] and not j["archived"]
]
return sorted(urls)
def build_digest(repo):
name = repo.split("/")[-1]
return {"digest": f"{name}.html", "since": "1 week", "items": [repo]}
def build_list_item(repo):
name = repo.split("/")[-1]
return f'<li><a href="{name}.html">{name}</a></li>'
now = datetime.utcnow()
date = now.strftime("%Y-%m-%d")
time = now.strftime("%H:%M:%S")
repos = query_org_repos()
with open("config.yml", "w") as f:
f.write(f"# Generated on {date} at {time} UTC\n\n")
yaml.dump({"digests": [build_digest(repo) for repo in repos]}, f)
with open("index.html", "w") as f:
list_items = [build_list_item(repo) for repo in repos]
f.write(INDEX_TEMPLATE % "\n".join(list_items))
if __name__ == "__main__":
main()