forked from int32bit/openstack-cheat-sheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_services_from_json_to_markdown.py
executable file
·33 lines (28 loc) · 1.23 KB
/
convert_services_from_json_to_markdown.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
#!/usr/bin/python3
#coding=utf-8
from collections import OrderedDict
import json
from pprint import pprint
JSON_FILE = 'openstack_services.json'
FIELDS = ["名称", "LOGO", "服务", "年龄", "部署率", "成熟度"]
def _convert_to_md_row(fields):
return '|' + '|'.join(fields) + '|'
with open(JSON_FILE) as f:
data = json.load(f)
for group in data['grouped_components']:
print("\n### %s\n" % group)
print(_convert_to_md_row(FIELDS))
print(_convert_to_md_row(['----'] * len(FIELDS)))
for service in data['grouped_components'][group]:
code_name = service['code_name']
description = service['description'] or '-'
name = "[%s](https://wiki.openstack.org/wiki/%s)" % (
code_name, code_name.split()[0])
service_name = service['name']
age = str(service['age']) + '年'
adoption = service['adoption'] + '%'
maturity_points = service['maturity_points'] + '/7'
logo = "![%s](https://www.openstack.org/software/images/mascots/%s.png)" % (
service['slug'], service['slug'])
print(_convert_to_md_row(
[name, logo, service_name, age, adoption, maturity_points]))