forked from tuna/mirror-web
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gen_desc.py
executable file
·46 lines (37 loc) · 915 Bytes
/
gen_desc.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
#!/usr/bin/env python3
import json
import urllib.request
from collections import OrderedDict
mirrordsync = json.loads(
urllib.request
.urlopen("http://mirrors.njupt.edu.cn/mirrordsync.json")
.read()
.decode('utf-8')
)
mirrors = list({t for t in mirrordsync})
mirrors.sort()
with open('_data/mirror_desc.json') as f:
descriptions = json.load(f)
descriptions = {
x['name']: x['desc'] for x in descriptions
}
for m in mirrors:
if m not in descriptions:
descriptions[m] = ""
descriptions = sorted(
[
OrderedDict([('name', name), ('desc', desc)])
for name, desc in descriptions.items()
],
key=lambda x: x['name']
)
content = (
json
.dumps(descriptions, indent=2)
.encode('utf-8')
.decode('unicode-escape')
.encode('utf-8')
)
with open('_data/mirror_desc.json', 'wb') as f:
f.write(content)
# vim: ts=4 sw=4 sts=4 expandtab