Created
March 4, 2014 00:16
-
-
Save elbuo8/9337584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
from random import randint | |
from sendgrid import Mail, SendGridClient | |
app = Flask(__name__) | |
app.debug = True | |
tweets = [] | |
#put code here | |
if __name__ == '__main__': | |
app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/tweet', methods=['POST', 'GET']) | |
def handle_create(): | |
if request.method == 'POST': | |
new_tweet = {"id": randint(), "text": request.form['tweet']} | |
tweets.append(newtweet) | |
return jsonify(newtweet) | |
else: | |
return jsonify({"tweets": tweets}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/tweet/emailhook', methods=['POST']) | |
def email_tweet(): | |
new_tweet = {'id': randint(), 'text': request.form['subject']} | |
tweets.append(new_tweet) | |
return jsonify(new_tweet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pip install virtualenv | |
// or | |
$ easy_install virtualenv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ virtualenv tweetbot | |
$ cd tweetbot | |
$ source bin/activate | |
$ pip install flask sendgrid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/tweet/<int:id>', methods=['PUT', 'GET', 'DELETE']) | |
def handle_single_tweet(id): | |
for tweet in tweets: | |
if tweet['id'] == id: | |
if request.method == 'GET': | |
return jsonify(tweet) | |
elif request.method == 'PUT': | |
tweet['text'] = request.form('text') | |
return jsonify(tweet) | |
else: | |
removed = tweet | |
tweets.remove(tweet) | |
return jsonify(removed) | |
return jsonify({"error": "Not found"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment