Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- r = praw.Reddit(client_id='tasle5fsKGf-_A',
- client_secret='G2QgWFGKxOUArC4_HVE7o0upiuc',
- password='Boobz!',
- user_agent='Jerry Thomas Image Post watcher 0.3 /u/cwinthrop',
- username='BOTLbot')
- 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']
- def containsLink(url):
- for item in notAllowed:
- if item in url:
- return True
- return False
- #Settings
- MAXTIME = 1
- MAXEDIT = 10
- SUBREDDIT = 'cigars'
- #Initialize Database
- import sqlite3
- conn = sqlite3.connect('posts.db');
- c = conn.cursor()
- c.execute('CREATE TABLE IF NOT EXISTS newposts (id text, created text, isremoved text, commid text);')
- def addPost(postId, postCreated, isRemoved, commId):
- c.execute('''INSERT INTO newposts VALUES ('{}', '{}', '{}', '{}')'''.format(postId, postCreated, isRemoved, commId))
- def listAll():
- for post in c.execute('''SELECT * FROM newposts'''):
- print(post)
- def deleteAll():
- c.execute('''DELETE FROM newposts''')
- def isOld(Ptime):
- return (time.time()-float(Ptime))/60 > MAXTIME
- def isOldPost(postId):
- for item in c.execute('SELECT created FROM newposts WHERE id={}'.format(postId)):
- return (time.time()-float(item[0]))/60 > MAXTIME
- def alreadyExists(postId):
- for thing in c.execute('''SELECT created FROM newposts WHERE id={}'''.format(postId)):
- return True
- return False
- def deleteSpec(postId):
- c.execute('''DELETE FROM newposts WHERE id='{}' '''.format(postId))
- def noParentComment(post):
- matches = [str(comment.author).lower() for comment in post.comments if str(comment.author).lower() == str(post.author).lower()]
- return len(matches) == 0
- #check ages for non-removed posts
- def checkAges():
- 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))]:
- 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.**''')
- post.mod.remove()
- msg.mod.distinguish(how='yes', sticky='true')
- addPost(post.id, post.created_utc, 'true', msg.id)
- def checkDatabase():
- listAll()
- for post in c.execute('SELECT * FROM newposts'):
- if (time.time() - float(post[1]))/60 > MAXEDIT:
- 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))
- deleteSpec(post[0])
- else:
- actualPost = r.submission(id=post[0])
- if str(actualPost.author) == 'None':
- deleteSpec(actualPost.id)
- 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.')
- actualPost.mod.lock()
- if not noParentComment(actualPost):
- actualPost.mod.approve()
- r.comment(id=post[3]).delete()
- deleteSpec(post[0])
- while True:
- checkAges()
- checkDatabase()
- conn.commit()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement