-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess_3.py
49 lines (32 loc) · 1.16 KB
/
preprocess_3.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
41
42
43
44
45
46
47
48
49
import json
import sys
sys.path.insert(
1, "C:/Users/Yaelg/Google Drive/National_Library/Python/VC_Preprocessing"
)
from VC_collections.authorities import *
def extract_dictionary_from_conf(file):
with open(file, encoding="utf8") as json_file:
file_data = json.load(json_file)
print("\n".join([f"{key} :{val}" for key, val in file_data.items()]))
print("\n")
return file_data
def search_for_file_with_extention(file_extention: str, directory: Path) -> list:
"""
:param file_extention:
:param directory:
:return: list of file paths with the desired extention
"""
file_list = list()
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(file_extention):
print(os.path.join(root, file))
file_info = extract_dictionary_from_conf(os.path.join(root, file))
file_list.append(os.path.join(root, file))
return file_list
def main():
folder_path = Path().cwd()
path_to_search = folder_path.parents[1]
file_list = search_for_file_with_extention("conf", path_to_search)
if __name__ == "__main__":
main()