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