-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeautify.py
77 lines (61 loc) · 1.99 KB
/
beautify.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
import json
from pathlib import Path
from appdirs import AppDirs
import os
import sys
from time import sleep
print("""
▓▓▓▓▓▓▓▓▓▓
░▓ Author ▓ Abdullah <https://abdullah.today>
░▓▓▓▓▓▓▓▓▓▓
░░░░░░░░░░
""")
print("""
Usage:-
beautify <Path to wallpapers> <Duration>
""")
dirs = AppDirs('beautify', 'Abdullah')
def walls_path(path):
try:
with open(Path(dirs.user_config_dir)/'config', 'w+') as f:
d = {}
d['walls_dir'] = path
json.dump(d, f)
f.close()
except FileNotFoundError:
os.makedirs(dirs.user_config_dir)
walls_path(path)
def getting_ready():
try:
with open(Path(dirs.user_config_dir)/'config', 'r') as f:
fetch_data = json.load(f)
walls_dir = fetch_data.get('walls_dir')
return walls_dir
except FileNotFoundError:
return sys.exit(f"Please run {dirs.appname} with wallpapers path")
except (KeyError, json.decoder.JSONDecodeError):
os.remove(Path(dirs.user_config_dir)/'config')
return sys.exit(f"""
{dirs.appname} wasn't able to get correct data. Old configuration file
is removed. Please run {dirs.appname} with wallpapers path again.
""")
def start_it(duration=600):
wallpapers = os.listdir(getting_ready())
for i in range(len(wallpapers)):
wallpapers[i] = str(Path(getting_ready()).joinpath(wallpapers[i]))
while True:
for i in wallpapers:
os.system(f"feh --bg-scale '{i}'")
sleep(duration)
try:
if Path.is_dir(Path(sys.argv[1])):
walls_path(sys.argv[1])
getting_ready()
start_it(int(sys.argv[2]))
elif not Path.is_dir(Path(sys.argv[1])):
print(sys.argv[1] + " isn't a directory. Please enter path of a directory.")
except ValueError:
print("Please enter a digit for duration between wallpapers's changes")
except IndexError:
start_it()