forked from Kludex/awesome-fastapi-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_table.py
40 lines (34 loc) · 1.13 KB
/
generate_table.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
from typing import List
import json
from pytablewriter import MarkdownTableWriter
from stdlib_list import stdlib_list
NATIVE = ["fastapi", "starlette", "pydantic", "typing", "uvicorn", "app"]
def filter_list(dependencies: List[str]) -> List[str]:
return [
dependency
for dependency in dependencies
if not (
dependency in NATIVE
or dependency in stdlib_list("3.8")
or dependency.startswith("_")
)
]
def format_with_link(project: str) -> str:
links = open("unique_links.txt", "r")
for link in links.readlines():
if project in link:
return f"[{project}]({link})"
with open("results.json") as json_file:
data = json.load(json_file)
writer = MarkdownTableWriter()
writer.headers = ["Project", "Dependencies"]
writer.value_matrix = [
[format_with_link(project), ", ".join(filter_list(dependencies))]
for project, dependencies in data.items()
if (
len(filter_list(dependencies)) > 0
and len(filter_list(dependencies)) < 20
and project != ""
)
]
writer.write_table()