· 8 years ago · Aug 15, 2018, 12:24 PM
1import praw
2import time
3import sqlite3
4
5
6# connect to the database. if it doesn't exist, automatically create.
7conn = sqlite3.connect('storage.db', isolation_level=None)
8cur = conn.cursor()
9
10processed_submissions = set()
11comments_to_process = set()
12
13def process_submission(submission):
14 response = submission.reply("Upvote if this submission is good and follows the rules! Downvote if it doesn't.. *If this comment reaches 0 score, it'll be removed automatically.")
15 # distinguish the post and sticky it.
16 response.mod.distinguish(how='yes', sticky='True')
17 processed_submissions.add(submission.id)
18 comments_to_process.add(response.id)
19 cur.execute('INSERT INTO stuffToPlot (commentID, submissionID) VALUES (?, ?)',
20 (response.id, submission.id))
21
22def process_commented_submissions():
23 for comment_id in comments_to_process:
24 comment = reddit.comment(comment_id)
25 if comment.score < 1:
26 print("A submission has 0 points. Removing now.")
27 comment.edit("**This post has 0 (or less) points. It has been removed automatically.**")
28 parent = comment.parent()
29 comments_to_process.remove(comment_id)
30 c.execute("DELETE FROM stuffToPlot WHERE commentID=?", (comment_id,))
31 submission = reddit.submission(id=parent)
32 submission.mod.remove(spam=False)
33
34print("Logging into reddit!")
35reddit = praw.Reddit(user_agent='x',
36 client_id='x', client_secret='x',
37 username='x', password='x')
38
39
40print("Logged into reddit!")
41cur.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(commentID TEXT, submissionID TEXT)') # create tables if they dont exist
42print("Finished database configuration")
43print("Now attempting to populate variables with data.")
44cur.execute("SELECT commentID FROM stuffToPlot")
45for row in cur.fetchall()
46 comments_to_process.add(row[0])
47print("Finished comment data entry.")
48c.execute("SELECT submissionID from stuffToPlot")
49for row in cur.fetchall():
50 processed_submissions.append(row[0])
51print("Finished submission data entry, ready to go!")
52
53while True:
54 for submission in reddit.subreddit("communitymod").new(limit=35):
55 process_submission(submission)
56
57 process_commented_submissions()