Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- import sqlite3
- # connect to the database. if it doesn't exist, automatically create.
- conn = sqlite3.connect('storage.db', isolation_level=None)
- cur = conn.cursor()
- processed_submissions = set()
- comments_to_process = set()
- def process_submission(submission):
- 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.")
- # distinguish the post and sticky it.
- response.mod.distinguish(how='yes', sticky='True')
- processed_submissions.add(submission.id)
- comments_to_process.add(response.id)
- cur.execute('INSERT INTO stuffToPlot (commentID, submissionID) VALUES (?, ?)',
- (response.id, submission.id))
- def process_commented_submissions():
- for comment_id in comments_to_process:
- comment = reddit.comment(comment_id)
- if comment.score < 1:
- print("A submission has 0 points. Removing now.")
- comment.edit("**This post has 0 (or less) points. It has been removed automatically.**")
- parent = comment.parent()
- comments_to_process.remove(comment_id)
- c.execute("DELETE FROM stuffToPlot WHERE commentID=?", (comment_id,))
- submission = reddit.submission(id=parent)
- submission.mod.remove(spam=False)
- print("Logging into reddit!")
- reddit = praw.Reddit(user_agent='x',
- client_id='x', client_secret='x',
- username='x', password='x')
- print("Logged into reddit!")
- cur.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(commentID TEXT, submissionID TEXT)') # create tables if they dont exist
- print("Finished database configuration")
- print("Now attempting to populate variables with data.")
- cur.execute("SELECT commentID FROM stuffToPlot")
- for row in cur.fetchall()
- comments_to_process.add(row[0])
- print("Finished comment data entry.")
- c.execute("SELECT submissionID from stuffToPlot")
- for row in cur.fetchall():
- processed_submissions.append(row[0])
- print("Finished submission data entry, ready to go!")
- while True:
- for submission in reddit.subreddit("communitymod").new(limit=35):
- process_submission(submission)
- process_commented_submissions()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement