Skip to content

Commit

Permalink
Merge pull request #1 from teaqu/subreddit-sort
Browse files Browse the repository at this point in the history
Sort posts (new, hot, top)
  • Loading branch information
federicotorrielli authored Feb 21, 2021
2 parents 9d513d5 + c07e42c commit 8f9f2f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ ENV/

# Rope project settings
.ropeproject

# Intelij
.idea/
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -132,4 +139,5 @@ Example of configuration file:
```
subreddit=art
time=day
sort=top
```
15 changes: 12 additions & 3 deletions change_wallpaper_reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 8f9f2f8

Please sign in to comment.