From 25aa2a500d1def55d931e782f2f43eb9f025fe6f Mon Sep 17 00:00:00 2001 From: Jennifer Roper <29236317+jenroper@users.noreply.github.com> Date: Tue, 29 Aug 2017 19:33:27 -0400 Subject: [PATCH 01/14] Create praw.ini Adding support for PRAW 5.0 and not hard coding my personal authentication info. --- praw.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 praw.ini diff --git a/praw.ini b/praw.ini new file mode 100644 index 0000000..24f6538 --- /dev/null +++ b/praw.ini @@ -0,0 +1,3 @@ +[dailywallpaper] +client_id=REPLACE_WITH_YOUR_CLIENT_ID +client_secret=REPLACE_WITH_YOUR_CLIENT_SECRET From c86c30402cbfdc974c50b0c2376043ef6d6696c0 Mon Sep 17 00:00:00 2001 From: Jennifer Roper <29236317+jenroper@users.noreply.github.com> Date: Tue, 29 Aug 2017 19:45:17 -0400 Subject: [PATCH 02/14] Update change_wallpaper_reddit.py Adding support for praw 5.0 --- change_wallpaper_reddit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 201f0a0..7a1e87d 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -90,7 +90,7 @@ def get_top_image(sub_reddit): :sub_reddit: name of the sub reddit :return: the image link """ - submissions = sub_reddit.get_new(limit=10) if args.time == "new" else sub_reddit.get_top(params={"t": args.time}, + submissions = sub_reddit.get_new(limit=10) if args.time == "new" else sub_reddit.top(params={"t": args.time}, limit=10) for submission in submissions: ret = {"id": submission.id} @@ -163,8 +163,8 @@ def detect_desktop_environment(): supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu"] # Python Reddit Api Wrapper - r = praw.Reddit(user_agent="Get top wallpaper from /r/{subreddit} by /u/ssimunic".format(subreddit=subreddit)) - + r = praw.Reddit('dailywallpaper', user_agent="Get top wallpaper from /r/{subreddit} by /u/ssimunic".format(subreddit=subreddit)) + # Get top image link image = get_top_image(r.get_subreddit(subreddit)) if "url" not in image: From eb339915121385c9630a45471a98c0ac19ff5de5 Mon Sep 17 00:00:00 2001 From: Jennifer Roper <29236317+jenroper@users.noreply.github.com> Date: Tue, 29 Aug 2017 19:46:37 -0400 Subject: [PATCH 03/14] Update requirements.txt Updated praw version to 5.0.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1271f8b..de01863 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==4.0.10 future==0.15.2 -praw==3.5.0 +praw==5.0.1 requests==2.10.0 six==1.10.0 update-checker==0.11 From 33efd8012668b7ec9061d92a6c67911c2b65e92c Mon Sep 17 00:00:00 2001 From: jenroper Date: Tue, 29 Aug 2017 20:47:20 -0400 Subject: [PATCH 04/14] Added instructions for updating praw.ini --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 4c224a7..06cd14b 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,14 @@ The rest is the same. Using script ======= +Update praw.ini: +You need to register this app with your reddit account. +https://www.reddit.com/prefs/apps/ + +You need to copy your client id and client secret into the praw.ini file. +The id will be in the upper left corner of your app information (it will be a long alphanumeric string). +The secret will be labeled "secret". + Simply run: ``` python /home/silvio/Scripts/change_wallpaper_reddit.py From 5251a9ea7a44a65bb5943c4b0530113061700f4d Mon Sep 17 00:00:00 2001 From: Jennifer Roper Date: Tue, 29 Aug 2017 20:54:59 -0400 Subject: [PATCH 05/14] Update README.md formatting --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06cd14b..417670b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Using script ======= Update praw.ini: + You need to register this app with your reddit account. https://www.reddit.com/prefs/apps/ From 770572939b8ad7f7b11ed69f0d51d79626281017 Mon Sep 17 00:00:00 2001 From: jenroper Date: Tue, 29 Aug 2017 20:59:47 -0400 Subject: [PATCH 06/14] fixed bug getting subreddit --- 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 7a1e87d..c421939 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -166,7 +166,7 @@ def detect_desktop_environment(): r = praw.Reddit('dailywallpaper', user_agent="Get top wallpaper from /r/{subreddit} by /u/ssimunic".format(subreddit=subreddit)) # Get top image link - image = get_top_image(r.get_subreddit(subreddit)) + 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.") From fb374a50fde886612fbd9c27d4ee3e63c8a9bbd6 Mon Sep 17 00:00:00 2001 From: jenroper Date: Wed, 30 Aug 2017 17:20:14 -0400 Subject: [PATCH 07/14] fixed issue with time filter so images are selection within the specified time frame instead of all --- change_wallpaper_reddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index c421939..78ea1e4 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -90,9 +90,9 @@ def get_top_image(sub_reddit): :sub_reddit: name of the sub reddit :return: the image link """ - submissions = sub_reddit.get_new(limit=10) if args.time == "new" else sub_reddit.top(params={"t": args.time}, - limit=10) + submissions = sub_reddit.new(limit=10) if args.time == "new" else sub_reddit.top(time_filter=args.time, limit=10) for submission in submissions: + ret = {"id": submission.id} if not args.nsfw and submission.over_18: continue From 86d9998a8c4778e58ae23d80b22cbf137f11f0aa Mon Sep 17 00:00:00 2001 From: Jennifer Roper Date: Mon, 4 Sep 2017 16:51:08 -0400 Subject: [PATCH 08/14] Update README.md Added better instructions for using this script in a cron job. --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 417670b..6a5d04a 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,37 @@ or Running every minute or hour ======= -Look into using cronjobs on Linux or Task Scheduler on Windows for performing this. +You can configure this script to run at timed intervals in Windows using the Task Scheduler. + +In Linux, you can write a cronjob or an anacron script. +There are two environment variables that need to be set during the cron job or anacron script. +``` +export DISPLAY=:0 +``` + +The other variable is dependent on your desktop environment + +KDE: +``` +export KDE_FULL_SESSION=true +``` + +Gnome or Cinnamon: +``` +export GNOME_DESKTOP_SESSION_ID=anything +``` + +Lubuntu: +``` +export DESKTOP_SESSION=Lubuntu +``` + +mate: +``` +export DESKTOP_SESSION=mate +``` + +[Click here for instructions on configuring cron jobs.](https://help.ubuntu.com/community/CronHowto) Configuration file ======= From 9ce88d06a805ac985084b89c2ffebd8a8219d258 Mon Sep 17 00:00:00 2001 From: Jennifer Roper Date: Mon, 4 Sep 2017 16:52:35 -0400 Subject: [PATCH 09/14] Update README.md fixed spelling of GNOME --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a5d04a..f2aaec9 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ KDE: export KDE_FULL_SESSION=true ``` -Gnome or Cinnamon: +GNOME or Cinnamon: ``` export GNOME_DESKTOP_SESSION_ID=anything ``` From 590ee235dcb0bd4c56fb085041d049e2b43c1fc1 Mon Sep 17 00:00:00 2001 From: jenroper Date: Thu, 7 Sep 2017 08:46:24 -0400 Subject: [PATCH 10/14] Now supports image types other than .jpg --- change_wallpaper_reddit.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 78ea1e4..c592b97 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -99,8 +99,10 @@ def get_top_image(sub_reddit): url = submission.url # Strip trailing arguments (after a '?') url = re.sub(R"\?.*", "", url) + imageType = url.split('.')[-1] if url.endswith(".jpg") or url.endswith(".png"): ret["url"] = url + ret["type"] = imageType return ret # Imgur support if ("imgur.com" in url) and ("/a/" not in url) and ("/gallery/" not in url): @@ -108,6 +110,7 @@ def get_top_image(sub_reddit): url = url.rsplit("/", 1)[0] id = url.rsplit("/", 1)[1].rsplit(".", 1)[0] ret["url"] = "http://i.imgur.com/{id}.jpg".format(id=id) + ret["type"] = 'jpg' return ret @@ -178,10 +181,12 @@ 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}.jpg".format(home_dir=home_dir, save_dir=save_dir, + save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{imageType}".format(home_dir=home_dir, save_dir=save_dir, subreddit=subreddit, - id=image["id"]) + id=image["id"], + imageType=image["type"]) if os.path.isfile(save_location): sys.exit("Info: Image already exists, nothing to do, the program is" \ From c6e3b64c6f6fa638d532ba15ff3d83d305bfa688 Mon Sep 17 00:00:00 2001 From: jenroper Date: Thu, 7 Sep 2017 09:24:48 -0400 Subject: [PATCH 11/14] Now supports files on imgur other than .jpg --- change_wallpaper_reddit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index c592b97..3dc9b6b 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -109,8 +109,8 @@ def get_top_image(sub_reddit): 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) - ret["type"] = 'jpg' + ret["url"] = "http://i.imgur.com/{id}.{imageType}".format(id=id, imageType=imageType) + ret["type"] = imageType return ret From 654a637fcace8b3d250a0643389ebcdbfd3ebbdc Mon Sep 17 00:00:00 2001 From: jenroper Date: Fri, 8 Sep 2017 18:51:10 -0400 Subject: [PATCH 12/14] added multireddit support --- README.md | 6 ++++++ change_wallpaper_reddit.py | 30 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f2aaec9..7306152 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,12 @@ If you wanna use other subreddit, include argument with the subreddit name: python /home/silvio/Scripts/change_wallpaper_reddit.py --subreddit art ``` +If you want to use a public multireddit, you must specify the user of the redditor that owns the multireddit and the name of the multireddit. +Example: +``` +python /home/silvio/Scripts/change_wallpaper_reddit.py --user redditor --multireddit nameOfMultireddit +``` + 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: diff --git a/change_wallpaper_reddit.py b/change_wallpaper_reddit.py index 3dc9b6b..dc81383 100755 --- a/change_wallpaper_reddit.py +++ b/change_wallpaper_reddit.py @@ -27,6 +27,8 @@ def load_config(): default["time"] = "day" default["display"] = "0" default["output"] = "Pictures/Wallpapers" + default["user"] = None + default["multireddit"] = None config_path = os.path.expanduser("~/.config/change_wallpaper_reddit.rc") section_name = "root" @@ -57,6 +59,8 @@ def add_to_ret(fun, name): add_to_ret(config.getint, "display") add_to_ret(config.get, "time") add_to_ret(config.get, "output") + add_to_ret(config.get, "user") + add_to_ret(config.get, "multireddit") return ret @@ -80,17 +84,20 @@ def parse_args(): 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("-u", "--user", type=str, default=config["user"], + help="Set the reddit username that owns the multireddit to use.") + parser.add_argument("-m", "--multireddit", type=str, default=config["multireddit"], + help="Name of multireddit to use.") args = parser.parse_args() return args -def get_top_image(sub_reddit): +def get_top_image(submissions): """Get image link of most upvoted wallpaper of the day :sub_reddit: name of the sub reddit :return: the image link """ - submissions = sub_reddit.new(limit=10) if args.time == "new" else sub_reddit.top(time_filter=args.time, limit=10) for submission in submissions: ret = {"id": submission.id} @@ -161,15 +168,28 @@ def detect_desktop_environment(): args = parse_args() subreddit = args.subreddit + multireddit = args.multireddit + user = args.user save_dir = args.output supported_linux_desktop_envs = ["gnome", "mate", "kde", "lubuntu"] # Python Reddit Api Wrapper - r = praw.Reddit('dailywallpaper', user_agent="Get top wallpaper from /r/{subreddit} by /u/ssimunic".format(subreddit=subreddit)) + r = praw.Reddit('dailywallpaper', user_agent="Get top wallpaper by /u/ssimunic") + + # Get top submissions + if ((multireddit is not None) and (user is not None)): + print("Using {user}'s multireddit {multireddit}".format(user=user, multireddit=multireddit)) + multi_reddit = r.multireddit(user, multireddit) + submissions = multi_reddit.new(limit=10) if args.time == "new" else multi_reddit.top(time_filter=args.time, limit=10) + sourceType = multireddit + else: + sub_reddit = r.subreddit(subreddit) + submissions = sub_reddit.new(limit=10) if args.time == "new" else sub_reddit.top(time_filter=args.time, limit=10) + sourceType = subreddit # Get top image link - image = get_top_image(r.subreddit(subreddit)) + image = get_top_image(submissions) if "url" not in image: sys.exit("Error: No suitable images were found, the program is now" \ " exiting.") @@ -184,7 +204,7 @@ def detect_desktop_environment(): home_dir = os.path.expanduser("~") save_location = "{home_dir}/{save_dir}/{subreddit}-{id}.{imageType}".format(home_dir=home_dir, save_dir=save_dir, - subreddit=subreddit, + subreddit=sourceType, id=image["id"], imageType=image["type"]) From 5cb11f7a0b91b96b8b0d4267764e8a1dbbed0466 Mon Sep 17 00:00:00 2001 From: jenroper Date: Fri, 8 Sep 2017 18:59:23 -0400 Subject: [PATCH 13/14] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7306152..f95b9f2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you wanna use other subreddit, include argument with the subreddit name: python /home/silvio/Scripts/change_wallpaper_reddit.py --subreddit art ``` -If you want to use a public multireddit, you must specify the user of the redditor that owns the multireddit and the name of the multireddit. +If you want to use a public multireddit, you must specify the name of the redditor that owns the multireddit and the name of the multireddit. Example: ``` python /home/silvio/Scripts/change_wallpaper_reddit.py --user redditor --multireddit nameOfMultireddit From 5dffb10cb14187d0bcce3120842767ed2ee99713 Mon Sep 17 00:00:00 2001 From: jenroper Date: Thu, 8 Mar 2018 21:55:04 -0500 Subject: [PATCH 14/14] update to praw 5.3 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index de01863..ed8bb75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ decorator==4.0.10 future==0.15.2 -praw==5.0.1 +praw==5.3.0 requests==2.10.0 six==1.10.0 update-checker==0.11