From 3b79dfe1fdeccb853dddfcf4d082b82bfa4f4710 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Wed, 19 Aug 2020 15:57:21 +0200 Subject: [PATCH 01/36] fixing some old material. Now requires to input credentials.json before anything else. --- change_wallpaper_reddit.py | 23 ++++++++++++++++------- credentials.json | 4 ++++ requirements.txt | 12 ++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 credentials.json diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 92f67bb..2f7a834 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -10,6 +10,7 @@ import requests import sys import time +import json from configparser import ConfigParser from io import StringIO from collections import defaultdict @@ -63,6 +64,7 @@ def add_to_ret(fun, name): except IOError as e: return default + config = load_config() @@ -107,8 +109,8 @@ def get_top_image(sub_reddit): elif ("imgur.com" in url) and ("/a/" not in url) and ("/gallery/" not in url): if url.endswith("/new"): url = url.rsplit("/", 1)[0] - id = url.rsplit("/", 1)[1].rsplit(".", 1)[0] - ret["url"] = "http://i.imgur.com/{id}.jpg".format(id=id) + id_toget = url.rsplit("/", 1)[1].rsplit(".", 1)[0] + ret["url"] = "http://i.imgur.com/{id}.jpg".format(id=id_toget) else: continue @@ -169,8 +171,14 @@ def detect_desktop_environment(): supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu", "i3"] + # Load credentials from credentials.json file + with open('./credentials.json') as f: + params = json.load(f) + # Python Reddit Api Wrapper - r = praw.Reddit(user_agent="Get top wallpaper from /r/{subreddit} by /u/ssimunic".format(subreddit=subreddit)) + r = praw.Reddit(client_id=params['client_id'], + client_secret=params['api_key'], + user_agent=f"Get top wallpaper from /r/{subreddit} by /u/ssimunic") # Get top image link image = get_top_image(r.subreddit(subreddit)) @@ -186,10 +194,11 @@ def detect_desktop_environment(): # Get home directory and location where image will be saved # (default location for Ubuntu is used) home_dir = os.path.expanduser("~") - save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{image_type}".format(home_dir=home_dir, save_dir=save_dir, - subreddit=subreddit, - id=image["id"], - image_type=image['type']) + save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{image_type}".format(home_dir=home_dir, + save_dir=save_dir, + subreddit=subreddit, + id=image["id"], + image_type=image['type']) if not os.path.isfile(save_location): # Create folders if they don't exist diff --git a/credentials.json b/credentials.json new file mode 100644 index 0000000..1214ed2 --- /dev/null +++ b/credentials.json @@ -0,0 +1,4 @@ +{ + "client_id": "XXXXXXXXX-XXXX", + "api_key": "XXXXXXXXXXXX_XXXXXX-XXXXXXX" +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index eb49937..200fbf5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -decorator==4.0.10 -future==0.15.2 -praw==5.4.0 -requests==2.10.0 -six==1.10.0 -update-checker==0.11 +decorator>4.0.10 +future>0.15.2 +praw>5.4.0 +requests>2.10.0 +six>1.10.0 +update-checker>0.11 From e103a767e17b4ca6cc56a97cf301d671649eb6d3 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Thu, 20 Aug 2020 17:05:18 +0200 Subject: [PATCH 02/36] updated README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c224a7..2f7b98a 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,11 @@ The rest is the same. Using script ======= +First, you'll need to configure the _credentials.json_ file with your personal Reddit API. +Your api_key will be the Reddit API secret and your client_id the first and smaller code: +![Reddit API](https://camo.githubusercontent.com/d53f92cd85d1279a239444acee25179e8e6d8bb5/687474703a2f2f692e696d6775722e636f6d2f65326b4f5231612e706e67) -Simply run: +Then, simply run: ``` python /home/silvio/Scripts/change_wallpaper_reddit.py ``` From 2118b07fde88e205521ebcc96a2bb23b500aa6a5 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Thu, 20 Aug 2020 17:05:55 +0200 Subject: [PATCH 03/36] updated README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2f7b98a..42526f7 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Using script ======= First, you'll need to configure the _credentials.json_ file with your personal Reddit API. Your api_key will be the Reddit API secret and your client_id the first and smaller code: + ![Reddit API](https://camo.githubusercontent.com/d53f92cd85d1279a239444acee25179e8e6d8bb5/687474703a2f2f692e696d6775722e636f6d2f65326b4f5231612e706e67) Then, simply run: From 3a73f128a73793c745a623d315cd9a2506dba2ad Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Thu, 20 Aug 2020 17:22:43 +0200 Subject: [PATCH 04/36] updated requirements.txt --- change_wallpaper_reddit.py | 11 ++++++----- requirements.txt | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 2f7a834..0330045 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -1,19 +1,20 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals + import argparse import ctypes +import json import os -import praw import platform import re -import requests import sys -import time -import json +from collections import defaultdict from configparser import ConfigParser from io import StringIO -from collections import defaultdict + +import praw +import requests if sys.version_info <= (2, 6): import commands as subprocess diff --git a/requirements.txt b/requirements.txt index 200fbf5..25d1f92 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -decorator>4.0.10 -future>0.15.2 -praw>5.4.0 -requests>2.10.0 -six>1.10.0 -update-checker>0.11 +decorator==4.4.2 +future==0.18.2 +praw==7.1.0 +requests==2.24.0 +six==1.15.0 +update-checker==0.18.0 From 556b5d74dc6f50691e6e3a851a9ba33a268dd590 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sat, 19 Sep 2020 11:36:26 +0200 Subject: [PATCH 05/36] fixed some typos --- change_wallpaper_reddit.py | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 0330045..241f547 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -24,7 +24,7 @@ def load_config(): default = defaultdict(str) - default["subreddit"] = "wallpapers" + default["subreddit"] = "wallpaper" default["nsfw"] = "False" default["time"] = "day" default["display"] = "0" @@ -33,14 +33,14 @@ def load_config(): config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") section_name = "root" try: - config = ConfigParser(default) + conf = ConfigParser(default) with open(config_path, "r") as stream: stream = StringIO("[{section_name}]\n{stream_read}".format(section_name=section_name, stream_read=stream.read())) if sys.version_info >= (3, 0): - config.read_file(stream) + conf.read_file(stream) else: - config.readfp(stream) + conf.read_file(stream) ret = {} @@ -48,17 +48,17 @@ def load_config(): def add_to_ret(fun, name): try: ret[name] = fun(section_name, name) - except ValueError as e: + except ValueError as e_code: err_str = "Error in config file. Variable '{}': {}. The default '{}' will be used." - # print sys.stderr >> err_str.format(name, str(e), default[name]) + # print sys.stderr >> err_str.format(name, str(e_code), default[name]) ret[name] = default[name] - add_to_ret(config.get, "subreddit") - add_to_ret(config.getboolean, "nsfw") - add_to_ret(config.getint, "display") - add_to_ret(config.get, "time") - add_to_ret(config.get, "output") + add_to_ret(conf.get, "subreddit") + add_to_ret(conf.getboolean, "nsfw") + add_to_ret(conf.getint, "display") + add_to_ret(conf.get, "time") + add_to_ret(conf.get, "output") return ret @@ -71,7 +71,7 @@ def add_to_ret(fun, name): def parse_args(): """parse args with argparse - :returns: args + :returns: arguments """ parser = argparse.ArgumentParser(description="Daily Reddit Wallpaper") parser.add_argument("-s", "--subreddit", type=str, default=config["subreddit"], @@ -84,8 +84,8 @@ def parse_args(): parser.add_argument("-o", "--output", type=str, default=config["output"], help="Set the outputfolder in the home directory to save the Wallpapers to.") - args = parser.parse_args() - return args + arguments = parser.parse_args() + return arguments def get_top_image(sub_reddit): @@ -179,13 +179,12 @@ def detect_desktop_environment(): # Python Reddit Api Wrapper r = praw.Reddit(client_id=params['client_id'], client_secret=params['api_key'], - user_agent=f"Get top wallpaper from /r/{subreddit} by /u/ssimunic") + user_agent=f"Get top wallpaper from /r/{subreddit}") # Get top image link image = get_top_image(r.subreddit(subreddit)) if "url" not in image: - sys.exit("Error: No suitable images were found, the program is now" \ - " exiting.") + sys.exit("Error: No suitable images were found, the program is now exiting.") # Request image response = requests.get(image["url"], allow_redirects=False) @@ -203,9 +202,9 @@ def detect_desktop_environment(): if not os.path.isfile(save_location): # Create folders if they don't exist - dir = os.path.dirname(save_location) - if not os.path.exists(dir): - os.makedirs(dir) + directory = os.path.dirname(save_location) + if not os.path.exists(directory): + os.makedirs(directory) # Write to disk with open(save_location, "wb") as fo: From c1e46c86b3dca55d18b3c27c8afded0b2b403dde Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sat, 19 Sep 2020 11:38:55 +0200 Subject: [PATCH 06/36] updated README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42526f7..cfd3fae 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Daily Reddit Wallpaper [![Build Status](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper) -This script changes your wallpaper to most upvoted image of the day on [/r/wallpapers](https://www.reddit.com/r/wallpapers/) or from any other subreddit. +This script changes your wallpaper to most upvoted image of the day on [/r/wallpaper](https://www.reddit.com/r/wallpaper/) or from any other subreddit. **Run it on startup for new wallpaper on every session.** From 3d115586cac1118b6cf75d01e0bbb23acd4914fa Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sat, 19 Sep 2020 11:44:08 +0200 Subject: [PATCH 07/36] updated travis tests --- .travis.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 86b5eac..76344fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,8 @@ language: python python: - "2.6" - "2.7" - - "3.2" - - "3.3" - - "3.4" - - "3.5" - - "3.5-dev" # 3.5 development branch - - "nightly" # currently points to 3.6-dev + - "3.6" + - "3.8" # command to install dependencies install: "pip install -r requirements.txt" # command to run tests From fcf2112abc1132d0e9d7dcc60bd2325d3875ed46 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sat, 19 Sep 2020 11:48:56 +0200 Subject: [PATCH 08/36] updated travis tests --- .travis.yml | 5 +++-- README.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76344fd..80322e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: python python: - - "2.6" - - "2.7" - "3.6" + - "3.7" - "3.8" + - "nightly" + - "pypy3" # command to install dependencies install: "pip install -r requirements.txt" # command to run tests diff --git a/README.md b/README.md index cfd3fae..5a2929b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Daily Reddit Wallpaper -[![Build Status](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper) +[![Build Status](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper) This script changes your wallpaper to most upvoted image of the day on [/r/wallpaper](https://www.reddit.com/r/wallpaper/) or from any other subreddit. From c8c95faa707998709668efafe78beec120a37a0e Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sat, 19 Sep 2020 11:52:11 +0200 Subject: [PATCH 09/36] updated travis tests, final. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a2929b..2b22e82 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Daily Reddit Wallpaper -[![Build Status](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/ssimunic/Daily-Reddit-Wallpaper) +[![Build Status](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper) This script changes your wallpaper to most upvoted image of the day on [/r/wallpaper](https://www.reddit.com/r/wallpaper/) or from any other subreddit. From 84a28579e9a41372043535fa870fcd7e9cd8de44 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sun, 20 Sep 2020 10:56:03 +0200 Subject: [PATCH 10/36] Changed pathing method for Windows --- change_wallpaper_reddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 241f547..67b8db9 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -173,7 +173,7 @@ def detect_desktop_environment(): supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu", "i3"] # Load credentials from credentials.json file - with open('./credentials.json') as f: + with open(os.path.dirname(os.path.realpath(sys.argv[0])) + '/credentials.json') as f: params = json.load(f) # Python Reddit Api Wrapper From 0dccbb4f6c2fb9d63059952478de6be15e4968aa Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Thu, 24 Dec 2020 23:20:00 +0000 Subject: [PATCH 11/36] Changed a little bit the Readme --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2b22e82..5f4b8ec 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This script changes your wallpaper to most upvoted image of the day on [/r/wallp Dependencies ======= -Make sure you have [Python](https://www.python.org/downloads/) installed and PATH variable set. +Make sure you have [Python3](https://www.python.org/downloads/) installed and PATH variable set. Ubuntu ------ @@ -25,6 +25,21 @@ You will need modules ```requests``` and ```praw``` installed, which are in requ pip install -r requirements.txt ``` +Arch +------ +If you don't have ```pip``` for Python: +``` +pacman -S python-pip +``` +or, with yay: +``` +yay -S python-pip +``` +Then just install the requirements.txt with: +``` +pip install -r requirements.txt +``` + Windows ------ Follow [this guide](https://pip.pypa.io/en/stable/installing/) to install ```pip``` and configure PATH variable. @@ -37,21 +52,21 @@ Your api_key will be the Reddit API secret and your client_id the first and smal ![Reddit API](https://camo.githubusercontent.com/d53f92cd85d1279a239444acee25179e8e6d8bb5/687474703a2f2f692e696d6775722e636f6d2f65326b4f5231612e706e67) -Then, simply run: +Then, in the current project folder, run: ``` -python /home/silvio/Scripts/change_wallpaper_reddit.py +python change_wallpaper_reddit.py ``` If you wanna use other subreddit, include argument with the subreddit name: ``` -python /home/silvio/Scripts/change_wallpaper_reddit.py --subreddit art +python change_wallpaper_reddit.py --subreddit art ``` If you don't want to change your wallpaper daily, you can use newest, hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: ```new```, ```hour```, ```week```, ```month```, ```year``` to the script. Example: ``` -python /home/silvio/Scripts/change_wallpaper_reddit.py --time week +python change_wallpaper_reddit.py --time week ``` NSFW images are disabled by default, to enable them add ```--nsfw```. From c07e42c213f0ea000716dbb64eac0e0705284bd7 Mon Sep 17 00:00:00 2001 From: teaqu Date: Wed, 17 Feb 2021 09:08:19 +0000 Subject: [PATCH 12/36] Sort posts (new, hot, top) --- .gitignore | 3 +++ README.md | 10 +++++++++- change_wallpaper_reddit.py | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 72364f9..b8f08ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,6 @@ ENV/ # Rope project settings .ropeproject + +# Intelij +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 5f4b8ec..8a39bd7 100644 --- a/README.md +++ b/README.md @@ -62,13 +62,20 @@ If you wanna use other subreddit, include argument with the subreddit name: python change_wallpaper_reddit.py --subreddit art ``` -If you don't want to change your wallpaper daily, you can use newest, hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: ```new```, ```hour```, ```week```, ```month```, ```year``` to the script. +If you don't want to change your wallpaper daily, you can use hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: ```hour```, ```week```, ```month```, ```year``` to the script. Example: ``` python change_wallpaper_reddit.py --time week ``` +If you want to choose which wallpaper appears, you can sort posts by adding the arguments: ```hot```, ```top```, ```new``` to the script. + +Example: +``` +python change_wallpaper_reddit.py --sort top +``` + NSFW images are disabled by default, to enable them add ```--nsfw```. On OS X, you can specify display number with option ```--display```. Use 0 for all display (default), 1 for main display and so on. @@ -132,4 +139,5 @@ Example of configuration file: ``` subreddit=art time=day +sort=top ``` diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 67b8db9..52ef455 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -29,6 +29,7 @@ def load_config(): default["time"] = "day" default["display"] = "0" default["output"] = "Pictures/Wallpapers" + default["sort"] = "hot" config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") section_name = "root" @@ -59,6 +60,7 @@ def add_to_ret(fun, name): add_to_ret(conf.getint, "display") add_to_ret(conf.get, "time") add_to_ret(conf.get, "output") + add_to_ret(conf.get, "sort") return ret @@ -77,12 +79,14 @@ def parse_args(): parser.add_argument("-s", "--subreddit", type=str, default=config["subreddit"], help="Example: art, getmotivated, wallpapers, ...") parser.add_argument("-t", "--time", type=str, default=config["time"], - help="Example: new, hour, day, week, month, year") + help="Example: hour, day, week, month, year") parser.add_argument("-n", "--nsfw", action='store_true', default=config["nsfw"], help="Enables NSFW tagged posts.") parser.add_argument("-d", "--display", type=int, default=config["display"], help="Desktop display number on OS X (0: all displays, 1: main display, etc") parser.add_argument("-o", "--output", type=str, default=config["output"], help="Set the outputfolder in the home directory to save the Wallpapers to.") + parser.add_argument("--sort", type=str, default=config["sort"], + help="Can be one of: hot, top, new.") arguments = parser.parse_args() return arguments @@ -93,8 +97,13 @@ def get_top_image(sub_reddit): :sub_reddit: name of the sub reddit :return: the image link """ - submissions = sub_reddit.new(limit=10) if args.time == "new" else sub_reddit.hot(params={"t": args.time}, - limit=10) + if args.sort == "top": + submissions = sub_reddit.top(args.time) + elif args.sort == "new": + submissions = sub_reddit.new(params={"t": args.time}, limit=10) + else: + submissions = sub_reddit.hot(params={"t": args.time}, limit=10) + for submission in submissions: ret = {"id": submission.id} if not args.nsfw and submission.over_18: From 6e71b327a57e4f1cb68aa13dc912c63a93fc9d91 Mon Sep 17 00:00:00 2001 From: teaqu Date: Wed, 17 Feb 2021 10:53:42 +0000 Subject: [PATCH 13/36] Remove nose --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80322e5..ca2cc2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,3 @@ python: - "pypy3" # command to install dependencies install: "pip install -r requirements.txt" -# command to run tests -script: nosetests From 71ceb9e8292b89d295e84df7d87463cabf05d059 Mon Sep 17 00:00:00 2001 From: teaqu Date: Wed, 17 Feb 2021 10:59:48 +0000 Subject: [PATCH 14/36] change to pytest --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index ca2cc2c..c4431fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,6 @@ python: - "pypy3" # command to install dependencies install: "pip install -r requirements.txt" +# command to run tests +script: + - pytest From cabb3830a7b89066e29e467b8ec7a10bbd1c6764 Mon Sep 17 00:00:00 2001 From: teaqu Date: Wed, 17 Feb 2021 11:10:41 +0000 Subject: [PATCH 15/36] change to nose2 --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c4431fe..044c89d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,4 @@ python: # command to install dependencies install: "pip install -r requirements.txt" # command to run tests -script: - - pytest +script: "nose2 -v" From 0f3134221df98d93439267061ee24550a59e1e6b Mon Sep 17 00:00:00 2001 From: teaqu Date: Wed, 17 Feb 2021 11:14:27 +0000 Subject: [PATCH 16/36] Add nose2 as a requirement. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 25d1f92..22f4980 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ praw==7.1.0 requests==2.24.0 six==1.15.0 update-checker==0.18.0 +nose2==0.10.0 From 699a24125abb11748925add51a47274a46ac745b Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Sun, 21 Feb 2021 10:33:24 +0100 Subject: [PATCH 17/36] Replaced useless nightly tests --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 044c89d..c04ba7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ python: - "3.6" - "3.7" - "3.8" - - "nightly" + - "3.9" - "pypy3" # command to install dependencies install: "pip install -r requirements.txt" From 415fb393612d60fc9340a54b2c572e96bb0baedb Mon Sep 17 00:00:00 2001 From: rahilshah10 <32785595+rahilshah10@users.noreply.github.com> Date: Sun, 11 Jul 2021 19:47:46 -0700 Subject: [PATCH 18/36] Add randomize in sort, limit on number of posts --- change_wallpaper_reddit.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 52ef455..8873fb5 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -9,6 +9,7 @@ import platform import re import sys +import random from collections import defaultdict from configparser import ConfigParser from io import StringIO @@ -25,11 +26,13 @@ def load_config(): default = defaultdict(str) default["subreddit"] = "wallpaper" - default["nsfw"] = "False" + default["nsfw"] = False default["time"] = "day" default["display"] = "0" default["output"] = "Pictures/Wallpapers" default["sort"] = "hot" + default["limit"] = 20 + default["random"] = False config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") section_name = "root" @@ -61,6 +64,8 @@ def add_to_ret(fun, name): add_to_ret(conf.get, "time") add_to_ret(conf.get, "output") add_to_ret(conf.get, "sort") + add_to_ret(conf.get, "limit") + add_to_ret(conf.get, "random") return ret @@ -87,6 +92,10 @@ def parse_args(): help="Set the outputfolder in the home directory to save the Wallpapers to.") parser.add_argument("--sort", type=str, default=config["sort"], help="Can be one of: hot, top, new.") + parser.add_argument("-l","--limit", type=str, default=config["limit"], + help="Set a limit to pull posts") + parser.add_argument("-r","--random", action='store_true', default=config["random"], + help="Randomize witin sort") arguments = parser.parse_args() return arguments @@ -98,11 +107,16 @@ def get_top_image(sub_reddit): :return: the image link """ if args.sort == "top": - submissions = sub_reddit.top(args.time) + submissions = sub_reddit.top(params={"t": args.time}, limit=int(args.limit)) elif args.sort == "new": - submissions = sub_reddit.new(params={"t": args.time}, limit=10) + submissions = sub_reddit.new(params={"t": args.time}, limit=int(args.limit)) else: - submissions = sub_reddit.hot(params={"t": args.time}, limit=10) + submissions = sub_reddit.hot(params={"t": args.time}, limit=int(args.limit)) + + if args.random: + submissions= sorted(submissions, key=lambda k: random.random()) + else: + submissions = submissions for submission in submissions: ret = {"id": submission.id} @@ -192,7 +206,10 @@ def detect_desktop_environment(): # Get top image link image = get_top_image(r.subreddit(subreddit)) - if "url" not in image: + try: + if "url" not in image: + sys.exit("Error: No suitable images were found, the program is now exiting.") + except TypeError: sys.exit("Error: No suitable images were found, the program is now exiting.") # Request image From ca24803ad3c57ee38beaa45676c758dd64b237f3 Mon Sep 17 00:00:00 2001 From: rahilshah10 <32785595+rahilshah10@users.noreply.github.com> Date: Sun, 11 Jul 2021 19:50:02 -0700 Subject: [PATCH 19/36] Update praw --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 22f4980..6d75503 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==4.4.2 future==0.18.2 -praw==7.1.0 +praw==7.3.0 requests==2.24.0 six==1.15.0 update-checker==0.18.0 From 48fb76a0f5c2d61bf3b915fda4a81371aca29bc7 Mon Sep 17 00:00:00 2001 From: rahilshah10 <32785595+rahilshah10@users.noreply.github.com> Date: Sat, 24 Jul 2021 21:11:47 -0700 Subject: [PATCH 20/36] Fix Time and Random Functionality --- change_wallpaper_reddit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 8873fb5..74e1841 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -107,13 +107,13 @@ def get_top_image(sub_reddit): :return: the image link """ if args.sort == "top": - submissions = sub_reddit.top(params={"t": args.time}, limit=int(args.limit)) + submissions = sub_reddit.top(time_filter = args.time, limit=int(args.limit)) elif args.sort == "new": - submissions = sub_reddit.new(params={"t": args.time}, limit=int(args.limit)) + submissions = sub_reddit.new(time_filter = args.time, limit=int(args.limit)) else: - submissions = sub_reddit.hot(params={"t": args.time}, limit=int(args.limit)) + submissions = sub_reddit.hot(time_filter = args.time, limit=int(args.limit)) - if args.random: + if args.random == True: submissions= sorted(submissions, key=lambda k: random.random()) else: submissions = submissions From 50f9b301a1a0805df250319ea38f14ee6099ff11 Mon Sep 17 00:00:00 2001 From: rahilshah10 <32785595+rahilshah10@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:22:15 -0700 Subject: [PATCH 21/36] Fixes to the randomization --- change_wallpaper_reddit.py | 17 ++++++++++------- requirements.txt | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 74e1841..d4f1e1f 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -27,14 +27,15 @@ def load_config(): default = defaultdict(str) default["subreddit"] = "wallpaper" default["nsfw"] = False - default["time"] = "day" + default["time"] = "all" default["display"] = "0" default["output"] = "Pictures/Wallpapers" default["sort"] = "hot" default["limit"] = 20 default["random"] = False - config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") + # config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") + config_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '\\change_wallpaper_reddit.rc' section_name = "root" try: conf = ConfigParser(default) @@ -65,7 +66,7 @@ def add_to_ret(fun, name): add_to_ret(conf.get, "output") add_to_ret(conf.get, "sort") add_to_ret(conf.get, "limit") - add_to_ret(conf.get, "random") + add_to_ret(conf.getboolean, "random") return ret @@ -111,7 +112,7 @@ def get_top_image(sub_reddit): elif args.sort == "new": submissions = sub_reddit.new(time_filter = args.time, limit=int(args.limit)) else: - submissions = sub_reddit.hot(time_filter = args.time, limit=int(args.limit)) + submissions = sub_reddit.hot(limit=int(args.limit)) if args.random == True: submissions= sorted(submissions, key=lambda k: random.random()) @@ -120,14 +121,17 @@ def get_top_image(sub_reddit): for submission in submissions: ret = {"id": submission.id} + ret["subreddit"] = submission.subreddit.display_name + print(ret["subreddit"]) if not args.nsfw and submission.over_18: continue url = submission.url + print(f'url : {url}') # Strip trailing arguments (after a '?') url = re.sub(R"\?.*", "", url) ret['type'] = url.split(".")[-1] - if url.endswith(".jpg") or url.endswith(".png"): + if url.endswith(".jpg") or url.endswith(".png") or url.endswith(".jpeg"): ret["url"] = url # Imgur support elif ("imgur.com" in url) and ("/a/" not in url) and ("/gallery/" not in url): @@ -214,7 +218,6 @@ def detect_desktop_environment(): # Request image response = requests.get(image["url"], allow_redirects=False) - # If image is available, proceed to save if response.status_code == requests.codes.ok: # Get home directory and location where image will be saved @@ -222,7 +225,7 @@ def detect_desktop_environment(): home_dir = os.path.expanduser("~") save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{image_type}".format(home_dir=home_dir, save_dir=save_dir, - subreddit=subreddit, + subreddit=image.get("subreddit",'some_wallpaper'), id=image["id"], image_type=image['type']) diff --git a/requirements.txt b/requirements.txt index 6d75503..d1d8cf3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==4.4.2 future==0.18.2 -praw==7.3.0 +praw==7.4.0 requests==2.24.0 six==1.15.0 update-checker==0.18.0 From dde9feacb95913a69e52c3f9176c7455eb5f9dea Mon Sep 17 00:00:00 2001 From: rahilshah10 <32785595+rahilshah10@users.noreply.github.com> Date: Sun, 19 Sep 2021 15:48:03 -0700 Subject: [PATCH 22/36] Updates to New logic --- change_wallpaper_reddit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index d4f1e1f..aa944d6 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -110,7 +110,7 @@ def get_top_image(sub_reddit): if args.sort == "top": submissions = sub_reddit.top(time_filter = args.time, limit=int(args.limit)) elif args.sort == "new": - submissions = sub_reddit.new(time_filter = args.time, limit=int(args.limit)) + submissions = sub_reddit.new(limit=int(args.limit)) else: submissions = sub_reddit.hot(limit=int(args.limit)) From 603d902c5c206d1416340a751d92b6a605fcb5ed Mon Sep 17 00:00:00 2001 From: "Federico \"EvilScript\" Torrielli" Date: Tue, 21 Dec 2021 15:59:25 +0100 Subject: [PATCH 23/36] Smaller changes --- .gitignore | 0 .travis.yml | 0 LICENSE | 0 README.md | 0 credentials.json | 0 requirements.txt | 0 6 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .travis.yml mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.md mode change 100644 => 100755 credentials.json mode change 100644 => 100755 requirements.txt diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.travis.yml b/.travis.yml old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/credentials.json b/credentials.json old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 From f0b9a9dc20c8ff4ec3ec8c2a478b2e87ffaf4e2b Mon Sep 17 00:00:00 2001 From: "Federico \"EvilScript\" Torrielli" Date: Tue, 21 Dec 2021 16:29:56 +0100 Subject: [PATCH 24/36] Code adjustement, rollbacks, module updates and other changes --- change_wallpaper_reddit.py | 55 +++++++++++++++++++++++--------------- requirements.txt | 8 +++--- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index aa944d6..a4b3751 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -34,8 +34,15 @@ def load_config(): default["limit"] = 20 default["random"] = False - # config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") - config_path = os.path.dirname(os.path.realpath(sys.argv[0])) + '\\change_wallpaper_reddit.rc' + # If Linux, use config_path_linux otherwise use config_path_windows + config_path_linux = os.path.expanduser( + "~/.config/change_wallpaper_reddit.rc") + config_path_windows = os.path.dirname(os.path.realpath( + sys.argv[0])) + '\\change_wallpaper_reddit.rc' + if platform.system() == "Linux": + config_path = config_path_linux + else: + config_path = config_path_windows section_name = "root" try: conf = ConfigParser(default) @@ -54,9 +61,6 @@ def add_to_ret(fun, name): try: ret[name] = fun(section_name, name) except ValueError as e_code: - err_str = "Error in config file. Variable '{}': {}. The default '{}' will be used." - - # print sys.stderr >> err_str.format(name, str(e_code), default[name]) ret[name] = default[name] add_to_ret(conf.get, "subreddit") @@ -86,16 +90,17 @@ def parse_args(): help="Example: art, getmotivated, wallpapers, ...") parser.add_argument("-t", "--time", type=str, default=config["time"], help="Example: hour, day, week, month, year") - parser.add_argument("-n", "--nsfw", action='store_true', default=config["nsfw"], help="Enables NSFW tagged posts.") + parser.add_argument("-n", "--nsfw", action='store_true', + default=config["nsfw"], help="Enables NSFW tagged posts.") parser.add_argument("-d", "--display", type=int, default=config["display"], help="Desktop display number on OS X (0: all displays, 1: main display, etc") parser.add_argument("-o", "--output", type=str, default=config["output"], help="Set the outputfolder in the home directory to save the Wallpapers to.") parser.add_argument("--sort", type=str, default=config["sort"], help="Can be one of: hot, top, new.") - parser.add_argument("-l","--limit", type=str, default=config["limit"], + parser.add_argument("-l", "--limit", type=str, default=config["limit"], help="Set a limit to pull posts") - parser.add_argument("-r","--random", action='store_true', default=config["random"], + parser.add_argument("-r", "--random", action='store_true', default=config["random"], help="Randomize witin sort") arguments = parser.parse_args() @@ -108,14 +113,15 @@ def get_top_image(sub_reddit): :return: the image link """ if args.sort == "top": - submissions = sub_reddit.top(time_filter = args.time, limit=int(args.limit)) + submissions = sub_reddit.top( + time_filter=args.time, limit=int(args.limit)) elif args.sort == "new": submissions = sub_reddit.new(limit=int(args.limit)) else: submissions = sub_reddit.hot(limit=int(args.limit)) - if args.random == True: - submissions= sorted(submissions, key=lambda k: random.random()) + if args.random: + submissions = sorted(submissions, key=lambda k: random.random()) else: submissions = submissions @@ -152,6 +158,7 @@ def detect_desktop_environment(): :return: environment """ environment = {} + d_session = os.environ.get("DESKTOP_SESSION") if os.environ.get("KDE_FULL_SESSION") == "true": environment["name"] = "kde" environment["command"] = """ @@ -170,14 +177,16 @@ def detect_desktop_environment(): """ elif os.environ.get("GNOME_DESKTOP_SESSION_ID"): environment["name"] = "gnome" - environment["command"] = "gsettings set org.gnome.desktop.background picture-uri file://{save_location}" - elif os.environ.get("DESKTOP_SESSION") == "Lubuntu": + environment[ + "command"] = "gsettings set org.gnome.desktop.background picture-uri file://{save_location}" + elif d_session == "Lubuntu": environment["name"] = "lubuntu" environment["command"] = "pcmanfm -w {save_location} --wallpaper-mode=fit" - elif os.environ.get("DESKTOP_SESSION") == "mate": + elif d_session == "mate": environment["name"] = "mate" - environment["command"] = "gsettings set org.mate.background picture-filename {save_location}" - elif os.environ.get("DESKTOP_SESSION") == "i3": + environment[ + "command"] = "gsettings set org.mate.background picture-filename {save_location}" + elif d_session == "i3" or d_session == "leftwm" or d_session == "dwm": environment["name"] = "i3" environment["command"] = "feh --bg-scale {save_location}" else: @@ -212,7 +221,8 @@ def detect_desktop_environment(): image = get_top_image(r.subreddit(subreddit)) try: if "url" not in image: - sys.exit("Error: No suitable images were found, the program is now exiting.") + sys.exit( + "Error: No suitable images were found, the program is now exiting.") except TypeError: sys.exit("Error: No suitable images were found, the program is now exiting.") @@ -225,7 +235,7 @@ def detect_desktop_environment(): home_dir = os.path.expanduser("~") save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{image_type}".format(home_dir=home_dir, save_dir=save_dir, - subreddit=image.get("subreddit",'some_wallpaper'), + subreddit=subreddit, id=image["id"], image_type=image['type']) @@ -247,7 +257,8 @@ def detect_desktop_environment(): # Check desktop environments for linux desktop_environment = detect_desktop_environment() if desktop_environment and desktop_environment["name"] in supported_linux_desktop_envs: - os.system(desktop_environment["command"].format(save_location=save_location)) + os.system(desktop_environment["command"].format( + save_location=save_location)) else: print("Unsupported desktop environment") @@ -255,10 +266,12 @@ def detect_desktop_environment(): if platform_name.startswith("Win"): # Python 3.x if sys.version_info >= (3, 0): - ctypes.windll.user32.SystemParametersInfoW(20, 0, save_location, 3) + ctypes.windll.user32.SystemParametersInfoW( + 20, 0, save_location, 3) # Python 2.x else: - ctypes.windll.user32.SystemParametersInfoA(20, 0, save_location, 3) + ctypes.windll.user32.SystemParametersInfoA( + 20, 0, save_location, 3) # OS X/macOS if platform_name.startswith("Darwin"): diff --git a/requirements.txt b/requirements.txt index d1d8cf3..7ab97d4 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -decorator==4.4.2 +decorator==5.1.0 future==0.18.2 -praw==7.4.0 -requests==2.24.0 -six==1.15.0 +praw==7.5.0 +requests==2.26.0 +six==1.16.0 update-checker==0.18.0 nose2==0.10.0 From cdbc97135d35fe0ed29cbac35ce9a57ac31496b9 Mon Sep 17 00:00:00 2001 From: Federico EvilScript Torrielli Date: Wed, 26 Jan 2022 12:13:27 +0100 Subject: [PATCH 25/36] Update requirements.txt --- .gitignore | 0 .travis.yml | 0 LICENSE | 0 README.md | 0 change_wallpaper_reddit.py | 0 credentials.json | 0 requirements.txt | 4 ++-- 7 files changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .travis.yml mode change 100755 => 100644 LICENSE mode change 100755 => 100644 README.md mode change 100755 => 100644 change_wallpaper_reddit.py mode change 100755 => 100644 credentials.json mode change 100755 => 100644 requirements.txt diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.travis.yml b/.travis.yml old mode 100755 new mode 100644 diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py old mode 100755 new mode 100644 diff --git a/credentials.json b/credentials.json old mode 100755 new mode 100644 diff --git a/requirements.txt b/requirements.txt old mode 100755 new mode 100644 index 7ab97d4..4e9b0e6 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -decorator==5.1.0 +decorator==5.1.1 future==0.18.2 praw==7.5.0 -requests==2.26.0 +requests==2.27.1 six==1.16.0 update-checker==0.18.0 nose2==0.10.0 From 934dcdf1534d3f23f156759ae139326b8c7c4310 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 May 2023 03:10:44 +0000 Subject: [PATCH 26/36] Bump requests from 2.27.1 to 2.31.0 Bumps [requests](https://github.com/psf/requests) from 2.27.1 to 2.31.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.27.1...v2.31.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4e9b0e6..6f19bba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ decorator==5.1.1 future==0.18.2 praw==7.5.0 -requests==2.27.1 +requests==2.31.0 six==1.16.0 update-checker==0.18.0 nose2==0.10.0 From 788dbd266b53c6b02db34b59381588a93ea8f465 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:51:20 +0000 Subject: [PATCH 27/36] Bump future from 0.18.2 to 0.18.3 Bumps [future](https://github.com/PythonCharmers/python-future) from 0.18.2 to 0.18.3. - [Release notes](https://github.com/PythonCharmers/python-future/releases) - [Changelog](https://github.com/PythonCharmers/python-future/blob/master/docs/changelog.rst) - [Commits](https://github.com/PythonCharmers/python-future/compare/v0.18.2...v0.18.3) --- updated-dependencies: - dependency-name: future dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6f19bba..b9358ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ decorator==5.1.1 -future==0.18.2 +future==0.18.3 praw==7.5.0 requests==2.31.0 six==1.16.0 From 0f562fe1dfb9e118a01a30ddfef5aae7981844e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:51:21 +0000 Subject: [PATCH 28/36] Bump requests from 2.31.0 to 2.32.2 Bumps [requests](https://github.com/psf/requests) from 2.31.0 to 2.32.2. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.31.0...v2.32.2) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6f19bba..2f9e518 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ decorator==5.1.1 future==0.18.2 praw==7.5.0 -requests==2.31.0 +requests==2.32.2 six==1.16.0 update-checker==0.18.0 nose2==0.10.0 From 4ddba26fd051f477f3ce66894491b30be44d029f Mon Sep 17 00:00:00 2001 From: ThatMatrix Date: Mon, 16 Dec 2024 10:21:49 +0100 Subject: [PATCH 29/36] fix(requirements.txt): bump praw version to 7.8.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 080b5ca..443cd85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==5.1.1 future==0.18.3 -praw==7.5.0 +praw==7.8.1 requests==2.32.2 six==1.16.0 update-checker==0.18.0 From 5e526590563866edca7f42c6b198bc2cdefb2988 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Tue, 1 Jul 2025 09:54:35 +0200 Subject: [PATCH 30/36] fix: update dependencies in requirements.txt and improve Python version compatibility in change_wallpaper_reddit.py --- change_wallpaper_reddit.py | 222 ++++++++++++++++++++++--------------- requirements.txt | 7 +- 2 files changed, 137 insertions(+), 92 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index a4b3751..03928ce 100644 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -1,27 +1,22 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- -from __future__ import unicode_literals import argparse import ctypes import json import os import platform +import random import re +import subprocess import sys -import random from collections import defaultdict from configparser import ConfigParser -from io import StringIO +from pathlib import Path import praw import requests -if sys.version_info <= (2, 6): - import commands as subprocess -else: - import subprocess - def load_config(): default = defaultdict(str) @@ -35,10 +30,9 @@ def load_config(): default["random"] = False # If Linux, use config_path_linux otherwise use config_path_windows - config_path_linux = os.path.expanduser( - "~/.config/change_wallpaper_reddit.rc") - config_path_windows = os.path.dirname(os.path.realpath( - sys.argv[0])) + '\\change_wallpaper_reddit.rc' + config_path_linux = Path.home() / ".config" / "change_wallpaper_reddit.rc" + config_path_windows = Path(sys.argv[0]).parent / "change_wallpaper_reddit.rc" + if platform.system() == "Linux": config_path = config_path_linux else: @@ -47,12 +41,8 @@ def load_config(): try: conf = ConfigParser(default) with open(config_path, "r") as stream: - stream = StringIO("[{section_name}]\n{stream_read}".format(section_name=section_name, - stream_read=stream.read())) - if sys.version_info >= (3, 0): - conf.read_file(stream) - else: - conf.read_file(stream) + config_string = f"[{section_name}]\n{stream.read()}" + conf.read_string(config_string) ret = {} @@ -60,7 +50,7 @@ def load_config(): def add_to_ret(fun, name): try: ret[name] = fun(section_name, name) - except ValueError as e_code: + except ValueError: ret[name] = default[name] add_to_ret(conf.get, "subreddit") @@ -74,7 +64,7 @@ def add_to_ret(fun, name): return ret - except IOError as e: + except IOError: return default @@ -86,22 +76,62 @@ def parse_args(): :returns: arguments """ parser = argparse.ArgumentParser(description="Daily Reddit Wallpaper") - parser.add_argument("-s", "--subreddit", type=str, default=config["subreddit"], - help="Example: art, getmotivated, wallpapers, ...") - parser.add_argument("-t", "--time", type=str, default=config["time"], - help="Example: hour, day, week, month, year") - parser.add_argument("-n", "--nsfw", action='store_true', - default=config["nsfw"], help="Enables NSFW tagged posts.") - parser.add_argument("-d", "--display", type=int, default=config["display"], - help="Desktop display number on OS X (0: all displays, 1: main display, etc") - parser.add_argument("-o", "--output", type=str, default=config["output"], - help="Set the outputfolder in the home directory to save the Wallpapers to.") - parser.add_argument("--sort", type=str, default=config["sort"], - help="Can be one of: hot, top, new.") - parser.add_argument("-l", "--limit", type=str, default=config["limit"], - help="Set a limit to pull posts") - parser.add_argument("-r", "--random", action='store_true', default=config["random"], - help="Randomize witin sort") + parser.add_argument( + "-s", + "--subreddit", + type=str, + default=config["subreddit"], + help="Example: art, getmotivated, wallpapers, ...", + ) + parser.add_argument( + "-t", + "--time", + type=str, + default=config["time"], + help="Example: hour, day, week, month, year", + ) + parser.add_argument( + "-n", + "--nsfw", + action="store_true", + default=config["nsfw"], + help="Enables NSFW tagged posts.", + ) + parser.add_argument( + "-d", + "--display", + type=int, + default=config["display"], + help="Desktop display number on OS X (0: all displays, 1: main display, etc", + ) + parser.add_argument( + "-o", + "--output", + type=str, + default=config["output"], + help="Set the outputfolder in the home directory to save the Wallpapers to.", + ) + parser.add_argument( + "--sort", type=str, default=config["sort"], help="Can be one of: hot, top, new." + ) + parser.add_argument( + "-l", + "--limit", + type=str, + default=config["limit"], + help="Set a limit to pull posts", + ) + parser.add_argument( + "-r", + "--random", + action="store_true", + default=config["random"], + help="Randomize witin sort", + ) + parser.add_argument("--client-id", type=str, help="Reddit API client ID.") + parser.add_argument( + "--api-key", type=str, help="Reddit API client secret (api key)." + ) arguments = parser.parse_args() return arguments @@ -113,8 +143,7 @@ def get_top_image(sub_reddit): :return: the image link """ if args.sort == "top": - submissions = sub_reddit.top( - time_filter=args.time, limit=int(args.limit)) + submissions = sub_reddit.top(time_filter=args.time, limit=int(args.limit)) elif args.sort == "new": submissions = sub_reddit.new(limit=int(args.limit)) else: @@ -122,8 +151,6 @@ def get_top_image(sub_reddit): if args.random: submissions = sorted(submissions, key=lambda k: random.random()) - else: - submissions = submissions for submission in submissions: ret = {"id": submission.id} @@ -132,19 +159,19 @@ def get_top_image(sub_reddit): if not args.nsfw and submission.over_18: continue url = submission.url - print(f'url : {url}') + print(f"url : {url}") # Strip trailing arguments (after a '?') - url = re.sub(R"\?.*", "", url) - ret['type'] = url.split(".")[-1] + url = re.sub(r"\?.*", "", url) + ret["type"] = url.split(".")[-1] - if url.endswith(".jpg") or url.endswith(".png") or url.endswith(".jpeg"): + if url.endswith((".jpg", ".png", ".jpeg")): ret["url"] = url # Imgur support - elif ("imgur.com" in url) and ("/a/" not in url) and ("/gallery/" not in url): + elif "imgur.com" in url and "/a/" not in url and "/gallery/" not in url: if url.endswith("/new"): url = url.rsplit("/", 1)[0] id_toget = url.rsplit("/", 1)[1].rsplit(".", 1)[0] - ret["url"] = "http://i.imgur.com/{id}.jpg".format(id=id_toget) + ret["url"] = f"http://i.imgur.com/{id_toget}.jpg" else: continue @@ -159,6 +186,7 @@ def detect_desktop_environment(): """ environment = {} d_session = os.environ.get("DESKTOP_SESSION") + xdg_current_desktop = os.environ.get("XDG_CURRENT_DESKTOP") if os.environ.get("KDE_FULL_SESSION") == "true": environment["name"] = "kde" environment["command"] = """ @@ -175,18 +203,22 @@ def detect_desktop_environment(): }} ' """ - elif os.environ.get("GNOME_DESKTOP_SESSION_ID"): + elif os.environ.get("GNOME_DESKTOP_SESSION_ID") or ( + xdg_current_desktop and "GNOME" in xdg_current_desktop.upper() + ): environment["name"] = "gnome" - environment[ - "command"] = "gsettings set org.gnome.desktop.background picture-uri file://{save_location}" + environment["command"] = ( + "gsettings set org.gnome.desktop.background picture-uri file://{save_location} && gsettings set org.gnome.desktop.background picture-uri-dark file://{save_location}" + ) elif d_session == "Lubuntu": environment["name"] = "lubuntu" environment["command"] = "pcmanfm -w {save_location} --wallpaper-mode=fit" elif d_session == "mate": environment["name"] = "mate" - environment[ - "command"] = "gsettings set org.mate.background picture-filename {save_location}" - elif d_session == "i3" or d_session == "leftwm" or d_session == "dwm": + environment["command"] = ( + "gsettings set org.mate.background picture-filename {save_location}" + ) + elif d_session in ("i3", "leftwm", "dwm"): environment["name"] = "i3" environment["command"] = "feh --bg-scale {save_location}" else: @@ -194,35 +226,57 @@ def detect_desktop_environment(): info = subprocess.getoutput("xprop -root _DT_SAVE_MODE") if ' = "xfce4"' in info: environment["name"] = "xfce" + environment["command"] = ( + "xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image -s {save_location}" + ) except (OSError, RuntimeError): environment = None pass return environment -if __name__ == '__main__': - +if __name__ == "__main__": args = parse_args() subreddit = args.subreddit save_dir = args.output - supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu", "i3"] + supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu", "i3", "xfce"] - # Load credentials from credentials.json file - with open(os.path.dirname(os.path.realpath(sys.argv[0])) + '/credentials.json') as f: - params = json.load(f) + client_id = args.client_id + api_key = args.api_key + + if not all([client_id, api_key]): + # Load credentials from credentials.json file + credentials_path = Path(sys.argv[0]).parent / "credentials.json" + try: + with open(credentials_path) as f: + params = json.load(f) + client_id = client_id or params.get("client_id") + api_key = api_key or params.get("api_key") + except (IOError, json.JSONDecodeError): + pass + + if not all([client_id, api_key]): + sys.exit( + "Error: client_id and api_key not provided. " + "Please provide them as arguments (--client-id, --api-key) " + "or in credentials.json." + ) # Python Reddit Api Wrapper - r = praw.Reddit(client_id=params['client_id'], - client_secret=params['api_key'], - user_agent=f"Get top wallpaper from /r/{subreddit}") + r = praw.Reddit( + client_id=client_id, + client_secret=api_key, + user_agent=f"Get top wallpaper from /r/{subreddit}", + ) # Get top image link image = get_top_image(r.subreddit(subreddit)) try: if "url" not in image: sys.exit( - "Error: No suitable images were found, the program is now exiting.") + "Error: No suitable images were found, the program is now exiting." + ) except TypeError: sys.exit("Error: No suitable images were found, the program is now exiting.") @@ -232,18 +286,13 @@ def detect_desktop_environment(): if response.status_code == requests.codes.ok: # Get home directory and location where image will be saved # (default location for Ubuntu is used) - home_dir = os.path.expanduser("~") - save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{image_type}".format(home_dir=home_dir, - save_dir=save_dir, - subreddit=subreddit, - id=image["id"], - image_type=image['type']) - - if not os.path.isfile(save_location): + save_location = ( + Path.home() / save_dir / f"{subreddit}-{image['id']}.{image['type']}" + ) + + if not save_location.is_file(): # Create folders if they don't exist - directory = os.path.dirname(save_location) - if not os.path.exists(directory): - os.makedirs(directory) + save_location.parent.mkdir(parents=True, exist_ok=True) # Write to disk with open(save_location, "wb") as fo: @@ -253,25 +302,21 @@ def detect_desktop_environment(): # Check OS and environments platform_name = platform.system() if platform_name.startswith("Lin"): - # Check desktop environments for linux desktop_environment = detect_desktop_environment() - if desktop_environment and desktop_environment["name"] in supported_linux_desktop_envs: - os.system(desktop_environment["command"].format( - save_location=save_location)) + if ( + desktop_environment + and desktop_environment["name"] in supported_linux_desktop_envs + ): + os.system( + desktop_environment["command"].format(save_location=save_location) + ) else: print("Unsupported desktop environment") # Windows if platform_name.startswith("Win"): - # Python 3.x - if sys.version_info >= (3, 0): - ctypes.windll.user32.SystemParametersInfoW( - 20, 0, save_location, 3) - # Python 2.x - else: - ctypes.windll.user32.SystemParametersInfoA( - 20, 0, save_location, 3) + ctypes.windll.user32.SystemParametersInfoW(20, 0, str(save_location), 3) # OS X/macOS if platform_name.startswith("Darwin"): @@ -292,8 +337,9 @@ def detect_desktop_environment(): tell desktop {display} set picture to "{save_location}" end tell - end tell'""".format(display=args.display, - save_location=save_location) + end tell'""".format( + display=args.display, save_location=save_location + ) os.system(command) else: sys.exit("Error: Image url is not available, the program is now exiting.") diff --git a/requirements.txt b/requirements.txt index 443cd85..bec00a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ -decorator==5.1.1 -future==0.18.3 +decorator==5.2.1 praw==7.8.1 requests==2.32.2 -six==1.16.0 +six==1.17.0 update-checker==0.18.0 -nose2==0.10.0 +nose2==0.15.1 From 625af18400f04b8995042438bd1f541189e736ca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 07:56:58 +0000 Subject: [PATCH 31/36] Bump requests from 2.32.2 to 2.32.4 Bumps [requests](https://github.com/psf/requests) from 2.32.2 to 2.32.4. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.32.2...v2.32.4) --- updated-dependencies: - dependency-name: requests dependency-version: 2.32.4 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bec00a5..5eadc95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==5.2.1 praw==7.8.1 -requests==2.32.2 +requests==2.32.4 six==1.17.0 update-checker==0.18.0 nose2==0.15.1 From 14d355c49ef38c4d4054e4195a058a1904b035ce Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Wed, 9 Jul 2025 18:18:15 +0200 Subject: [PATCH 32/36] feat: enhance configuration and argument parsing for wallpaper script - Updated default output directory to "Wallpapers". - Added flair filtering option in argument parsing. - Improved help descriptions for time and sort arguments. --- change_wallpaper_reddit.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 03928ce..5c0b970 100644 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -24,10 +24,11 @@ def load_config(): default["nsfw"] = False default["time"] = "all" default["display"] = "0" - default["output"] = "Pictures/Wallpapers" + default["output"] = "Wallpapers" default["sort"] = "hot" default["limit"] = 20 default["random"] = False + default["flair"] = "" # If Linux, use config_path_linux otherwise use config_path_windows config_path_linux = Path.home() / ".config" / "change_wallpaper_reddit.rc" @@ -61,6 +62,7 @@ def add_to_ret(fun, name): add_to_ret(conf.get, "sort") add_to_ret(conf.get, "limit") add_to_ret(conf.getboolean, "random") + add_to_ret(conf.get, "flair") return ret @@ -88,7 +90,7 @@ def parse_args(): "--time", type=str, default=config["time"], - help="Example: hour, day, week, month, year", + help="Time filter for 'top' sort only. Example: hour, day, week, month, year, all", ) parser.add_argument( "-n", @@ -112,7 +114,10 @@ def parse_args(): help="Set the outputfolder in the home directory to save the Wallpapers to.", ) parser.add_argument( - "--sort", type=str, default=config["sort"], help="Can be one of: hot, top, new." + "--sort", + type=str, + default=config["sort"], + help="Can be one of: hot, top, new. Note: --time only works with 'top'", ) parser.add_argument( "-l", @@ -128,6 +133,13 @@ def parse_args(): default=config["random"], help="Randomize witin sort", ) + parser.add_argument( + "-f", + "--flair", + type=str, + default=config["flair"], + help="Filter by flair text (e.g., 'Desktop', 'Mobile')", + ) parser.add_argument("--client-id", type=str, help="Reddit API client ID.") parser.add_argument( "--api-key", type=str, help="Reddit API client secret (api key)." @@ -158,6 +170,12 @@ def get_top_image(sub_reddit): print(ret["subreddit"]) if not args.nsfw and submission.over_18: continue + # Filter by flair if specified + if args.flair and ( + not submission.link_flair_text + or args.flair.lower() not in submission.link_flair_text.lower() + ): + continue url = submission.url print(f"url : {url}") # Strip trailing arguments (after a '?') From 6b11b9f520eeb4f271467c98883f9f86d6433f3d Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Wed, 9 Jul 2025 18:30:19 +0200 Subject: [PATCH 33/36] refactor: streamline configuration loading and enhance argument parsing in change_wallpaper_reddit.py --- change_wallpaper_reddit.py | 451 +++++++++++++++++++++---------------- 1 file changed, 253 insertions(+), 198 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 5c0b970..6764989 100644 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import argparse -import ctypes import json import os import platform @@ -10,64 +9,72 @@ import re import subprocess import sys -from collections import defaultdict from configparser import ConfigParser from pathlib import Path -import praw -import requests +import praw # type: ignore +import requests # type: ignore + +# Platform detection constants +PLATFORM = platform.system() +IS_LINUX = PLATFORM == "Linux" +IS_WINDOWS = PLATFORM == "Windows" +IS_DARWIN = PLATFORM == "Darwin" + +# Default configuration +DEFAULT_CONFIG = { + "subreddit": "wallpaper", + "nsfw": False, + "time": "all", + "display": "0", + "output": "Wallpapers", + "sort": "hot", + "limit": 20, + "random": False, + "flair": "", +} + +# URL regex pattern (compiled once for performance) +URL_STRIP_PATTERN = re.compile(r"\?.*") def load_config(): - default = defaultdict(str) - default["subreddit"] = "wallpaper" - default["nsfw"] = False - default["time"] = "all" - default["display"] = "0" - default["output"] = "Wallpapers" - default["sort"] = "hot" - default["limit"] = 20 - default["random"] = False - default["flair"] = "" - - # If Linux, use config_path_linux otherwise use config_path_windows - config_path_linux = Path.home() / ".config" / "change_wallpaper_reddit.rc" - config_path_windows = Path(sys.argv[0]).parent / "change_wallpaper_reddit.rc" - - if platform.system() == "Linux": - config_path = config_path_linux - else: - config_path = config_path_windows - section_name = "root" + """Load configuration from file or return defaults""" + config_path = ( + Path.home() / ".config" / "change_wallpaper_reddit.rc" + if IS_LINUX + else Path(sys.argv[0]).parent / "change_wallpaper_reddit.rc" + ) + try: - conf = ConfigParser(default) + conf = ConfigParser(DEFAULT_CONFIG) with open(config_path, "r") as stream: - config_string = f"[{section_name}]\n{stream.read()}" + config_string = f"[root]\n{stream.read()}" conf.read_string(config_string) - ret = {} - - # Add a value to ret, printing an error message if there is an error - def add_to_ret(fun, name): + # Build config dict with error handling + config = {} + config_mappings = [ + ("subreddit", conf.get), + ("nsfw", conf.getboolean), + ("display", conf.getint), + ("time", conf.get), + ("output", conf.get), + ("sort", conf.get), + ("limit", conf.getint), + ("random", conf.getboolean), + ("flair", conf.get), + ] + + for key, getter in config_mappings: try: - ret[name] = fun(section_name, name) - except ValueError: - ret[name] = default[name] - - add_to_ret(conf.get, "subreddit") - add_to_ret(conf.getboolean, "nsfw") - add_to_ret(conf.getint, "display") - add_to_ret(conf.get, "time") - add_to_ret(conf.get, "output") - add_to_ret(conf.get, "sort") - add_to_ret(conf.get, "limit") - add_to_ret(conf.getboolean, "random") - add_to_ret(conf.get, "flair") - - return ret + config[key] = getter("root", key) + except (ValueError, TypeError): + config[key] = DEFAULT_CONFIG[key] + return config except IOError: - return default + return DEFAULT_CONFIG.copy() config = load_config() @@ -122,7 +129,7 @@ def parse_args(): parser.add_argument( "-l", "--limit", - type=str, + type=int, default=config["limit"], help="Set a limit to pull posts", ) @@ -149,215 +156,263 @@ def parse_args(): return arguments -def get_top_image(sub_reddit): +def get_top_image(sub_reddit, args): """Get image link of most upvoted wallpaper of the day :sub_reddit: name of the sub reddit + :args: parsed arguments :return: the image link """ + # Use generator dispatch for better performance if args.sort == "top": - submissions = sub_reddit.top(time_filter=args.time, limit=int(args.limit)) + submissions = sub_reddit.top(time_filter=args.time, limit=args.limit) elif args.sort == "new": - submissions = sub_reddit.new(limit=int(args.limit)) + submissions = sub_reddit.new(limit=args.limit) else: - submissions = sub_reddit.hot(limit=int(args.limit)) + submissions = sub_reddit.hot(limit=args.limit) if args.random: submissions = sorted(submissions, key=lambda k: random.random()) for submission in submissions: - ret = {"id": submission.id} - ret["subreddit"] = submission.subreddit.display_name - print(ret["subreddit"]) if not args.nsfw and submission.over_18: continue + # Filter by flair if specified if args.flair and ( not submission.link_flair_text or args.flair.lower() not in submission.link_flair_text.lower() ): continue + url = submission.url - print(f"url : {url}") # Strip trailing arguments (after a '?') - url = re.sub(r"\?.*", "", url) - ret["type"] = url.split(".")[-1] + url = URL_STRIP_PATTERN.sub("", url) + + # Extract file extension + file_extension = url.split(".")[-1].lower() if url.endswith((".jpg", ".png", ".jpeg")): - ret["url"] = url + return { + "id": submission.id, + "subreddit": submission.subreddit.display_name, + "url": url, + "type": file_extension, + } # Imgur support elif "imgur.com" in url and "/a/" not in url and "/gallery/" not in url: if url.endswith("/new"): url = url.rsplit("/", 1)[0] id_toget = url.rsplit("/", 1)[1].rsplit(".", 1)[0] - ret["url"] = f"http://i.imgur.com/{id_toget}.jpg" - else: - continue + return { + "id": submission.id, + "subreddit": submission.subreddit.display_name, + "url": f"http://i.imgur.com/{id_toget}.jpg", + "type": "jpg", + } - return ret + return None def detect_desktop_environment(): """Get current Desktop Environment - http://stackoverflow.com - /questions/2035657/what-is-my-current-desktop-environment - :return: environment + :return: environment dict or None """ - environment = {} + if not IS_LINUX: + return None + + # Environment variables for detection d_session = os.environ.get("DESKTOP_SESSION") xdg_current_desktop = os.environ.get("XDG_CURRENT_DESKTOP") + + # KDE detection if os.environ.get("KDE_FULL_SESSION") == "true": - environment["name"] = "kde" - environment["command"] = """ - qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript ' - var allDesktops = desktops(); - print (allDesktops); - for (i=0;i Date: Mon, 1 Sep 2025 16:11:55 +0200 Subject: [PATCH 34/36] Update dependencies and add pyproject.toml for daily-reddit-wallpaper project - Updated requests from version 2.32.4 to 2.32.5 in requirements.txt - Added pyproject.toml to define project metadata and dependencies - Created uv.lock to lock dependencies for the project --- README.md | 137 +++++++++++++++++++++------------ pyproject.toml | 14 ++++ requirements.txt | 2 +- uv.lock | 195 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 300 insertions(+), 48 deletions(-) create mode 100644 pyproject.toml create mode 100644 uv.lock diff --git a/README.md b/README.md index 8a39bd7..1cf59f0 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,152 @@ # Daily Reddit Wallpaper + [![Build Status](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper) This script changes your wallpaper to most upvoted image of the day on [/r/wallpaper](https://www.reddit.com/r/wallpaper/) or from any other subreddit. - **Run it on startup for new wallpaper on every session.** -*Supported: Linux (gnome, kde, mate, lxde), Windows and OS X* +_Supported: Linux (gnome, kde, mate, lxde), Windows and OS X_ + +## Dependencies -Dependencies -======= Make sure you have [Python3](https://www.python.org/downloads/) installed and PATH variable set. -Ubuntu ------- -If you don't have ```pip ``` for Python: +### Quick setup with uv (optional but fast) + +[uv](https://github.com/astral-sh/uv) is a modern, extremely fast Python package/dependency manager. This repo already includes a `pyproject.toml`, `requirements.txt` and a lock file `uv.lock`, so you can reproduce the exact environment quickly. + +Install uv (one time): + +```bash +curl -Ls https://astral.sh/uv/install.sh | sh ``` -sudo apt-get install python-pip + +Sync (create a virtual env and install dependencies): + +```bash +uv sync ``` -You will need modules ```requests``` and ```praw``` installed, which are in requirements.txt: +Run the script (uv will use the managed virtualenv automatically): +```bash +uv run python change_wallpaper_reddit.py --subreddit art ``` -pip install -r requirements.txt + +You can omit `python` and pass arguments directly: + +```bash +uv run change_wallpaper_reddit.py --time week --sort top ``` -Arch ------- -If you don't have ```pip``` for Python: +To upgrade dependencies (respecting version constraints): + +```bash +uv lock --upgrade +uv sync +``` + +If you prefer traditional `pip`, follow the OS specific instructions below. + +### Ubuntu + +If you don't have `pip` for Python: + +```bash +sudo apt-get install python-pip +``` + +You will need modules `requests` and `praw` installed, which are in requirements.txt: + +```bash +pip install -r requirements.txt ``` + +### Arch + +If you don't have `pip` for Python: + +```bash pacman -S python-pip ``` + or, with yay: -``` + +```bash yay -S python-pip ``` + Then just install the requirements.txt with: -``` + +```bash pip install -r requirements.txt ``` -Windows ------- -Follow [this guide](https://pip.pypa.io/en/stable/installing/) to install ```pip``` and configure PATH variable. +### Windows + +Follow [this guide](https://pip.pypa.io/en/stable/installing/) to install `pip` and configure PATH variable. The rest is the same. -Using script -======= +## Using script + First, you'll need to configure the _credentials.json_ file with your personal Reddit API. Your api_key will be the Reddit API secret and your client_id the first and smaller code: ![Reddit API](https://camo.githubusercontent.com/d53f92cd85d1279a239444acee25179e8e6d8bb5/687474703a2f2f692e696d6775722e636f6d2f65326b4f5231612e706e67) Then, in the current project folder, run: -``` + +```bash python change_wallpaper_reddit.py ``` If you wanna use other subreddit, include argument with the subreddit name: -``` + +```bash python change_wallpaper_reddit.py --subreddit art ``` -If you don't want to change your wallpaper daily, you can use hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: ```hour```, ```week```, ```month```, ```year``` to the script. +If you don't want to change your wallpaper daily, you can use hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: `hour`, `week`, `month`, `year` to the script. Example: -``` + +```bash python change_wallpaper_reddit.py --time week ``` -If you want to choose which wallpaper appears, you can sort posts by adding the arguments: ```hot```, ```top```, ```new``` to the script. +If you want to choose which wallpaper appears, you can sort posts by adding the arguments: `hot`, `top`, `new` to the script. Example: -``` + +```bash python change_wallpaper_reddit.py --sort top ``` -NSFW images are disabled by default, to enable them add ```--nsfw```. +NSFW images are disabled by default, to enable them add `--nsfw`. -On OS X, you can specify display number with option ```--display```. Use 0 for all display (default), 1 for main display and so on. +On OS X, you can specify display number with option `--display`. Use 0 for all display (default), 1 for main display and so on. -To change default location where image will be saved, use ```--output folder/subfolder```. +To change default location where image will be saved, use `--output folder/subfolder`. + +## Running on startup + +### Ubuntu (startup) -Running on startup -======= -Ubuntu ------- To make managment of the script simple, we can accomplish this using built-in Startup Applications. ![Startup Applications](http://i.imgur.com/NDFmFd9.png) - Click on Add. ![Add new startup command](http://i.imgur.com/uFqQ8ky.png) -Note: you can use ```--subreddit``` and ```--time``` arguments here aswell. +Note: you can use `--subreddit` and `--time` arguments here aswell. +### Windows (startup) -Windows ------- We will be using Task Scheduler for this. You can find it in Windows search. -Once you open it, click on ```Create Basic Task``` +Once you open it, click on `Create Basic Task` Follow the procedure. ![Procedure](http://i.imgur.com/1uZMpyc.png) @@ -112,31 +157,29 @@ Follow the procedure. ![Procedure](http://i.imgur.com/zOCCfQI.png) -In ```Add arguments``` field type the location of the script. Example +In `Add arguments` field type the location of the script. Example -``` +```powershell "D:\change_wallpaper_reddit.py" ``` or -``` +```powershell "D:\change_wallpaper_reddit.py" --subreddit art --time week ``` -Running every minute or hour -======= +## Running every minute or hour Look into using cronjobs on Linux or Task Scheduler on Windows for performing this. -Configuration file -======= +## Configuration file -Instead of writing arguments every time you run the script, you can also use configuration file which should be located at ```~/.config/change_wallpaper_reddit.rc```. +Instead of writing arguments every time you run the script, you can also use configuration file which should be located at `~/.config/change_wallpaper_reddit.rc`. Example of configuration file: -``` +```ini subreddit=art time=day sort=top diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..83e5cf4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[project] +name = "daily-reddit-wallpaper" +version = "0.1.0" +description = "This script changes your wallpaper to most upvoted image of the day on Reddit." +readme = "README.md" +requires-python = ">=3.11" +dependencies = [ + "decorator==5.2.1", + "nose2==0.15.1", + "praw==7.8.1", + "requests==2.32.5", + "six==1.17.0", + "update-checker==0.18.0", +] diff --git a/requirements.txt b/requirements.txt index 5eadc95..2975809 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==5.2.1 praw==7.8.1 -requests==2.32.4 +requests==2.32.5 six==1.17.0 update-checker==0.18.0 nose2==0.15.1 diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..8b3f6c4 --- /dev/null +++ b/uv.lock @@ -0,0 +1,195 @@ +version = 1 +revision = 3 +requires-python = ">=3.11" + +[[package]] +name = "certifi" +version = "2025.8.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/dc/67/960ebe6bf230a96cda2e0abcf73af550ec4f090005363542f0765df162e0/certifi-2025.8.3.tar.gz", hash = "sha256:e564105f78ded564e3ae7c923924435e1daa7463faeab5bb932bc53ffae63407", size = 162386, upload-time = "2025-08-03T03:07:47.08Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e5/48/1549795ba7742c948d2ad169c1c8cdbae65bc450d6cd753d124b17c8cd32/certifi-2025.8.3-py3-none-any.whl", hash = "sha256:f6c12493cfb1b06ba2ff328595af9350c65d6644968e5d3a2ffd78699af217a5", size = 161216, upload-time = "2025-08-03T03:07:45.777Z" }, +] + +[[package]] +name = "charset-normalizer" +version = "3.4.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/83/2d/5fd176ceb9b2fc619e63405525573493ca23441330fcdaee6bef9460e924/charset_normalizer-3.4.3.tar.gz", hash = "sha256:6fce4b8500244f6fcb71465d4a4930d132ba9ab8e71a7859e6a5d59851068d14", size = 122371, upload-time = "2025-08-09T07:57:28.46Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7f/b5/991245018615474a60965a7c9cd2b4efbaabd16d582a5547c47ee1c7730b/charset_normalizer-3.4.3-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:b256ee2e749283ef3ddcff51a675ff43798d92d746d1a6e4631bf8c707d22d0b", size = 204483, upload-time = "2025-08-09T07:55:53.12Z" }, + { url = "https://files.pythonhosted.org/packages/c7/2a/ae245c41c06299ec18262825c1569c5d3298fc920e4ddf56ab011b417efd/charset_normalizer-3.4.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:13faeacfe61784e2559e690fc53fa4c5ae97c6fcedb8eb6fb8d0a15b475d2c64", size = 145520, upload-time = "2025-08-09T07:55:54.712Z" }, + { url = "https://files.pythonhosted.org/packages/3a/a4/b3b6c76e7a635748c4421d2b92c7b8f90a432f98bda5082049af37ffc8e3/charset_normalizer-3.4.3-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:00237675befef519d9af72169d8604a067d92755e84fe76492fef5441db05b91", size = 158876, upload-time = "2025-08-09T07:55:56.024Z" }, + { url = "https://files.pythonhosted.org/packages/e2/e6/63bb0e10f90a8243c5def74b5b105b3bbbfb3e7bb753915fe333fb0c11ea/charset_normalizer-3.4.3-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:585f3b2a80fbd26b048a0be90c5aae8f06605d3c92615911c3a2b03a8a3b796f", size = 156083, upload-time = "2025-08-09T07:55:57.582Z" }, + { url = "https://files.pythonhosted.org/packages/87/df/b7737ff046c974b183ea9aa111b74185ac8c3a326c6262d413bd5a1b8c69/charset_normalizer-3.4.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0e78314bdc32fa80696f72fa16dc61168fda4d6a0c014e0380f9d02f0e5d8a07", size = 150295, upload-time = "2025-08-09T07:55:59.147Z" }, + { url = "https://files.pythonhosted.org/packages/61/f1/190d9977e0084d3f1dc169acd060d479bbbc71b90bf3e7bf7b9927dec3eb/charset_normalizer-3.4.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:96b2b3d1a83ad55310de8c7b4a2d04d9277d5591f40761274856635acc5fcb30", size = 148379, upload-time = "2025-08-09T07:56:00.364Z" }, + { url = "https://files.pythonhosted.org/packages/4c/92/27dbe365d34c68cfe0ca76f1edd70e8705d82b378cb54ebbaeabc2e3029d/charset_normalizer-3.4.3-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:939578d9d8fd4299220161fdd76e86c6a251987476f5243e8864a7844476ba14", size = 160018, upload-time = "2025-08-09T07:56:01.678Z" }, + { url = "https://files.pythonhosted.org/packages/99/04/baae2a1ea1893a01635d475b9261c889a18fd48393634b6270827869fa34/charset_normalizer-3.4.3-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:fd10de089bcdcd1be95a2f73dbe6254798ec1bda9f450d5828c96f93e2536b9c", size = 157430, upload-time = "2025-08-09T07:56:02.87Z" }, + { url = "https://files.pythonhosted.org/packages/2f/36/77da9c6a328c54d17b960c89eccacfab8271fdaaa228305330915b88afa9/charset_normalizer-3.4.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:1e8ac75d72fa3775e0b7cb7e4629cec13b7514d928d15ef8ea06bca03ef01cae", size = 151600, upload-time = "2025-08-09T07:56:04.089Z" }, + { url = "https://files.pythonhosted.org/packages/64/d4/9eb4ff2c167edbbf08cdd28e19078bf195762e9bd63371689cab5ecd3d0d/charset_normalizer-3.4.3-cp311-cp311-win32.whl", hash = "sha256:6cf8fd4c04756b6b60146d98cd8a77d0cdae0e1ca20329da2ac85eed779b6849", size = 99616, upload-time = "2025-08-09T07:56:05.658Z" }, + { url = "https://files.pythonhosted.org/packages/f4/9c/996a4a028222e7761a96634d1820de8a744ff4327a00ada9c8942033089b/charset_normalizer-3.4.3-cp311-cp311-win_amd64.whl", hash = "sha256:31a9a6f775f9bcd865d88ee350f0ffb0e25936a7f930ca98995c05abf1faf21c", size = 107108, upload-time = "2025-08-09T07:56:07.176Z" }, + { url = "https://files.pythonhosted.org/packages/e9/5e/14c94999e418d9b87682734589404a25854d5f5d0408df68bc15b6ff54bb/charset_normalizer-3.4.3-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:e28e334d3ff134e88989d90ba04b47d84382a828c061d0d1027b1b12a62b39b1", size = 205655, upload-time = "2025-08-09T07:56:08.475Z" }, + { url = "https://files.pythonhosted.org/packages/7d/a8/c6ec5d389672521f644505a257f50544c074cf5fc292d5390331cd6fc9c3/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0cacf8f7297b0c4fcb74227692ca46b4a5852f8f4f24b3c766dd94a1075c4884", size = 146223, upload-time = "2025-08-09T07:56:09.708Z" }, + { url = "https://files.pythonhosted.org/packages/fc/eb/a2ffb08547f4e1e5415fb69eb7db25932c52a52bed371429648db4d84fb1/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c6fd51128a41297f5409deab284fecbe5305ebd7e5a1f959bee1c054622b7018", size = 159366, upload-time = "2025-08-09T07:56:11.326Z" }, + { url = "https://files.pythonhosted.org/packages/82/10/0fd19f20c624b278dddaf83b8464dcddc2456cb4b02bb902a6da126b87a1/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:3cfb2aad70f2c6debfbcb717f23b7eb55febc0bb23dcffc0f076009da10c6392", size = 157104, upload-time = "2025-08-09T07:56:13.014Z" }, + { url = "https://files.pythonhosted.org/packages/16/ab/0233c3231af734f5dfcf0844aa9582d5a1466c985bbed6cedab85af9bfe3/charset_normalizer-3.4.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1606f4a55c0fd363d754049cdf400175ee96c992b1f8018b993941f221221c5f", size = 151830, upload-time = "2025-08-09T07:56:14.428Z" }, + { url = "https://files.pythonhosted.org/packages/ae/02/e29e22b4e02839a0e4a06557b1999d0a47db3567e82989b5bb21f3fbbd9f/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:027b776c26d38b7f15b26a5da1044f376455fb3766df8fc38563b4efbc515154", size = 148854, upload-time = "2025-08-09T07:56:16.051Z" }, + { url = "https://files.pythonhosted.org/packages/05/6b/e2539a0a4be302b481e8cafb5af8792da8093b486885a1ae4d15d452bcec/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:42e5088973e56e31e4fa58eb6bd709e42fc03799c11c42929592889a2e54c491", size = 160670, upload-time = "2025-08-09T07:56:17.314Z" }, + { url = "https://files.pythonhosted.org/packages/31/e7/883ee5676a2ef217a40ce0bffcc3d0dfbf9e64cbcfbdf822c52981c3304b/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_s390x.whl", hash = "sha256:cc34f233c9e71701040d772aa7490318673aa7164a0efe3172b2981218c26d93", size = 158501, upload-time = "2025-08-09T07:56:18.641Z" }, + { url = "https://files.pythonhosted.org/packages/c1/35/6525b21aa0db614cf8b5792d232021dca3df7f90a1944db934efa5d20bb1/charset_normalizer-3.4.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:320e8e66157cc4e247d9ddca8e21f427efc7a04bbd0ac8a9faf56583fa543f9f", size = 153173, upload-time = "2025-08-09T07:56:20.289Z" }, + { url = "https://files.pythonhosted.org/packages/50/ee/f4704bad8201de513fdc8aac1cabc87e38c5818c93857140e06e772b5892/charset_normalizer-3.4.3-cp312-cp312-win32.whl", hash = "sha256:fb6fecfd65564f208cbf0fba07f107fb661bcd1a7c389edbced3f7a493f70e37", size = 99822, upload-time = "2025-08-09T07:56:21.551Z" }, + { url = "https://files.pythonhosted.org/packages/39/f5/3b3836ca6064d0992c58c7561c6b6eee1b3892e9665d650c803bd5614522/charset_normalizer-3.4.3-cp312-cp312-win_amd64.whl", hash = "sha256:86df271bf921c2ee3818f0522e9a5b8092ca2ad8b065ece5d7d9d0e9f4849bcc", size = 107543, upload-time = "2025-08-09T07:56:23.115Z" }, + { url = "https://files.pythonhosted.org/packages/65/ca/2135ac97709b400c7654b4b764daf5c5567c2da45a30cdd20f9eefe2d658/charset_normalizer-3.4.3-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:14c2a87c65b351109f6abfc424cab3927b3bdece6f706e4d12faaf3d52ee5efe", size = 205326, upload-time = "2025-08-09T07:56:24.721Z" }, + { url = "https://files.pythonhosted.org/packages/71/11/98a04c3c97dd34e49c7d247083af03645ca3730809a5509443f3c37f7c99/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:41d1fc408ff5fdfb910200ec0e74abc40387bccb3252f3f27c0676731df2b2c8", size = 146008, upload-time = "2025-08-09T07:56:26.004Z" }, + { url = "https://files.pythonhosted.org/packages/60/f5/4659a4cb3c4ec146bec80c32d8bb16033752574c20b1252ee842a95d1a1e/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:1bb60174149316da1c35fa5233681f7c0f9f514509b8e399ab70fea5f17e45c9", size = 159196, upload-time = "2025-08-09T07:56:27.25Z" }, + { url = "https://files.pythonhosted.org/packages/86/9e/f552f7a00611f168b9a5865a1414179b2c6de8235a4fa40189f6f79a1753/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:30d006f98569de3459c2fc1f2acde170b7b2bd265dc1943e87e1a4efe1b67c31", size = 156819, upload-time = "2025-08-09T07:56:28.515Z" }, + { url = "https://files.pythonhosted.org/packages/7e/95/42aa2156235cbc8fa61208aded06ef46111c4d3f0de233107b3f38631803/charset_normalizer-3.4.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:416175faf02e4b0810f1f38bcb54682878a4af94059a1cd63b8747244420801f", size = 151350, upload-time = "2025-08-09T07:56:29.716Z" }, + { url = "https://files.pythonhosted.org/packages/c2/a9/3865b02c56f300a6f94fc631ef54f0a8a29da74fb45a773dfd3dcd380af7/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:6aab0f181c486f973bc7262a97f5aca3ee7e1437011ef0c2ec04b5a11d16c927", size = 148644, upload-time = "2025-08-09T07:56:30.984Z" }, + { url = "https://files.pythonhosted.org/packages/77/d9/cbcf1a2a5c7d7856f11e7ac2d782aec12bdfea60d104e60e0aa1c97849dc/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:fdabf8315679312cfa71302f9bd509ded4f2f263fb5b765cf1433b39106c3cc9", size = 160468, upload-time = "2025-08-09T07:56:32.252Z" }, + { url = "https://files.pythonhosted.org/packages/f6/42/6f45efee8697b89fda4d50580f292b8f7f9306cb2971d4b53f8914e4d890/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_s390x.whl", hash = "sha256:bd28b817ea8c70215401f657edef3a8aa83c29d447fb0b622c35403780ba11d5", size = 158187, upload-time = "2025-08-09T07:56:33.481Z" }, + { url = "https://files.pythonhosted.org/packages/70/99/f1c3bdcfaa9c45b3ce96f70b14f070411366fa19549c1d4832c935d8e2c3/charset_normalizer-3.4.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:18343b2d246dc6761a249ba1fb13f9ee9a2bcd95decc767319506056ea4ad4dc", size = 152699, upload-time = "2025-08-09T07:56:34.739Z" }, + { url = "https://files.pythonhosted.org/packages/a3/ad/b0081f2f99a4b194bcbb1934ef3b12aa4d9702ced80a37026b7607c72e58/charset_normalizer-3.4.3-cp313-cp313-win32.whl", hash = "sha256:6fb70de56f1859a3f71261cbe41005f56a7842cc348d3aeb26237560bfa5e0ce", size = 99580, upload-time = "2025-08-09T07:56:35.981Z" }, + { url = "https://files.pythonhosted.org/packages/9a/8f/ae790790c7b64f925e5c953b924aaa42a243fb778fed9e41f147b2a5715a/charset_normalizer-3.4.3-cp313-cp313-win_amd64.whl", hash = "sha256:cf1ebb7d78e1ad8ec2a8c4732c7be2e736f6e5123a4146c5b89c9d1f585f8cef", size = 107366, upload-time = "2025-08-09T07:56:37.339Z" }, + { url = "https://files.pythonhosted.org/packages/8e/91/b5a06ad970ddc7a0e513112d40113e834638f4ca1120eb727a249fb2715e/charset_normalizer-3.4.3-cp314-cp314-macosx_10_13_universal2.whl", hash = "sha256:3cd35b7e8aedeb9e34c41385fda4f73ba609e561faedfae0a9e75e44ac558a15", size = 204342, upload-time = "2025-08-09T07:56:38.687Z" }, + { url = "https://files.pythonhosted.org/packages/ce/ec/1edc30a377f0a02689342f214455c3f6c2fbedd896a1d2f856c002fc3062/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b89bc04de1d83006373429975f8ef9e7932534b8cc9ca582e4db7d20d91816db", size = 145995, upload-time = "2025-08-09T07:56:40.048Z" }, + { url = "https://files.pythonhosted.org/packages/17/e5/5e67ab85e6d22b04641acb5399c8684f4d37caf7558a53859f0283a650e9/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:2001a39612b241dae17b4687898843f254f8748b796a2e16f1051a17078d991d", size = 158640, upload-time = "2025-08-09T07:56:41.311Z" }, + { url = "https://files.pythonhosted.org/packages/f1/e5/38421987f6c697ee3722981289d554957c4be652f963d71c5e46a262e135/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:8dcfc373f888e4fb39a7bc57e93e3b845e7f462dacc008d9749568b1c4ece096", size = 156636, upload-time = "2025-08-09T07:56:43.195Z" }, + { url = "https://files.pythonhosted.org/packages/a0/e4/5a075de8daa3ec0745a9a3b54467e0c2967daaaf2cec04c845f73493e9a1/charset_normalizer-3.4.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:18b97b8404387b96cdbd30ad660f6407799126d26a39ca65729162fd810a99aa", size = 150939, upload-time = "2025-08-09T07:56:44.819Z" }, + { url = "https://files.pythonhosted.org/packages/02/f7/3611b32318b30974131db62b4043f335861d4d9b49adc6d57c1149cc49d4/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ccf600859c183d70eb47e05a44cd80a4ce77394d1ac0f79dbd2dd90a69a3a049", size = 148580, upload-time = "2025-08-09T07:56:46.684Z" }, + { url = "https://files.pythonhosted.org/packages/7e/61/19b36f4bd67f2793ab6a99b979b4e4f3d8fc754cbdffb805335df4337126/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:53cd68b185d98dde4ad8990e56a58dea83a4162161b1ea9272e5c9182ce415e0", size = 159870, upload-time = "2025-08-09T07:56:47.941Z" }, + { url = "https://files.pythonhosted.org/packages/06/57/84722eefdd338c04cf3030ada66889298eaedf3e7a30a624201e0cbe424a/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_s390x.whl", hash = "sha256:30a96e1e1f865f78b030d65241c1ee850cdf422d869e9028e2fc1d5e4db73b92", size = 157797, upload-time = "2025-08-09T07:56:49.756Z" }, + { url = "https://files.pythonhosted.org/packages/72/2a/aff5dd112b2f14bcc3462c312dce5445806bfc8ab3a7328555da95330e4b/charset_normalizer-3.4.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d716a916938e03231e86e43782ca7878fb602a125a91e7acb8b5112e2e96ac16", size = 152224, upload-time = "2025-08-09T07:56:51.369Z" }, + { url = "https://files.pythonhosted.org/packages/b7/8c/9839225320046ed279c6e839d51f028342eb77c91c89b8ef2549f951f3ec/charset_normalizer-3.4.3-cp314-cp314-win32.whl", hash = "sha256:c6dbd0ccdda3a2ba7c2ecd9d77b37f3b5831687d8dc1b6ca5f56a4880cc7b7ce", size = 100086, upload-time = "2025-08-09T07:56:52.722Z" }, + { url = "https://files.pythonhosted.org/packages/ee/7a/36fbcf646e41f710ce0a563c1c9a343c6edf9be80786edeb15b6f62e17db/charset_normalizer-3.4.3-cp314-cp314-win_amd64.whl", hash = "sha256:73dc19b562516fc9bcf6e5d6e596df0b4eb98d87e4f79f3ae71840e6ed21361c", size = 107400, upload-time = "2025-08-09T07:56:55.172Z" }, + { url = "https://files.pythonhosted.org/packages/8a/1f/f041989e93b001bc4e44bb1669ccdcf54d3f00e628229a85b08d330615c5/charset_normalizer-3.4.3-py3-none-any.whl", hash = "sha256:ce571ab16d890d23b5c278547ba694193a45011ff86a9162a71307ed9f86759a", size = 53175, upload-time = "2025-08-09T07:57:26.864Z" }, +] + +[[package]] +name = "daily-reddit-wallpaper" +version = "0.1.0" +source = { virtual = "." } +dependencies = [ + { name = "decorator" }, + { name = "nose2" }, + { name = "praw" }, + { name = "requests" }, + { name = "six" }, + { name = "update-checker" }, +] + +[package.metadata] +requires-dist = [ + { name = "decorator", specifier = "==5.2.1" }, + { name = "nose2", specifier = "==0.15.1" }, + { name = "praw", specifier = "==7.8.1" }, + { name = "requests", specifier = "==2.32.5" }, + { name = "six", specifier = "==1.17.0" }, + { name = "update-checker", specifier = "==0.18.0" }, +] + +[[package]] +name = "decorator" +version = "5.2.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/43/fa/6d96a0978d19e17b68d634497769987b16c8f4cd0a7a05048bec693caa6b/decorator-5.2.1.tar.gz", hash = "sha256:65f266143752f734b0a7cc83c46f4618af75b8c5911b00ccb61d0ac9b6da0360", size = 56711, upload-time = "2025-02-24T04:41:34.073Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4e/8c/f3147f5c4b73e7550fe5f9352eaa956ae838d5c51eb58e7a25b9f3e2643b/decorator-5.2.1-py3-none-any.whl", hash = "sha256:d316bb415a2d9e2d2b3abcc4084c6502fc09240e292cd76a76afc106a1c8e04a", size = 9190, upload-time = "2025-02-24T04:41:32.565Z" }, +] + +[[package]] +name = "idna" +version = "3.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490, upload-time = "2024-09-15T18:07:39.745Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442, upload-time = "2024-09-15T18:07:37.964Z" }, +] + +[[package]] +name = "nose2" +version = "0.15.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/9b/a6/f29c21026c40476ce3994ac55e16ef60b9c1d2a88d02c3fc20b07d253dab/nose2-0.15.1.tar.gz", hash = "sha256:36770f519df5becd3cbfe0bee4abbfbf9b9f6b4eb4e03361d282b7efcfc4f0df", size = 169809, upload-time = "2024-06-01T03:20:11.435Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/87/e6/6babe53a1dbfa55f6d30eb7408f4c4994658e5f27e3dbbb2b437912e5a32/nose2-0.15.1-py3-none-any.whl", hash = "sha256:564450c0c4f1602dfe171902ceb4726cc56658af7a620ae1826f1ffc86b09a86", size = 211274, upload-time = "2024-06-01T03:20:04.423Z" }, +] + +[[package]] +name = "praw" +version = "7.8.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "prawcore" }, + { name = "update-checker" }, + { name = "websocket-client" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/4c/52/7dd0b3d9ccb78e90236420ef6c51b6d9b2400a7229442f0cfcf2258cce21/praw-7.8.1.tar.gz", hash = "sha256:3c5767909f71e48853eb6335fef7b50a43cbe3da728cdfb16d3be92904b0a4d8", size = 154106, upload-time = "2024-10-25T21:49:33.16Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/73/ca/60ec131c3b43bff58261167045778b2509b83922ce8f935ac89d871bd3ea/praw-7.8.1-py3-none-any.whl", hash = "sha256:15917a81a06e20ff0aaaf1358481f4588449fa2421233040cb25e5c8202a3e2f", size = 189338, upload-time = "2024-10-25T21:49:31.109Z" }, +] + +[[package]] +name = "prawcore" +version = "2.4.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8a/62/d4c99cf472205f1e5da846b058435a6a7c988abf8eb6f7d632a7f32f4a77/prawcore-2.4.0.tar.gz", hash = "sha256:b7b2b5a1d04406e086ab4e79988dc794df16059862f329f4c6a43ed09986c335", size = 15862, upload-time = "2023-10-01T23:30:49.408Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/96/5c/8af904314e42d5401afcfaff69940dc448e974f80f7aa39b241a4fbf0cf1/prawcore-2.4.0-py3-none-any.whl", hash = "sha256:29af5da58d85704b439ad3c820873ad541f4535e00bb98c66f0fbcc8c603065a", size = 17203, upload-time = "2023-10-01T23:30:47.651Z" }, +] + +[[package]] +name = "requests" +version = "2.32.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "certifi" }, + { name = "charset-normalizer" }, + { name = "idna" }, + { name = "urllib3" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c9/74/b3ff8e6c8446842c3f5c837e9c3dfcfe2018ea6ecef224c710c85ef728f4/requests-2.32.5.tar.gz", hash = "sha256:dbba0bac56e100853db0ea71b82b4dfd5fe2bf6d3754a8893c3af500cec7d7cf", size = 134517, upload-time = "2025-08-18T20:46:02.573Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1e/db/4254e3eabe8020b458f1a747140d32277ec7a271daf1d235b70dc0b4e6e3/requests-2.32.5-py3-none-any.whl", hash = "sha256:2462f94637a34fd532264295e186976db0f5d453d1cdd31473c85a6a161affb6", size = 64738, upload-time = "2025-08-18T20:46:00.542Z" }, +] + +[[package]] +name = "six" +version = "1.17.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" }, +] + +[[package]] +name = "update-checker" +version = "0.18.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/5c/0b/1bec4a6cc60d33ce93d11a7bcf1aeffc7ad0aa114986073411be31395c6f/update_checker-0.18.0.tar.gz", hash = "sha256:6a2d45bb4ac585884a6b03f9eade9161cedd9e8111545141e9aa9058932acb13", size = 6699, upload-time = "2020-08-04T07:08:50.429Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/0c/ba/8dd7fa5f0b1c6a8ac62f8f57f7e794160c1f86f31c6d0fb00f582372a3e4/update_checker-0.18.0-py3-none-any.whl", hash = "sha256:cbba64760a36fe2640d80d85306e8fe82b6816659190993b7bdabadee4d4bbfd", size = 7008, upload-time = "2020-08-04T07:08:49.51Z" }, +] + +[[package]] +name = "urllib3" +version = "2.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/15/22/9ee70a2574a4f4599c47dd506532914ce044817c7752a79b6a51286319bc/urllib3-2.5.0.tar.gz", hash = "sha256:3fc47733c7e419d4bc3f6b3dc2b4f890bb743906a30d56ba4a5bfa4bbff92760", size = 393185, upload-time = "2025-06-18T14:07:41.644Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a7/c2/fe1e52489ae3122415c51f387e221dd0773709bad6c6cdaa599e8a2c5185/urllib3-2.5.0-py3-none-any.whl", hash = "sha256:e6b01673c0fa6a13e374b50871808eb3bf7046c4b125b216f6bf1cc604cff0dc", size = 129795, upload-time = "2025-06-18T14:07:40.39Z" }, +] + +[[package]] +name = "websocket-client" +version = "1.8.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e6/30/fba0d96b4b5fbf5948ed3f4681f7da2f9f64512e1d303f94b4cc174c24a5/websocket_client-1.8.0.tar.gz", hash = "sha256:3239df9f44da632f96012472805d40a23281a991027ce11d2f45a6f24ac4c3da", size = 54648, upload-time = "2024-04-23T22:16:16.976Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/5a/84/44687a29792a70e111c5c477230a72c4b957d88d16141199bf9acb7537a3/websocket_client-1.8.0-py3-none-any.whl", hash = "sha256:17b44cc997f5c498e809b22cdf2d9c7a9e71c02c8cc2b6c56e7c2d1239bfa526", size = 58826, upload-time = "2024-04-23T22:16:14.422Z" }, +] From 65f7ebb438124b9008b41bfeff6c9f4190dd83e3 Mon Sep 17 00:00:00 2001 From: Federico Torrielli Date: Mon, 1 Sep 2025 16:17:21 +0200 Subject: [PATCH 35/36] docs: update README.md to enhance clarity and structure of installation and usage instructions --- README.md | 250 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 163 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 1cf59f0..71238c7 100644 --- a/README.md +++ b/README.md @@ -1,186 +1,262 @@ # Daily Reddit Wallpaper -[![Build Status](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper.svg?branch=master)](https://travis-ci.org/federicotorrielli/Daily-Reddit-Wallpaper) +Automated, scriptable, multi‑platform Reddit wallpaper fetcher. -This script changes your wallpaper to most upvoted image of the day on [/r/wallpaper](https://www.reddit.com/r/wallpaper/) or from any other subreddit. +[![Python](https://img.shields.io/badge/Python->=3.11-blue)](https://www.python.org/) +[![License](https://img.shields.io/badge/License-MIT-green)](LICENSE) +[![Reddit API](https://img.shields.io/badge/API-Reddit-orange)](https://www.reddit.com/dev/api/) -**Run it on startup for new wallpaper on every session.** +Fetch and set a fresh wallpaper from any subreddit (default: [/r/wallpaper](https://www.reddit.com/r/wallpaper/)). Runs well as a cron/systemd/Task Scheduler job. -_Supported: Linux (gnome, kde, mate, lxde), Windows and OS X_ +Supported desktops: GNOME, KDE Plasma, MATE, XFCE, LXDE/Lubuntu (pcmanfm), i3/other WM (via `feh`), macOS, Windows. -## Dependencies +## Features -Make sure you have [Python3](https://www.python.org/downloads/) installed and PATH variable set. +- Multiple sort modes: hot, top (with hour/day/week/month/year/all), new +- Flair filtering (`--flair "Desktop"`) +- Randomization within current listing (`--random`) +- NSFW opt‑in (`--nsfw`) +- Config file override (XDG config path on Linux) +- Imgur single‑image link support +- Download dedupe & resumable safe writes +- Works across common Linux DEs, macOS displays, Windows +- Lockfile (`uv.lock`) for reproducible env when using `uv` -### Quick setup with uv (optional but fast) +## Install / Setup -[uv](https://github.com/astral-sh/uv) is a modern, extremely fast Python package/dependency manager. This repo already includes a `pyproject.toml`, `requirements.txt` and a lock file `uv.lock`, so you can reproduce the exact environment quickly. +Pick one method: -Install uv (one time): +### 1. uv (fast, reproducible) + +Install uv (one-time): ```bash curl -Ls https://astral.sh/uv/install.sh | sh ``` -Sync (create a virtual env and install dependencies): +Sync dependencies (creates `.venv`): ```bash uv sync ``` -Run the script (uv will use the managed virtualenv automatically): +Run: ```bash -uv run python change_wallpaper_reddit.py --subreddit art +uv run change_wallpaper_reddit.py --subreddit art ``` -You can omit `python` and pass arguments directly: +Upgrade (respecting version constraints): ```bash -uv run change_wallpaper_reddit.py --time week --sort top +uv lock --upgrade && uv sync ``` -To upgrade dependencies (respecting version constraints): +### 2. pip (classic) ```bash -uv lock --upgrade -uv sync +python -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt +python change_wallpaper_reddit.py ``` -If you prefer traditional `pip`, follow the OS specific instructions below. +### 3. pipx (isolated, if published later) + +Not yet on PyPI; for now clone & use method 1 or 2. (Future improvement: add console script entry point.) -### Ubuntu +## Credentials -If you don't have `pip` for Python: +Create `credentials.json` beside the script: + +```jsonc +{ + "client_id": "YOUR_REDDIT_APP_CLIENT_ID", + "api_key": "YOUR_REDDIT_APP_SECRET" +} +``` + +Or pass inline: ```bash -sudo apt-get install python-pip +uv run change_wallpaper_reddit.py --client-id XXX --api-key YYY ``` -You will need modules `requests` and `praw` installed, which are in requirements.txt: +Create a Reddit script app at . + +## Usage + +Basic: ```bash -pip install -r requirements.txt +python change_wallpaper_reddit.py ``` -### Arch +Top of the week from r/art, save somewhere else, random inside top 30: + +```bash +python change_wallpaper_reddit.py -s art --sort top --time week -l 30 --random -o MyWallpapers +``` -If you don't have `pip` for Python: +Filter by flair (case-insensitive contains): ```bash -pacman -S python-pip +python change_wallpaper_reddit.py --flair "Desktop" ``` -or, with yay: +macOS main display only: ```bash -yay -S python-pip +python change_wallpaper_reddit.py --display 1 ``` -Then just install the requirements.txt with: +Allow NSFW: ```bash -pip install -r requirements.txt +python change_wallpaper_reddit.py --nsfw ``` -### Windows +### All CLI Options -Follow [this guide](https://pip.pypa.io/en/stable/installing/) to install `pip` and configure PATH variable. -The rest is the same. +| Flag | Long | Type | Default | Description | +| ---- | ----------- | ---- | ---------- | ---------------------------------------------------- | +| -s | --subreddit | str | wallpaper | Subreddit name | +| -t | --time | str | all | Time filter (top only): hour/day/week/month/year/all | +| -n | --nsfw | flag | False | Enable NSFW posts | +| -d | --display | int | 0 | macOS display (0 = all) | +| -o | --output | str | Wallpapers | Relative directory inside home to store images | +| | --sort | str | hot | hot/top/new | +| -l | --limit | int | 20 | Listing fetch limit | +| -r | --random | flag | False | Shuffle the fetched list before picking | +| -f | --flair | str | (empty) | Filter by flair substring | +| | --client-id | str | | Override Reddit client id | +| | --api-key | str | | Override Reddit client secret | -## Using script +Exit codes: 0 success, non‑zero on failure (missing creds, no image, network error). -First, you'll need to configure the _credentials.json_ file with your personal Reddit API. -Your api_key will be the Reddit API secret and your client_id the first and smaller code: +## Configuration File -![Reddit API](https://camo.githubusercontent.com/d53f92cd85d1279a239444acee25179e8e6d8bb5/687474703a2f2f692e696d6775722e636f6d2f65326b4f5231612e706e67) +Optional file (Linux): `~/.config/change_wallpaper_reddit.rc` +On Windows/macOS (fallback): same directory as script. -Then, in the current project folder, run: +Example: -```bash -python change_wallpaper_reddit.py +```ini +subreddit=wallpaper +sort=top +time=day +limit=40 +random=true +nsfw=false +flair=Desktop +output=Wallpapers +display=0 ``` -If you wanna use other subreddit, include argument with the subreddit name: +CLI flags override file values. -```bash -python change_wallpaper_reddit.py --subreddit art -``` +## Scheduling -If you don't want to change your wallpaper daily, you can use hourly, weekly, monthly or yearly wallpaper too by adding one of the following arguments: `hour`, `week`, `month`, `year` to the script. +### systemd user timer (recommended on modern Linux) -Example: +`~/.config/systemd/user/reddit-wallpaper.service`: -```bash -python change_wallpaper_reddit.py --time week +```ini +[Unit] +Description=Update Reddit wallpaper + +[Service] +Type=oneshot +WorkingDirectory=%h/path/to/Daily-Reddit-Wallpaper +ExecStart=%h/path/to/Daily-Reddit-Wallpaper/.venv/bin/python change_wallpaper_reddit.py --sort top --time day ``` -If you want to choose which wallpaper appears, you can sort posts by adding the arguments: `hot`, `top`, `new` to the script. +`~/.config/systemd/user/reddit-wallpaper.timer`: -Example: +```ini +[Unit] +Description=Run wallpaper updater daily -```bash -python change_wallpaper_reddit.py --sort top +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target ``` -NSFW images are disabled by default, to enable them add `--nsfw`. +Enable: -On OS X, you can specify display number with option `--display`. Use 0 for all display (default), 1 for main display and so on. +```bash +systemctl --user daemon-reload +systemctl --user enable --now reddit-wallpaper.timer +``` -To change default location where image will be saved, use `--output folder/subfolder`. +### Cron (legacy) -## Running on startup +Daily at 09:00: -### Ubuntu (startup) +```cron +0 9 * * * /usr/bin/env bash -lc 'cd "$HOME/path/to/Daily-Reddit-Wallpaper" && uv run change_wallpaper_reddit.py --sort top --time day' +``` -To make managment of the script simple, we can accomplish this using built-in Startup Applications. +Hourly: -![Startup Applications](http://i.imgur.com/NDFmFd9.png) +```cron +0 * * * * /usr/bin/env bash -lc 'cd "$HOME/path/to/Daily-Reddit-Wallpaper" && uv run change_wallpaper_reddit.py' +``` -Click on Add. +### Windows Task Scheduler -![Add new startup command](http://i.imgur.com/uFqQ8ky.png) +Create a basic task -> trigger (daily / logon) -> Action: Start a Program: -Note: you can use `--subreddit` and `--time` arguments here aswell. +Program/script: -### Windows (startup) +```text +python +``` -We will be using Task Scheduler for this. You can find it in Windows search. -Once you open it, click on `Create Basic Task` -Follow the procedure. +Arguments: -![Procedure](http://i.imgur.com/1uZMpyc.png) +```text +"C:\\path\\to\\change_wallpaper_reddit.py" --sort top --time day +``` -![Procedure](http://i.imgur.com/3ApvF6W.png) +Or use a virtualenv's python path. -![Procedure](http://i.imgur.com/fPdwcyg.png) +## Desktop Environment Notes -![Procedure](http://i.imgur.com/zOCCfQI.png) +- KDE: requires `qdbus` (usually present) +- i3/WM: needs `feh` installed (`sudo apt install feh`) +- XFCE: uses `xfconf-query` +- macOS: uses AppleScript, per-display if `--display` set +- Windows: standard `SystemParametersInfoW` -In `Add arguments` field type the location of the script. Example +## Troubleshooting -```powershell -"D:\change_wallpaper_reddit.py" -``` +| Issue | Suggestion | +| ------------------------------ | --------------------------------------------------------------------- | +| No images found | Increase `--limit`, relax flair, allow NSFW if appropriate | +| Credentials error | Regenerate Reddit app secret; confirm JSON keys | +| Wallpaper not changing (Linux) | Ensure DE supported & required tools installed (`feh`, `qdbus`, etc.) | +| Cron uses old Python | Use full path to venv python or switch to systemd timer | -or +Run verbose network test: -```powershell -"D:\change_wallpaper_reddit.py" --subreddit art --time week +```bash +python - <<'PY' +import requests;print(requests.get('https://www.reddit.com/.json',headers={'User-Agent':'test'}).status_code) +PY ``` -## Running every minute or hour +## Contributing -Look into using cronjobs on Linux or Task Scheduler on Windows for performing this. +Small focused PRs welcome: docs, new DE support, packaging (entry point), tests. Open an issue first for bigger changes. Style: keep functions small & explicit. -## Configuration file +## License -Instead of writing arguments every time you run the script, you can also use configuration file which should be located at `~/.config/change_wallpaper_reddit.rc`. +MIT. See `LICENSE`. -Example of configuration file: +--- -```ini -subreddit=art -time=day -sort=top -``` +Made better with automation & reproducibility (`uv`). From e1f2e609fac65ecb4f0445d05a7fff9b93d770ed Mon Sep 17 00:00:00 2001 From: Federico Torrielli <31370059+federicotorrielli@users.noreply.github.com> Date: Mon, 1 Sep 2025 16:24:03 +0200 Subject: [PATCH 36/36] Add Jekyll GitHub Pages deployment workflow This workflow builds and deploys a Jekyll site to GitHub Pages, with necessary dependencies preinstalled. --- .github/workflows/jekyll-gh-pages.yml | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/jekyll-gh-pages.yml diff --git a/.github/workflows/jekyll-gh-pages.yml b/.github/workflows/jekyll-gh-pages.yml new file mode 100644 index 0000000..0ebd768 --- /dev/null +++ b/.github/workflows/jekyll-gh-pages.yml @@ -0,0 +1,51 @@ +# Sample workflow for building and deploying a Jekyll site to GitHub Pages +name: Deploy Jekyll with GitHub Pages dependencies preinstalled + +on: + # Runs on pushes targeting the default branch + push: + branches: ["master"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Build with Jekyll + uses: actions/jekyll-build-pages@v1 + with: + source: ./ + destination: ./_site + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4