forked from D3vd/Meme_Api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreddit_handler.py
More file actions
34 lines (23 loc) · 809 Bytes
/
reddit_handler.py
File metadata and controls
34 lines (23 loc) · 809 Bytes
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
import praw
import random
from prawcore.exceptions import Redirect
from prawcore.exceptions import ResponseException
class ClientInfo:
id = 'TpEjWEc2SHTafQ'
secret = 'kuojXoBkMZs_JWrCVEaDWgW8FhA'
user_agent = 'Meme Api'
def is_img_link(link):
ext = link[-4:]
if ext == '.jpg' or ext == '.png':
return True
else:
return False
def get_posts(sub, limit):
r = praw.Reddit(client_id=ClientInfo.id, client_secret=ClientInfo.secret,
user_agent=ClientInfo.user_agent)
submissions = r.subreddit(sub).hot(limit=limit)
result = [{"title": submission.title,
"url": submission.url,
"link": submission.shortlink}
for submission in submissions]
return result