Beispiel #1
0
def update():
    """Tweet!"""

    with open('history.txt', 'rb') as hf:
        history = json.loads(hf.read())['history']

    tweet = ''
    while True:
        tweet = brains.new_tweet(
            filter(None, map(tools.tidy, tools.sentence_corpus(history)))
        )
        if len(tweet) <= 140:
            break

    # Connect.
    api = twitter.Api(
        os.environ['CONSUMER_KEY'],
        os.environ['CONSUMER_SECRET'],
        os.environ['ACCESS_TOKEN'],
        os.environ['ACCESS_TOKEN_SECRET'],
        cache=None,
    )
    # Post away!
    api.PostUpdate(tweet)

    time.sleep(12 * 60 * 60)

    return tweet
def test_corpus_to_sentences():
    """Converts a corpus of tweets to a corpus of sentences."""
    tweets = ["Hello, how're you? I'm great. Good.", "beer", "Gone fishing?"]

    assert tools.sentence_corpus(tweets) == ["Hello, how're you", "I'm great", "Good", "beer", "Gone fishing"]