Commit 6932fb28 authored by Matthew Ma's avatar Matthew Ma

finished part 2

parent bf5caf6a
#!/usr/bin/python
import praw
import pdb
import re
import os
#Create the Reddit instance
reddit = praw.Reddit('bot1')
if not os.path.isfile("posts_replied_to.txt"):
posts_replied_to = []
else:
with open("posts_replied_to.txt", "r") as f:
posts_replied_to = f.read()
posts_replied_to = posts_replied_to.split("\n")
posts_replied_to = list(filter(None, posts_replied_to))
subreddit = reddit.subreddit('pythonforengineers')
for submission in subreddit.new(limit=5):
print(submission.title)
if submission.id not in posts_replied_to:
if re.search("i love python", submission.title, re.IGNORECASE):
submission.reply("Botty bot says: Me too!!")
print("Bot replying to : ", submission.title)
posts_replied_to.append(submission.id)
with open("posts_replied_to.txt", "w") as f:
for post_id in posts_replied_to:
f.write(post_id + "\n")
\ No newline at end of file
88w1lw
88v8h2
8962d7
88v4kt
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment