Пример #1
0
failure_counter = 1  # 1 by default since it is the wait timer multiplier

while True:
    try:
        failure = False
        if mark_read:  # Needed to clear after a Reddit disconnection error
            reddit.inbox.mark_read(mark_read)
            mark_read.clear()
        # for all unread messages
        for message in reddit.inbox.unread():
            # for all unread comments
            if message.was_comment:
                result = None
                # username mentions are simple
                if message.subject == "username mention":
                    result = process_comment(reddit,
                                             reddit.comment(message.id))
                # if it was a reply, check to see if it contained a summon
                elif message.subject == "comment reply" or message.subject == "post reply":
                    if REPatterns.reply_mention.findall(message.body):
                        result = process_comment(reddit,
                                                 reddit.comment(message.id))
                    else:
                        secret_process(reddit, message)
                # Depending on success or other outcomes, we mark the message read
                if result == SUCCESS or result == USER_FAILURE:
                    mark_read.append(message)
                # If the upload failed, try again later
                elif result == UPLOAD_FAILURE:
                    failure = True
                    print("Upload failed, not removing from queue")
                else:
Пример #2
0

def signal_handler(sig, frame):
    print("Exiting...")
    q.exit_queue()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

while True:
    try:
        for i in q.get_jobs():
            print(i, i.origin_host, i.origin_id)
            result = process_comment(reddit,
                                     original_context=CommentContext.from_json(
                                         reddit, dict(i.context)))
            if result == SUCCESS or result == USER_FAILURE:
                q.remove_job(i)
        time.sleep(consts.sleep_time * failure_counter / 4)

    except prawcore.exceptions.ResponseException as e:  # Something funky happened
        q.exit_queue()
        print("Did a comment go missing?", e, vars(e))
        time.sleep(consts.sleep_time)

    except prawcore.exceptions.RequestException:  # Unable to connect to Reddit
        q.exit_queue()
        print("Unable to connect to Reddit, is the internet down?")
        time.sleep(consts.sleep_time * 2)