Ejemplo n.º 1
0
def move():
    from_index = request.body.get("from", "")
    to_index = request.body.get("to", "")
    if not from_index:
        from_index = (Tweet.count() - 1)

    if not to_index:
        to_index = 0

    from_index = int(from_index)
    to_index = int(to_index)

    response = Tweet.move(from_index, to_index)
    if not response:
        return database_error_response()

    tweet_dict = response.json_object()
    return jsonify(tweet=tweet_dict)
Ejemplo n.º 2
0
def tweet_count():
    return jsonify(count=Tweet.count())
Ejemplo n.º 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.")