Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created February 9, 2014 05:00
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 mattdeboard/8894503 to your computer and use it in GitHub Desktop.
Save mattdeboard/8894503 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from flask import Flask, make_response, request
from sqlalchemy import create_engine
app = Flask(__name__)
engine = create_engine('postgresql://eventcaptureuser:postgres@localhost/event',
pool_size=100, max_overflow=0)
@app.route("/capture", methods=['POST'])
def capture():
query = 'select insert_eventlog(%s, %s, %s, %s)'
params = [request.form.get(p) for p in
['event_type', 'ext_ref', 'user_ref', 'data']]
with engine.begin() as conn:
try:
conn.execution_options(autocommit=True).execute(query, params)
except Exception as err:
return make_response(err, 500)
return make_response('', 200)
@app.route("/")
def home():
return "It works!"
if __name__ == '__main__':
app.run(port=3000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment