-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants.py
63 lines (49 loc) · 1.62 KB
/
constants.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import winreg
DOWNLOAD_PATH = ""
FOLDERS_TO_CREATE = {
"Images": "jpg jpeg png gif bmp svg tiff heic",
"Survey Scans": "pdf",
"Compressed": "zip rar 7z tar gz",
"Misc": "*",
"Word Docs": "doc docx",
"PDFs": "pdf",
"CAD Files": "dwg dxf ini bak dwl dwl2",
"ASCII Files": "asc",
"Python Files": "py pyw ipynb json",
}
def get_download_path() -> str:
"""
Returns the default dowloads path for windows.
Args:
None
Returns:
str: The default downloads path for windows.
"""
if os.name == "nt":
sub_key = (
r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
)
downloads_guid = "{374DE290-123F-4565-9164-39C4925E467B}"
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key) as key:
location = winreg.QueryValueEx(key, downloads_guid)[0]
return location
return os.path.join(os.path.expanduser("~"), "Downloads")
def create_required_folders(
download_path: str, folders_to_create: dict
) -> None:
"""
Creates the destination folder if it doesn't exist.
Args:
download_path (str): The path to the downloads folder.
folders_to_create (dict): A dictionary of folders to create.
Returns:
None
"""
if not os.path.exists(download_path):
os.makedirs(download_path)
for folder in folders_to_create.keys():
if not os.path.exists(os.path.join(download_path, folder)):
os.mkdir(os.path.join(download_path, folder))
DOWNLOAD_PATH = get_download_path()
create_required_folders(DOWNLOAD_PATH, FOLDERS_TO_CREATE)