forked from RunaCapital/awesome-oss-alternatives
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_yamls.py
46 lines (37 loc) · 1.28 KB
/
create_yamls.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
"""
This script create yamls from README
"""
import yaml
def read_readme():
with open("README.md", "r", encoding="utf-8") as f:
all = f.readlines()
table_start = "|Category|Company|Description|GitHub Stars|Alternative to|\n"
table_end = "<!-- END STARTUP LIST -->\n"
idx = all.index(table_start)
idx_end = all.index(table_end)
return all[idx + 2 : idx_end - 1]
def parse_line(line: str):
arr = line.split("|")
category = arr[0]
name = arr[1].split("]")[0][1:]
website = arr[1].split("]")[1][1:-1]
description = arr[2]
github = arr[3].split(">")[0].split("href=")[1]
alts = list(map(lambda x: x.strip().split("]")[0][1:], arr[4].split(",")))
alts_links = list(map(lambda x: x.strip().split("](")[1][:-1], arr[4].split(",")))
return dict(
category=category,
company_name=name,
link=website,
description=description,
gh_link=github,
alts_names=alts,
alts_links=alts_links,
)
if __name__ == "__main__":
arr = read_readme()
for line in arr:
obj = parse_line(line)
file_name = "_".join(obj["company_name"].split(" "))
with open(f"submissions/{file_name}.yaml", "w") as file:
yaml.dump(obj, file, default_flow_style=False)