Advertisement
Guest User

Untitled

a guest
Feb 7th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. import sqlite3
  2. from time import sleep
  3.  
  4. import praw
  5.  
  6.  
  7. # connect to the database. if it doesn't exist, automatically create.
  8. conn = sqlite3.connect('storage.db', isolation_level=None)
  9. cur = conn.cursor()
  10.  
  11. processed_submissions = set()
  12. comments_to_process = set()
  13.  
  14. def process_submission(submission):
  15. if submission.id in processed_submissions:
  16. return
  17. 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.")
  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.  
  25. def 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. Removing now.")
  30. reddit.subreddit('USEFULREDCIRCLEBOT').message("A comment with less than one point has been detected. Please review: %s" % comment.permalink, 'Review Script Name')
  31. parent = comment.parent()
  32. comments_to_process.remove(comment_id)
  33. cur.execute("DELETE FROM stuffToPlot WHERE commentID=?", (comment_id,))
  34. submission = reddit.submission(id=parent)
  35. submission.mod.remove(spam=False)
  36.  
  37. reddit = praw.Reddit(user_agent='x',
  38. client_id='x', client_secret='x',
  39. username='x', password='x')
  40. print('reddit logon succesful')
  41.  
  42. cur.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(commentID TEXT, submissionID TEXT)') # create tables if they dont exist
  43. cur.execute("SELECT commentID, submissionID FROM stuffToPlot")
  44. for row in cur.fetchall():
  45. comments_to_process.add(row[0])
  46. processed_submissions.append(row[1])
  47. print('data loaded from database')
  48.  
  49. while True:
  50. for submission in reddit.subreddit("USEFULREDCIRCLEBOT").new(limit=35):
  51. process_submission(submission)
  52.  
  53. process_commented_submissions()
  54. # change pause to whatever seems useful
  55. sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement