-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemes.py
28 lines (25 loc) · 950 Bytes
/
memes.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
import praw
from prawcore import NotFound
class Memes:
def __init__(self, username, password, cID, cSecret) -> None:
self.reddit = praw.Reddit(username=username,
password=password,
client_id=cID,
client_secret=cSecret,
user_agent="pls kill me",
check_for_async=False)
def meme(self, subname: str):
subreddit = self.sub_exists(subname)
if not subreddit:
return None
meme = subreddit.random()
if meme is None:
meme = subreddit.hot(limit=1)
return meme.author.name+": "+meme.title+"$"+meme.url
def sub_exists(self, subname: str):
try:
sub = self.reddit.subreddit(subname)
sub.random()
return sub
except NotFound:
return None