mirror of
https://github.com/Kludex/awesome-fastapi-projects.git
synced 2024-11-24 04:21:09 +00:00
23 lines
516 B
Python
23 lines
516 B
Python
import re
|
|
import sys
|
|
|
|
filename_in = sys.argv[1]
|
|
filename_out = sys.argv[2]
|
|
file_in = open(filename_in, "r")
|
|
lines = file_in.readlines()
|
|
file_out = open(filename_out, "w")
|
|
|
|
imports = set()
|
|
|
|
for line in lines:
|
|
match1 = re.search(r"(from *(?!\.)(.+?)(?= |\.))", line)
|
|
match2 = re.search(r"(: *(import) (.+))", line)
|
|
if match1 is not None:
|
|
imports.add(match1.group(2))
|
|
if match2 is not None:
|
|
imports.add(match2.group(3))
|
|
|
|
|
|
for imp in sorted(list(imports)):
|
|
file_out.write(f"{imp}\n")
|