Advertisement
Guest User

Untitled

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