Пример #1
0
def main():
    from TweetPoster.reddit import Redditor
    from TweetPoster.twitter import Twitter

    db = Database()
    db.init()
    twitter = Twitter()
    reddit = Redditor().login(
        config['reddit']['username'],
        config['reddit']['password']
    )

    while True:
        try:
            posts = reddit.get_new_posts(db)
            for post in posts:
                handle_submission(post, twitter, reddit)
        except KeyboardInterrupt:
            import sys
            sys.exit(0)
        except requests.exceptions.Timeout:
            # These are exceptions we don't
            # want to tell sentry about
            pass
        except:
            sentry.captureException()
        finally:
            print 'sleeping'
            time.sleep(90)
Пример #2
0
def main():
    from TweetPoster.reddit import Redditor
    from TweetPoster.twitter import Twitter

    db = Database()
    db.init()
    twitter = Twitter()
    reddit = Redditor().login(config['reddit']['username'],
                              config['reddit']['password'])

    while True:
        try:
            posts = reddit.get_new_posts(db)
            for post in posts:
                handle_submission(post, twitter, reddit)
        except KeyboardInterrupt:
            import sys
            sys.exit(0)
        except requests.exceptions.Timeout:
            # These are exceptions we don't
            # want to tell sentry about
            pass
        except:
            sentry.captureException()
        finally:
            print 'sleeping'
            time.sleep(90)
Пример #3
0
def test_get_new():
    mock_posts()
    db = Database()
    db.init(clean=True)
    r = Redditor(bypass_ratelimit=True)
    all_posts = r.get_new_posts(db)
    assert len(all_posts) == 15

    # Mark some as processed
    for i, p in enumerate(all_posts):
        if i % 5 == 0:
            p.mark_as_processed(db)

    # Now check if only returns new ones
    posts = r.get_new_posts(db)
    assert len(posts) == 12
def test_get_new():
    mock_posts()
    db = Database()
    db.init(clean=True)
    r = Redditor(bypass_ratelimit=True)
    all_posts = r.get_new_posts(db)
    assert len(all_posts) == 15

    # Mark some as processed
    for i, p in enumerate(all_posts):
        if i % 5 == 0:
            p.mark_as_processed(db)

    # Now check if only returns new ones
    posts = r.get_new_posts(db)
    assert len(posts) == 12