2020-07-09 22:20:38 +00:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
from typing import Dict, Union
|
|
|
|
|
|
|
|
f_in = open("imports.txt", "r")
|
|
|
|
|
|
|
|
mp: Dict[str, Union[set, list]] = {}
|
|
|
|
|
|
|
|
for line in f_in.readlines():
|
|
|
|
try:
|
2020-07-09 23:15:08 +00:00
|
|
|
rep_name = line.split("/")[1]
|
2020-07-09 22:20:38 +00:00
|
|
|
except IndexError:
|
|
|
|
rep_name = ""
|
|
|
|
mp[rep_name] = mp.get(rep_name, set())
|
2020-07-09 23:15:08 +00:00
|
|
|
result = re.search(r"from (\w+)[\.\w+]*|:[ ]*import (\w*)\n", line)
|
2020-07-09 22:20:38 +00:00
|
|
|
if result:
|
|
|
|
if result.group(1):
|
|
|
|
mp[rep_name].add(result.group(1))
|
|
|
|
if result.group(2):
|
|
|
|
mp[rep_name].add(result.group(2))
|
|
|
|
|
|
|
|
for key in mp:
|
|
|
|
mp[key] = list(mp[key])
|
|
|
|
|
2020-07-09 23:15:08 +00:00
|
|
|
with open("results.json", "w") as f:
|
2020-07-09 22:20:38 +00:00
|
|
|
json.dump(mp, f, sort_keys=True, indent=2)
|
|
|
|
|
|
|
|
print(len(mp))
|
|
|
|
f_in.close()
|