from werkzeug.exceptions import NotFound
from flask import Flask, jsonify, make_response
import requests
import os
import simplejson as json

app = Flask(__name__)

database_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
print database_path

with open("{}/app/database/showtimes.json".format(database_path), "r") as f:
    showtimes = json.load(f)


@app.route("/", methods=['GET'])
def hello():
    return jsonify({
        "uri": "/",
        "subresource_uris": {
            "showtimes": "/showtimes",
            "showtime": "/showtimes/<date>"
        }
    })


@app.route("/showtimes", methods=['GET'])
def showtimes_list():
    return jsonify(showtimes)


@app.route("/showtimes/<date>", methods=['GET'])
def showtimes_record(date):
    if date not in showtimes:
        return "Not found"
    print showtimes[date]
    return jsonify(showtimes[date])

if __name__ == "__main__":
    app.run(host="0.0.0.0",port=5003, debug=True)
