-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallget.py
executable file
·39 lines (33 loc) · 1.23 KB
/
wallget.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/env python3
import re
import os
import praw
import urllib.request
class Wallget:
def __init__(self, prawbot):
self.valid_ext = ["png", "jpg", "jpeg", "webp"]
self.prawbot = prawbot
self.saved = prawbot.user.me().saved(limit=50)
def download(self):
print(f'Retreiving saved wallpapers for: {self.prawbot.user.me()}')
downloads = 0
for link in self.saved:
if link.subreddit == 'wallpapers':
sanitized_title = re.sub('[\W_]+', '', link.title)
extension = link.url.split('.')[-1].lower()
filename = f'{sanitized_title}.{extension}'
if extension not in self.valid_ext:
continue
if os.path.exists(filename):
continue
print(f'{link.title} : {link.url}')
urllib.request.urlretrieve(link.url, filename)
downloads += 1
if downloads:
print(f"{downloads} download(s) completed.")
if __name__ == '__main__':
prawbot1 = praw.Reddit("bot1",
user_agent="wallget - Saved /r/wallpapers Downloader"
)
downloader = Wallget(prawbot1)
downloader.download()