awesome-fastapi-projects/generate_table.py

43 lines
1.1 KiB
Python
Raw Normal View History

2020-07-09 22:43:36 +00:00
import json
from typing import List
2020-07-09 22:43:36 +00:00
from pytablewriter import MarkdownTableWriter
from stdlib_list import stdlib_list
2020-07-09 22:43:36 +00:00
2020-07-09 23:41:21 +00:00
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("_")
)
]
2020-07-09 23:41:21 +00:00
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:
2020-07-09 22:43:36 +00:00
data = json.load(json_file)
writer = MarkdownTableWriter()
writer.headers = ["Project", "Dependencies"]
writer.value_matrix = [
2020-07-09 23:47:51 +00:00
[format_with_link(project), ", ".join(filter_list(dependencies))]
for project, dependencies in data.items()
2020-07-09 23:41:21 +00:00
if (
len(filter_list(dependencies)) > 0
and len(filter_list(dependencies)) < 20
and project != ""
)
2020-07-09 22:43:36 +00:00
]
writer.write_table()