Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 83b29b4

Browse files
committed
Update script.py
Added some basic code into the script for it to work before creating a GUI
1 parent 120fe5e commit 83b29b4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

‎Reddit Meme Scraper/script.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /