-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupdate_md.py
131 lines (79 loc) · 2.89 KB
/
update_md.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
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
#
# Denes Turei <[email protected]>
# Saez Lab 2025
#
import pathlib as pl
import yaml
NCOL = 4
ROOT = pl.Path(__file__).parent.parent
IN_RESOURCES = ROOT / 'src' / 'resources.yaml'
IN_README_MAIN = ROOT / 'src'/ 'README.main.md'
IN_README_FOOT = ROOT / 'src'/ 'README.foot.md'
OUT = ROOT / 'README.md'
LOGOS = ROOT / 'logos'
URL_STEM = 'https://raw.githubusercontent.com/saezlab/.github/main/profile'
URL_ICONS = f'{URL_STEM}/icons'
URL_LOGOS = f'{URL_STEM}/logos'
def main():
with open(IN_RESOURCES) as fp:
resources = yaml.load(fp, Loader = yaml.SafeLoader)
names = resources['order']
resources = resources['resources']
with open(IN_README_MAIN) as fp:
readme = [fp.read() + '\n']
names = [n for n in names if n in resources]
names = names + [None] * (len(names) % NCOL)
for i in range(len(names) // NCOL):
logos = ['']
titles = ['']
links = ['']
for j in range(NCOL):
name = names[i * NCOL + j]
if name:
res = resources[name]
l = dict(res['links'])
for key in ('main', 'home', 'python', 'r'):
if main_url := l.get(key):
break
the_logo = f' **{name}** '
for ext in ('svg', 'png', 'jpeg', 'jpg'):
logo = f'{name.lower().replace("+", "plus")}.{ext}'
if (LOGOS / logo).exists():
the_logo = (
f' [<img alt="{name}" src="{URL_LOGOS}/{logo}"'
f' width="200"/>]({main_url}) '
)
break
logos.append(the_logo)
titles.append(f' **{name}** {res["main"]} ')
the_links = []
for typ, url in res['links']:
if typ == 'main':
continue
icon, *pkg = typ.split(':')
pkg = f'<sub><sup> {pkg[0]}</sup></sub>' if pkg else ''
the_links.append(
f'[<img src="{URL_ICONS}/{icon}.svg" '
f'height="16">{pkg}]({url})'
)
print(name)
links.append(' ' + ' '.join(the_links) + ' ')
else:
logos.append('')
titles.append('')
links.append('')
logos.append('')
titles.append('')
links.append('')
readme.append('|'.join(logos))
if i == 0:
readme.append('|' + ' --- |' * NCOL)
readme.append('|'.join(titles))
readme.append('|'.join(links))
with open(IN_README_FOOT) as fp:
readme.append('\n' + fp.read())
with open(OUT, 'w') as fp:
fp.write('\n'.join(readme))
if __name__ == '__main__':
main()