From 3679137e6cae8db9a1421b83051fd2e76f94f6ce Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 23 Oct 2020 00:35:09 -0700 Subject: [PATCH] add simple reddit package --- supportbot/reddit.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 supportbot/reddit.py diff --git a/supportbot/reddit.py b/supportbot/reddit.py new file mode 100644 index 0000000..e11af97 --- /dev/null +++ b/supportbot/reddit.py @@ -0,0 +1,44 @@ +import praw +from supportbot import config + + +class Reddit(object): + def __init__(self): + self.reddit = praw.Reddit( + client_id=config.PRAW_CLIENT_ID, + client_secret=config.PRAW_CLIENT_SECRET, + user_agent=config.PRAW_USER_AGENT, + username=config.PRAW_USERNAME, + password=config.PRAW_PASSWORD + ) + self.subreddit = "monerosupport" + + def post(self, title, url): + try: + submission = self.reddit.subreddit(self.subreddit).submit( + title=title, + url=url, + resubmit=False, + ) + return submission + except: + return False + + def comment(self, submission, comment): + try: + _comment = submission.reply(comment) + return _comment + except: + return False + +if __name__ == '__main__': + r = Reddit() + subreddit = r.reddit.subreddit(r.subreddit) + for submission in subreddit.new(): + print(submission) + print("author", submission.author) + print("id", submission.id) + print("name", submission.name) + print("permalink", submission.permalink) + print("title", submission.title) + print("\n")