Skip to content

Commit 8a1a5dd

Browse files
Updated and now everythings working even in apps
1 parent 7640dde commit 8a1a5dd

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

auto_download_cleaner.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,49 @@
44
import save as sv
55
import tray_icon as ti
66
import time as time
7+
import json
8+
def load_variables_from_json():
9+
dirname = os.path.dirname(__file__)
10+
filename = os.path.join(dirname, 'config.json')
11+
try:
12+
with open(filename, "r") as json_file:
13+
loaded_vars = json.load(json_file)
14+
except FileNotFoundError:
15+
# If the config file doesn't exist, return an empty dictionary
16+
return {}
17+
return loaded_vars
718
def move_file(main_directory, move_folder, filename):
19+
if move_folder is None:
20+
raise ValueError("Invalid move_folder: None")
21+
822
if not os.path.exists(move_folder):
923
os.makedirs(move_folder)
24+
1025
shutil.move(os.path.join(main_directory, filename), os.path.join(move_folder, filename))
1126
def check_file_extension(file_ext, mov_dir, filename):
1227
if filename.endswith(file_ext):
1328
time.sleep(1)
1429
move_file(main_directory=sv.get_default_download_folder(), move_folder=mov_dir, filename=filename)
1530
def main_stuff():
16-
loaded_vars = sv.load_variables_from_json()
31+
sv.main()
32+
loaded_vars = load_variables_from_json()
1733
print(loaded_vars)
1834
print(sv.get_default_download_folder())
19-
print(loaded_vars['DOCX'])
2035
print('Program started.')
2136
while var.run:
2237
for filename in os.listdir(sv.get_default_download_folder()):
2338
try:
24-
check_file_extension(".pdf", mov_dir=loaded_vars[var.PDF], filename=filename)
25-
check_file_extension(".docx", mov_dir=loaded_vars[var.DOCX], filename=filename)
26-
check_file_extension('.zip', mov_dir=loaded_vars[var.ZIP], filename=filename)
27-
check_file_extension(var.Image, mov_dir=loaded_vars[var.IMAGE], filename=filename)
28-
check_file_extension('.py', mov_dir=loaded_vars[var.Python], filename=filename)
29-
check_file_extension(var.Video, mov_dir=loaded_vars[var.VIDEO], filename=filename)
30-
check_file_extension(var.audio_formats, mov_dir=loaded_vars[var.MUSIC], filename=filename)
31-
check_file_extension('.torrent', mov_dir=loaded_vars[var.Torrent], filename=filename)
39+
check_file_extension(".pdf", mov_dir=loaded_vars.get(var.PDF), filename=filename)
40+
check_file_extension(".docx", mov_dir=loaded_vars.get(var.DOCX), filename=filename)
41+
check_file_extension('.zip', mov_dir=loaded_vars.get(var.ZIP), filename=filename)
42+
check_file_extension(var.Image, mov_dir=loaded_vars.get(var.IMAGE), filename=filename)
43+
check_file_extension('.py', mov_dir=loaded_vars.get(var.Python), filename=filename)
44+
check_file_extension(var.Video, mov_dir=loaded_vars.get(var.VIDEO), filename=filename)
45+
check_file_extension(var.audio_formats,mov_dir=loaded_vars.get(var.MUSIC), filename=filename)
46+
check_file_extension('.torrent', mov_dir=loaded_vars.get(var.Torrent), filename=filename)
3247
except PermissionError:
3348
continue
3449
if __name__ == "__main__":
35-
sv.main()
50+
3651
ti.start()
3752
main_stuff()

save.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ def create_default_directories():
5050
def save_variables_to_json(vars_dict):
5151
with open("config.json", "w") as json_file:
5252
json.dump(vars_dict, json_file, indent=4)
53-
def load_variables_from_json():
54-
dirname = os.path.dirname(__file__)
55-
filename = os.path.join(dirname, 'config.json')
56-
try:
57-
with open(filename, "r") as json_file:
58-
loaded_vars = json.load(json_file)
59-
except FileNotFoundError:
60-
# If the config file doesn't exist, return an empty dictionary
61-
return {}
62-
return loaded_vars
53+
6354
def main():
6455
username = getpass.getuser()
6556
# Create default directories for different file types

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# fine tuning.
66
build_options = {'packages': ['os','getpass'], 'excludes': [],'build_exe': 'build_windows','include_files':['icon.ico']}
77

8-
base = "Console"
8+
base = 'Win32GUI' if sys.platform=='win32' else None
99

1010
executables = [
11-
Executable('auto_downloader_clearner.py', base=base, target_name = 'Auto-Download-Cleanup',icon='icon.ico')
11+
Executable('auto_download_cleaner.py', base=base, target_name = 'Auto Download Cleanup',icon='icon.ico')
1212
]
1313

1414
setup(name='Auto-Download-Cleanup',

0 commit comments

Comments
 (0)