-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallpaperchanger.py
More file actions
executable file
·97 lines (79 loc) · 2.68 KB
/
wallpaperchanger.py
File metadata and controls
executable file
·97 lines (79 loc) · 2.68 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
"""
Author Milis Konecna <milis.konecna@gmail.com>
PURPOSE
change wallpaper of my fedora desktop
learn python scripting
USAGE
python scratch_13.py --dir ~/Pictures/
see --help
setup in fedora:
crontab -e
# run it each 30 minutes
crontab -l
*/30 * * * * /home/miluska/test/wallpaperchanger.py
"""
from optparse import OptionParser
import platform
import datetime
import random
import subprocess
import glob
class Main:
__parser = None
options = None
__params = None
__json_data = None
__list = []
__a = None
def __init__(self):
self.nicePicture = None
self.atLeastOnePicture = False
self.PictureList = []
self.__parser = OptionParser(usage="usage: %prog [options]",
version="%prog 1.0")
self.__parser.add_option("--dir",
dest="dir",
help="directory to eat",
default="/home")
(self.options, args) = self.__parser.parse_args()
def checkDirectory(self):
# create LIST from many file
# LIST is only jpg
# if directory is not accessible , write nice error
try:
# root_dir needs a trailing slash (i.e. /root/dir/)
for File in glob.iglob(self.options.dir + '/**/*.jpg', recursive=True):
self.PictureList.append(File)
except Exception as e:
print("Directory is not accessible;", e)
exit()
def selectPicture(self):
try:
self.nicePicture = random.choice(self.PictureList)
print(self.nicePicture)
except Exception as e:
print("Not any image found;", e)
exit()
def setFedoraBackgroung(self):
# run bash command, the right cmd for changing wallpaper should be:
# gsettings set org.gnome.desktop.background picture-options 'center'
# gsettings set org.gnome.desktop.background picture-uri "${URI}"
# subprocess.run(["gsettings", "set", "org.gnome.desktop.background", "picture-options","'center'"])
result = subprocess.run(["gsettings", "set", "org.gnome.desktop.background", "picture-uri", self.nicePicture])
# print(result.returncode)
if result.returncode == 0:
print('Wallpaper is there')
else:
print('gsettings command failed')
# READ Main class
getter = Main()
try:
print('python version', platform.python_version())
print(datetime.datetime.now())
getter.checkDirectory()
getter.selectPicture()
getter.setFedoraBackgroung()
# be able to ctrl+c if it stacks
except KeyboardInterrupt:
print('\nStopped by user')