-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallpaperchanger.py
55 lines (48 loc) · 1.55 KB
/
wallpaperchanger.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
#!/usr/bin/env python3
"""wallpaperchanger.py - simple wallpaper changer.
Simple script to download top wallpaper from
/r/wallpaper and set it as desktop wallpaper
in LXDE & XFCE
for praw install use this:
pip3 install --user praw==3.6.2
"""
import os
import shlex
import shutil
import subprocess
from datetime import date, datetime
from pathlib import Path
import praw
import requests
def main():
"""Where the shit happens XD"""
r = praw.Reddit(user_agent='Wallpaper Downloader')
url = next(r.get_subreddit('earthporn').get_top_from_day(limit=1)).url
req = requests.get(url, stream=True)
directory = Path(os.getenv("HOME") + "/Pictures/Wallpapers/")
if not directory.exists():
directory.mkdir()
current_time = date.isoformat(datetime.now())
directory = directory / os.path.basename(current_time)
with open(str(directory), 'wb') as f:
shutil.copyfileobj(req.raw, f)
output = subprocess.run(
"ls /usr/bin/*session",
shell=True,
stdout=subprocess.PIPE,
universal_newlines=True
)
if 'lxsession' in output.stdout:
args = shlex.split(
"pcmanfm -w --set-wallpaper={}".format(str(directory))
)
elif 'xfce4-session' in output.stdout:
#check xfconf-query -c xfce4-desktop -p /backdrop -lv
args = shlex.split(
"xfconf-query -c xfce4-desktop -p " +
"/backdrop/screen0/monitor0/workspace0/last-image -s {}"
.format(str(directory))
)
subprocess.Popen(args)
if __name__ == '__main__':
main()