forked from siyuniu/memes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreddit.py
67 lines (45 loc) · 2.09 KB
/
reddit.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Python Reddit API Wrapper. https://praw.readthedocs.io/en/latest/. Praw allows us to access Reddit API and helps us parse the data from the Reddit API.
import praw
class Reddit:
def __init__(self, nameOfSubreddit, limits):
"""Init Reddit Class"""
#Initializies the name of the subreddit.
self.nameOfSubreddit = nameOfSubreddit
#Initializies the amount of posts you retrieve from reddit.
self.limits = limits
#Initializies an instance of Reddit. Need account and application information to access it.
self.praw = praw.Reddit(client_id='kCrm1Fz7g6alMw',
client_secret='z3l8kIhB9zYAQl7QUobTOkBGCnQ',
user_agent='testscriptplswork',
username='joshdunigan',
password='joshdunigan123')
#Initializes the subreddit.
self.subreddit = self.praw.subreddit(nameOfSubreddit)
#Initializies a list used to return the information
self.urlList = []
self.titleList = []
self.authorList = []
self.scoreList = []
def getSubredditName(self):
""" Return the name of the Subreddit."""
return self.nameOfSubreddit
def setSubreddit(self, subredditName):
"""Changes the subreddit name. @param Name of the subreddit you want to change to."""
self.nameOfSubreddit = subredditName
self.subreddit = self.praw.subreddit(nameOfSubreddit)
def getImageUrl(self):
for submissions in self.subreddit.top(time_filter = 'day', limit = self.limits):
self.urlList.append(submissions.url)
return self.urlList
def getTitle(self):
for submissions in self.subreddit.top(time_filter = 'day', limit = self.limits):
self.titleList.append(submissions.title)
return self.titleList
def getScore(self):
"""Returns a lists of integers of scores of the posts."""
self.scoreList = [submissionsss.score for submissionsss in self.subreddit.top(time_filter = 'day', limit = self.limits)]
return self.scoreList
def getAuthor(self):
"""Returns a list of the usernames who submtited the posts."""
self.authorList = [submission.author for submission in self.subreddit.top(time_filter = 'day', limit = self.limits)]
return self.authorList