def run(): no_context = [ '/r/nocontext' ] banned_subreddits = [ 'wishlist', 'cringepics', 'askreddit' ] r = login.init() my_id = login.my_id(r) while True: try: for comment in praw.helpers.comment_stream(r, 'all', verbosity=0): subreddit = comment.subreddit.display_name.lower() if subreddit in banned_subreddits: continue text = util.txt(comment).lower().strip() if text in no_context \ and not comment.is_root \ and not db.has_replied(comment.id): db.reply(comment.id) login.refresh_praw(r) reply(r, comment) except praw.errors.OAuthInvalidToken: login.refresh_praw(r)
def run(): ban_template = 'you\'ve been banned from (/r/.+)' last_seen_message = None r = login.init() while True: try: newest_message = None for message in r.get_messages(place_holder=last_seen_message): author = message.author match_res = re.match(ban_template, message.subject) if newest_message == None: newest_message = message.id last_seen_message = newest_message if message.subject == 'blacklist': print '[blacklist] user:'******'[blacklist] subreddit' + subreddit db.ban_subreddit(subreddit) time.sleep(60) except praw.errors.OAuthInvalidToken: login.refresh_praw(r)
def __init__(self): """ charge la configuration """ id = login.init() self.bot = id.bot self.chatID = id.chatID
#coding=utf-8 import login import logging login.init() f = login.internal_login() token = login.get_login_token(f) logging.log(logging.WARNING, "token is" + str(token)) def sendMessage(msg): login.sendMessage(token, msg)