Skip to content

Instantly share code, notes, and snippets.

@jrm2k6
Created December 3, 2014 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrm2k6/394f297bf8659c6d0ffe to your computer and use it in GitHub Desktop.
Save jrm2k6/394f297bf8659c6d0ffe to your computer and use it in GitHub Desktop.
app = Flask(__name__)
assets = Environment(app)
Markdown(app, extensions=['codehilite'])
app.config.from_object(__name__)
app.config.from_object('publishr.config')
app.secret_key = 'this is my secret key'
global posts_exporter_instance
@app.route('/authorize_posts_backup/<export_type>', methods=['GET'])
def authorize_posts_backup(export_type):
// I create the instance here
posts_exporter_instance = post_exporter_factory(export_type)
authorize_url = posts_exporter_instance.get_authorize_url()
if authorize_url is not None:
return Response(json.dumps({"aurl": authorize_url}), status=200, mimetype='application/json')
else:
return Response(json.dumps({}), status=500, mimetype='application/json')
@app.route('/submit_verification_code', methods=['POST'])
def submit_verification_code():
verification_code_submitted = request.form['verification-code']
if verification_code_submitted is not None:
// i want to reuse the instance
return posts_exporter_instance.verify_credentials(verification_code_submitted)
else:
return Response(json.dumps({}), status=500, mimetype='application/json')
@app.route('/export_files', methods=['POST'])
def export_files():
checked_files = [v for k, v in request.form.iteritems()]
// i want to reuse the instance
return posts_exporter_instance.export_posts(checked_files)
if __name__ == '__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment