1
+ import praw
2
+ import PySimpleGUI as pg
3
+ import urllib
4
+ import pandas
5
+ import datetime as dt
6
+ import os
7
+
8
+ reddit = praw .Reddit (client_id = '' ,
9
+ client_secret = '' ,
10
+ user_agent = '' )
11
+
12
+ subreddit = reddit .subreddit ('sbname+sbname+sbname' )
13
+ posts = subreddit .hot (limit = 10 )
14
+
15
+ # Empty lists to hold data
16
+
17
+ image_urls = []
18
+ image_titles = []
19
+ image_scores = []
20
+ image_timestamps = []
21
+ image_ids = []
22
+ image_extensions = ['.jpg' , '.jpeg' , '.png' ]
23
+
24
+ # This iterates through posts and collects their data into lists
25
+
26
+ for post in posts :
27
+ image_urls .append (post .url .encode ('utf-8' ))
28
+ image_titles .append (post .title .encode ('utf-8' ))
29
+ image_scores .append (post .score )
30
+ image_timestamps .append (dt .datetime .fromtimestamp (post .created ))
31
+ image_ids .append (post .id )
32
+
33
+ # This iterates through URLs, checks if it has the specified image extension and downloads the image
34
+
35
+ for index , url in enumerate (image_urls ):
36
+ images_path = os .getcwd ()
37
+ _ , ext = os .path .splitext (url )
38
+ if ext in image_extensions :
39
+ try :
40
+ print ('Downloading ' , image_urls [index ], ' at' , images_path + image_titles [index ] + ext )
41
+ urllib .urlretrieve (image_urls [index ], images_path + image_titles [index ] + ext )
42
+ except :
43
+ print ('Something went wrong while downloading ' , image_urls [index ])
0 commit comments