-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_company.py
163 lines (132 loc) · 4.84 KB
/
add_company.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
"""
This script adds company directly to the list
"""
# import yaml
def get_repo_from_url(url):
"""
Given a url, return the repository name.
:param url: the url of the repo
:return: The repo name.
"""
idx = url.find(".com/")
return url[idx + len(".com/") :].strip("/")
def create_alternatives_md(names, links):
"""
Create a markdown string of the form:
[name1](link1), [name2](link2), ...
:param names: A list of alternative names for the image
:param links: A list of links to the alternative versions of the file
:return: A string of the form:
"""
return ", ".join(
(f"""[{name.strip()}]({link.strip()})""" for name, link in zip(names, links))
)
def create_shield_link(gh_link):
return "https://img.shields.io/github/stars/{repo}?style=social".format(
repo=get_repo_from_url(gh_link)
).strip()
def create_new_line(
category, company_name, description, link, gh_link, alts_names, alts_links
):
return "{}|{}|{}|{}|{}|\n".format(
category.strip(),
f"[{company_name.strip()}]({link.strip()})",
description.strip(),
f'<a href={gh_link.strip()}><img src="{create_shield_link(gh_link)}" width=150/></a>',
create_alternatives_md(alts_names, alts_links),
)
def add_new_company(
category, company_name, description, link, gh_link, alts_names, alts_links
):
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)
find_name = lambda x: x[x.index("[") + 1 : x.index("]")].strip()
find_cat = lambda x: x[: x.index("|")].strip()
categories = [(find_cat(x), find_name(x)) for x in all[idx + 2 : idx_end - 1]]
search_tup = (category.strip(), company_name.strip())
insert_idx = -1
for i, tup in enumerate(reversed(categories)):
if search_tup == tup:
return "This entry already exists"
elif search_tup > tup:
print(search_tup, tup)
insert_idx = len(categories) - i
break
all.insert(
insert_idx + idx + 2,
create_new_line(
category, company_name, description, link, gh_link, alts_names, alts_links
),
)
# file_name = "_".join(company_name.split(" "))
# with open(f"submissions/{file_name}.yaml", "w") as file:
# yaml.dump(
# dict(
# category=category,
# company_name=company_name,
# description=description,
# link=link,
# gh_link=gh_link,
# alts_names=alts_names,
# alts_links=alts_links,
# ),
# file,
# default_flow_style=False,
# )
with open("README.md", "w", encoding="utf-8") as f:
f.writelines(all)
return "ok, added!"
def add_company_from_command_line():
count = 0
args = dict()
while True:
if count == 0:
args["company_name"] = input("Enter the company name.\n(e.g Metabase)\n: ")
print("-" * 100)
count += 1
elif count == 1:
args["category"] = input(
"Enter category of the company. May be an existing or a new one.\n(e.g Business Intelligence)\n: "
)
print("-" * 100)
count += 1
elif count == 2:
args["description"] = input(
"Description of the company.\nKeep it short and simple (use one line)\n: "
)
print("-" * 100)
count += 1
elif count == 3:
args["link"] = input(
"""Url to the company's website.\n(e.g https://www.metabase.com/)\n: """
)
print("-" * 100)
count += 1
elif count == 4:
args["gh_link"] = input(
""""Url of the product's github repo.\n(e.g https://github.com/metabase/metabase)\n: """
)
print("-" * 100)
count += 1
elif count == 5:
args["alts_names"] = input(
"""Names of the company's well-known SaaS competitors.\n(e.g for Metabase: PowerBI, DataStudio, Tableau)\n: """
).split(",")
print("-" * 100)
count += 1
elif count == 6:
args["alts_links"] = input(
"Links to the corresponding SaaS competitors.\n(e.g for Metabase: https://powerbi.microsoft.com/, https://datastudio.google.com/, https://www.tableau.com/)\n: "
).split(",")
print("-" * 100)
count += 1
else:
result = add_new_company(**args)
print(result)
break
if __name__ == "__main__":
add_company_from_command_line()