-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
83 lines (62 loc) · 2.78 KB
/
helper.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
78
79
80
81
82
import os
from configparser import ConfigParser
from os import listdir
import gi
gi.require_version("Notify", "0.7")
from gi.repository import Notify, GdkPixbuf
class Helper(object):
def get_config(self):
config_file_path = os.path.dirname(os.path.realpath(__file__)) + '/config.ini'
if not os.path.exists(config_file_path):
return self.check_config(None)
config_reader = ConfigParser()
config_reader.read(config_file_path)
config = {}
config['wallpapers_directory'] = config_reader.get('settings', 'wallpapers_directory')
config['refresh_rate'] = config_reader.get('settings', 'refresh_rate')
config['subs'] = config_reader.get('settings', 'subs')
config['only_local'] = config_reader.get('settings', 'only_local')
config['over_18'] = config_reader.get('settings', 'allow_nsfw')
if not config['subs'] == "":
config['subs'] = config['subs'].split(',')
return self.check_config(config)
def check_config(self, config):
if config is None:
config = {}
config['wallpapers_directory'] = '~/Pictures/RedditWallpapers/'
config['refresh_rate'] = 120
config['subs'] = ['wallpapers']
config['only_local'] = False
config['over_18'] = False
config['wallpapers_directory'] = config['wallpapers_directory'].replace('~', os.path.expanduser("~"))
os.system("mkdir -p " + config['wallpapers_directory'])
if len(config['subs']) <= 0:
config['subs'] = ['wallpapers']
if not str(config['refresh_rate']).isdigit():
config['refresh_rate'] = 120
if config['only_local'] == '':
config['only_local'] = False
if config['over_18'] == '':
config['over_18'] = False
return config
def set_wallpaper(self, image):
config = self.get_config()
print('loading new wallpaper' + image)
os.system("gsettings set org.gnome.desktop.background picture-uri file://{}/{}".format(config['wallpapers_directory'], image))
self.send_notifaction()
def send_notifaction(self):
Notify.init("Wallpaper Changer")
notification = Notify.Notification.new(
'New wallpaper has been set!',
#'this is the body',
)
image = GdkPixbuf.Pixbuf.new_from_file(os.path.dirname(os.path.realpath(__file__)) + '/alien.png')
notification.set_image_from_pixbuf(image)
notification.show()
def clean_up(self):
config = self.get_config()
all_files = listdir(config['wallpapers_directory'])
for image in all_files:
file = config['wallpapers_directory'] + image
if os.stat(file).st_size <= 503:
os.remove(file)