Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. import praw
  2. import sqlite3
  3.  
  4.  
  5. # connect to the database. if it doesn't exist, automatically create.
  6. conn = sqlite3.connect('storage.db', isolation_level=None)
  7. cur = conn.cursor()
  8.  
  9. processed_submissions = set()
  10. comments_to_process = set()
  11.  
  12. def 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.  
  21. def 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.  
  33. print("Logging into reddit!")
  34. reddit = praw.Reddit(user_agent='x',
  35.                     client_id='x', client_secret='x',
  36.                     username='x', password='x')
  37.  
  38.  
  39. print("Logged into reddit!")
  40. cur.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(commentID TEXT, submissionID TEXT)') # create tables if they dont exist
  41. print("Finished database configuration")
  42. print("Now attempting to populate variables with data.")
  43. cur.execute("SELECT commentID FROM stuffToPlot")
  44. for row in cur.fetchall()
  45.     comments_to_process.add(row[0])
  46. print("Finished comment data entry.")
  47. c.execute("SELECT submissionID from stuffToPlot")
  48. for row in cur.fetchall():
  49.     processed_submissions.append(row[0])
  50. print("Finished submission data entry, ready to go!")
  51.  
  52. while True:
  53.     for submission in reddit.subreddit("communitymod").new(limit=35):
  54.         process_submission(submission)
  55.  
  56.     process_commented_submissions()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement