-
Notifications
You must be signed in to change notification settings - Fork 1
/
Utils.py
69 lines (54 loc) · 2.36 KB
/
Utils.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
import os
import json
import shutil
import requests
import subprocess
import gi
gi.require_version("GLib", "2.0")
gi.require_version("Gio", "2.0")
from gi.repository import GLib,Gio
class Utils():
def __init__(self,*args,**kwargs):
super().__init__(self,*args,**kwargs)
def send_notification(self,text):
subprocess.run(['notify-send','Mergin', f'"{text}"'])
def download_bing_wallpaper(self):
jsonData = requests.get("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US")
wallpaperData = json.loads(jsonData.text)
wallpaperLink = wallpaperData["images"][0]["url"][1:]
wallpaperName = "BING-" + wallpaperData["images"][0]["startdate"] + ".jpg"
wallpaperLink = wallpaperLink.split("&")[0]
fullWallpaperLink = "https://www.bing.com/" + wallpaperLink
#Downloading wallpaper
subprocess.run(["wget" , fullWallpaperLink])
shutil.move(wallpaperLink , "./src/"+wallpaperName)
return wallpaperName
def list_wallpapers():
return os.listdir("./src")
def set_wallpaper(self,wallpaper_name):
path = f'file://{os.getcwd()}/src/{wallpaper_name}'
mode_scheme = "org.gnome.desktop.interface"
background_scheme = "org.gnome.desktop.background"
mode_key = "color-scheme"
background_key = "picture-uri"
background_key_dark = "picture-uri-dark"
mode_settings = Gio.Settings(mode_scheme)
background_settings = Gio.Settings(background_scheme)
scheme = mode_settings.get_string(mode_key)
if "dark" in scheme:
background_settings.set_string(background_key_dark,path)
else:
background_settings.set_string(background_key,path)
def get_current_wallpaper():
mode_scheme = "org.gnome.desktop.interface"
background_scheme = "org.gnome.desktop.background"
mode_key = "color-scheme"
background_key = "picture-uri"
background_key_dark = "picture-uri-dark"
mode_settings = Gio.Settings(mode_scheme)
background_settings = Gio.Settings(background_scheme)
scheme = mode_settings.get_string(mode_key)
if "dark" in scheme:
return background_settings.get_string(background_key_dark)
else:
background_settings.get_string(background_key)