Created
December 9, 2013 19:04
-
-
Save PirosB3/7878860 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
import datetime | |
import json | |
import os | |
import time | |
import pymongo | |
from flask import Flask, render_template | |
from pymongo.uri_parser import parse_uri | |
# Define environment variables | |
DEBUG = os.environ.get('ENVIRONMENT_TYPE', 'debug') == 'debug' | |
MONGO_URL = os.environ.get('MONGOHQ_URL', 'mongodb://localhost/booker') | |
# Define persistence layer | |
conn = pymongo.Connection(MONGO_URL) | |
db = conn[parse_uri(MONGO_URL)['database']] | |
persistence = db['bookings'] | |
# Define web server | |
app = Flask(__name__) | |
app.config.from_object(__name__) | |
# Define constants and helper functions | |
to_dict = lambda k: {'name': k['name'], 'status': k['status'], 'date': k['datetime'].ctime()} | |
@app.route('/bookings') | |
def bookings(): | |
bookings = map(to_dict, persistence.find()) | |
return json.dumps(bookings) | |
@app.route('/') | |
def index(): | |
return render_template('index.html') | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment