Пример #1
0
def tweet(twit):
    tweet_to_tweet = Tweet.top()
    if not tweet_to_tweet:
        return
    return (twit.statuses.update(status=tweet_to_tweet.content),
            tweet_to_tweet)
Пример #2
0
def next_tweet():
    tweet = Tweet.top()
    if not tweet:
        return Response("No tweets.", 200)
    return jsonify(tweet=tweet.json_object())
Пример #3
0
    credentials = oauth_credentials()
    consumer_key = credentials["consumer_key"]
    consumer_secret = credentials["consumer_secret"]
    access_key = credentials["access_key"]
    access_secret = credentials["access_secret"]

    auth = twitter.OAuth(access_key, access_secret,
                         consumer_key, consumer_secret)
    return twitter.Twitter(auth=auth)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", "--test",
                        help="Don't tweet and print to standard out.",
                        action="store_true")
    args = parser.parse_args()
    if Tweet.count() == 0:
        print("No tweets found.")
        exit(0)
    if args.test:
        print(Tweet.top().content)
        exit(0)
    twitter_client = authenticate()
    response, tweeted = tweet(twitter_client)
    if response:
        Tweet.pop()
        print("Tweeted: \"", tweeted.content, "\"", sep="")
    else:
        print("Could not send tweet.")