-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwallpaper_bot.py
More file actions
43 lines (32 loc) · 1.18 KB
/
Copy pathwallpaper_bot.py
File metadata and controls
43 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import praw
import requests
import time as t
import glob, pprint, os
start_time = t.time()
r = glob.glob('*.jpg')
file_path = 'C:/Users/Public/Wallpapers'
image_list = []
reddit = praw.Reddit('wallpaper_bot')
reddit_data = reddit.subreddit("Wallpaper").hot(limit=256)
def image_download(image_url):
img = requests.get(image_url)
try:
img.raise_for_status()
except Exception as exc:
print('There was a problem... ' + exc)
file = open(str(t.time()) + '.jpg', 'xb') #the filename here is just the time at which it was downloaded
for chunk in img.iter_content(10000):
file.write(chunk)
for files in r:
os.remove(files)
print('Files removed\n')
for image in reddit_data:
if len(image_list) > 9:
print('Found ten wallpapers! Starting download...\n')
break
elif ('1080' in image.title or '1440' in image.title or '2160' in image.title) and (image.over_18 == False):
image_list.append(image.url)
for image in image_list:
image_download(image)
print('Image '+ str(int(image_list.index(image) + 1)) +' downloaded!\n')
print('Program finished without errors! Runtime:' + str(int(t.time()) - start_time) + ' seconds')