MCPcopy
hub / github.com/RunaCapital/awesome-oss-alternatives / add_new_company

Function add_new_company

add_company.py:52–108  ·  view source on GitHub ↗
(
    category, company_name, description, link, gh_link, alts_names, alts_links
)

Source from the content-addressed store, hash-verified

50
51
52def add_new_company(
53 category, company_name, description, link, gh_link, alts_names, alts_links
54):
55
56 with open("README.md", "r", encoding="utf-8") as f:
57 all = f.readlines()
58
59 table_start = "|Category|Company|Description|GitHub Stars|Alternative to|\n"
60 table_end = "<!-- END STARTUP LIST -->\n"
61
62 idx = all.index(table_start)
63 idx_end = all.index(table_end)
64
65 find_name = lambda x: x[x.index("[") + 1 : x.index("]")].strip()
66 find_cat = lambda x: x[: x.index("|")].strip()
67
68 categories = [(find_cat(x), find_name(x)) for x in all[idx + 2 : idx_end - 1]]
69
70 search_tup = (category.strip(), company_name.strip())
71
72 insert_idx = -1
73
74 for i, tup in enumerate(reversed(categories)):
75 if search_tup == tup:
76 return "This entry already exists"
77 elif search_tup > tup:
78 print(search_tup, tup)
79 insert_idx = len(categories) - i
80 break
81
82 all.insert(
83 insert_idx + idx + 2,
84 create_new_line(
85 category, company_name, description, link, gh_link, alts_names, alts_links
86 ),
87 )
88
89 # file_name = "_".join(company_name.split(" "))
90 # with open(f"submissions/{file_name}.yaml", "w") as file:
91 # yaml.dump(
92 # dict(
93 # category=category,
94 # company_name=company_name,
95 # description=description,
96 # link=link,
97 # gh_link=gh_link,
98 # alts_names=alts_names,
99 # alts_links=alts_links,
100 # ),
101 # file,
102 # default_flow_style=False,
103 # )
104
105 with open("README.md", "w", encoding="utf-8") as f:
106 f.writelines(all)
107
108 return "ok, added!"
109

Callers 2

build_listFunction · 0.90

Calls 1

create_new_lineFunction · 0.85

Tested by

no test coverage detected