Advertisement
Guest User

Untitled

a guest
Aug 16th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. import praw
  2. import time
  3. r = praw.Reddit(client_id='tasle5fsKGf-_A',
  4. client_secret='G2QgWFGKxOUArC4_HVE7o0upiuc',
  5. password='Boobz!',
  6. user_agent='Jerry Thomas Image Post watcher 0.3 /u/cwinthrop',
  7. username='BOTLbot')
  8.  
  9. notAllowed = ['500px.com', 'abload.de', 'anony.ws', 'barnoobs.com', 'dailymotion.com', 'deviantart.com', 'deviantart.net', 'fav.me', 'facebook.com', 'fbcdn.net', 'flickr.com', 'forgifs.com', 'giphy.com', 'gfycat.com', 'gifs.com', 'gifsoup.com', 'gyazo.com', 'imageshack.us', 'imgclean.com', 'imgix.net', 'imgur.com', 'instagr.am', 'instagram.com', 'i.redd.it', 'i.reddituploads.com', 'liveleak.com', 'mediacru.sh', 'media.tumblr.com', 'min.us', 'minus.com', 'mr2ndopinion.com', 'myimghost.com', 'photobucket.com', 'picsarus.com', 'postimg.org', 'puu.sh', 'sli.mg', 'staticflickr.com', 'tinypic.com', 'twitpic.com', 'vid.me','vimeo.com', 'v.redd.it', 'youtu.be', 'youtube.com', 'upload.wikimedia.org', 'worldstarhiphop.com']
  10.  
  11. def containsLink(url):
  12. for item in notAllowed:
  13. if item in url:
  14. return True
  15. return False
  16.  
  17. #Settings
  18.  
  19. MAXTIME = 1
  20. MAXEDIT = 10
  21. SUBREDDIT = 'cigars'
  22.  
  23. #Initialize Database
  24.  
  25. import sqlite3
  26. conn = sqlite3.connect('posts.db');
  27. c = conn.cursor()
  28.  
  29.  
  30. c.execute('CREATE TABLE IF NOT EXISTS newposts (id text, created text, isremoved text, commid text);')
  31.  
  32. def addPost(postId, postCreated, isRemoved, commId):
  33. c.execute('''INSERT INTO newposts VALUES ('{}', '{}', '{}', '{}')'''.format(postId, postCreated, isRemoved, commId))
  34.  
  35. def listAll():
  36. for post in c.execute('''SELECT * FROM newposts'''):
  37. print(post)
  38.  
  39. def deleteAll():
  40. c.execute('''DELETE FROM newposts''')
  41.  
  42.  
  43. def isOld(Ptime):
  44. return (time.time()-float(Ptime))/60 > MAXTIME
  45.  
  46. def isOldPost(postId):
  47. for item in c.execute('SELECT created FROM newposts WHERE id={}'.format(postId)):
  48. return (time.time()-float(item[0]))/60 > MAXTIME
  49.  
  50. def alreadyExists(postId):
  51. for thing in c.execute('''SELECT created FROM newposts WHERE id={}'''.format(postId)):
  52. return True
  53. return False
  54.  
  55. def deleteSpec(postId):
  56. c.execute('''DELETE FROM newposts WHERE id='{}' '''.format(postId))
  57.  
  58.  
  59. def noParentComment(post):
  60. matches = [str(comment.author).lower() for comment in post.comments if str(comment.author).lower() == str(post.author).lower()]
  61. return len(matches) == 0
  62.  
  63.  
  64. #check ages for non-removed posts
  65. def checkAges():
  66. for post in [post for post in r.subreddit(SUBREDDIT).new(limit=3) if isOld(post.created_utc) and noParentComment(post) and str(post.author).lower() != 'BOTLbot' and str(post.author).lower() != 'automoderator' and containsLink(str(post.url))]:
  67. msg = post.reply('''Thank for your submission, but you need to write something about your post. Was this a good cigar? Are you showing off your setup? Is this a humblebrag? Did you know that Ron Mexico's are the preferred smoke of this sub? Give us something to work with here or we are gonna have to remove your post, and nobody wants that. You have 10 minutes for this mission, should you choose to accept it. If not, your image goes into the ether.\n\nThis is an automated response, so replying to me or messaging me will do nothing, as I am a bot. Please contact the Moderators if you have further questions or concerns.**''')
  68. post.mod.remove()
  69. msg.mod.distinguish(how='yes', sticky='true')
  70. addPost(post.id, post.created_utc, 'true', msg.id)
  71.  
  72. def checkDatabase():
  73. listAll()
  74. for post in c.execute('SELECT * FROM newposts'):
  75. if (time.time() - float(post[1]))/60 > MAXEDIT:
  76. r.comment(id=post[3]).edit('This post has gone more than {} minutes with no descriptive comment and can no longer be restored.\n\nIf you care so little for your post that you can\'t be bothered to make a descriptive comment, why bother posting? This is an automated response, so replying to me or messaging me will do nothing, as I am a bot. Please contact the Moderators if you have further questions or concerns.'.format(MAXEDIT))
  77. deleteSpec(post[0])
  78. else:
  79. actualPost = r.submission(id=post[0])
  80. if str(actualPost.author) == 'None':
  81. deleteSpec(actualPost.id)
  82. r.comment(id=post[3]).edit('This post has been deleted and can no longer be approved.\n\nThis is an automated response, so replying to me or messaging me will do nothing, as I am a bot. Please contact the Moderators if you have further questions or concerns.')
  83. actualPost.mod.lock()
  84. if not noParentComment(actualPost):
  85. actualPost.mod.approve()
  86. r.comment(id=post[3]).delete()
  87. deleteSpec(post[0])
  88.  
  89. while True:
  90. checkAges()
  91. checkDatabase()
  92. conn.commit()
  93.  
  94.  
  95.  
  96.  
  97. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement