· 7 years ago · Feb 11, 2019, 04:30 PM
1import sqlite3
2from time import sleep
3
4import praw
5
6
7# connect to the database. if it doesn't exist, automatically create.
8conn = sqlite3.connect('storage.db', isolation_level=None)
9cur = conn.cursor()
10
11processed_submissions = set()
12comments_to_process = set()
13
14def process_submission(submission):
15 if submission.id in processed_submissions:
16 return
17 response = submission.reply("**Upvote** if this submission is a good example of a Useful Red Circle. **Downvote** if it is not.")
18 # distinguish the post and sticky it.
19 response.mod.distinguish(how='yes', sticky='True')
20 processed_submissions.add(submission.id)
21 comments_to_process.add(response.id)
22 cur.execute('INSERT INTO stuffToPlot (commentID, submissionID) VALUES (?, ?)',
23 (response.id, submission.id))
24
25def process_commented_submissions():
26 for comment_id in comments_to_process:
27 comment = reddit.comment(comment_id)
28 if comment.score < 1:
29 print("A submission has 0 points. Sending message to modmail.")
30 reddit.subreddit('USEFULREDCIRCLEBOT').message('TEST', "A comment with less than one point has been detected. Please review: %s" % comment.permalink)
31 parent = comment.parent()
32 # uncomment the lines below if you want the bot to delete the post instead of just sending a message to modmail.
33 # cur.execute("DELETE FROM stuffToPlot WHERE commentID=?", (comment_id,))
34 # submission = reddit.submission(id=parent)
35 # submission.mod.remove(spam=False)
36
37reddit = praw.Reddit(user_agent='x',
38 client_id='x', client_secret='x',
39 username='x', password='x')
40print('reddit logon succesful')
41
42cur.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(commentID TEXT, submissionID TEXT)') # create tables if they dont exist
43cur.execute("SELECT commentID, submissionID FROM stuffToPlot")
44for row in cur.fetchall():
45 comments_to_process.add(row[0])
46 processed_submissions.add(row[1])
47print('data loaded from database')
48
49while True:
50 for submission in reddit.subreddit("USEFULREDCIRCLEBOT").new(limit=35):
51 process_submission(submission)
52
53 process_commented_submissions()
54 comments_to_process = set()
55 # change pause to whatever seems useful
56 sleep(10)