Skip to content

Instantly share code, notes, and snippets.

@apendleton
Created January 13, 2012 05:52
Show Gist options
  • Save apendleton/1604844 to your computer and use it in GitHub Desktop.
Save apendleton/1604844 to your computer and use it in GitHub Desktop.
Twitter public timeline proxy for testing -- depends on flask
import urllib2, json, random, sys
from flask import Flask, request, make_response
app = Flask(__name__)
TIMELINE_DATA = None
@app.route('/public_timeline.json')
def public_timeline():
out = json.dumps(sorted(TIMELINE_DATA, key=lambda x: random.random()))
if 'callback' in request.args:
resp = make_response('%s(%s)' % (request.args['callback'], out))
resp.mimetype = 'text/javascript'
else:
resp = make_response(out)
resp.mimetype = 'application/json'
return resp
if __name__ == '__main__':
timeline_file = open(sys.argv[1], 'r') if len(sys.argv) > 1 else urllib2.urlopen("https://api.twitter.com/1/statuses/public_timeline.json")
TIMELINE_DATA = json.loads(timeline_file.read())
app.run(host='0.0.0.0', port=8888, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment