Skip to content
Snippets Groups Projects
Select Git revision
  • fd5e32b30950443e2375111e8c13ed24d1dd3ca9
  • master default protected
  • hotsource
  • compose
  • dockerservices
  • simpleservices
6 results

showtimes.py

Blame
  • Forked from COM3014 / microservices
    Up to date with the upstream repository.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    showtimes.py 832 B
    from services import root_dir, nice_json
    from flask import Flask
    from werkzeug.exceptions import NotFound
    import json
    import os
    
    
    app = Flask(__name__)
    
    with open("{}/database/showtimes.json".format(os.getcwd()), "r") as f:
        showtimes = json.load(f)
    
    
    @app.route("/", methods=['GET'])
    def hello():
        return nice_json({
            "uri": "/",
            "subresource_uris": {
                "showtimes": "/showtimes",
                "showtime": "/showtimes/<date>"
            }
        })
    
    
    @app.route("/showtimes", methods=['GET'])
    def showtimes_list():
        return nice_json(showtimes)
    
    
    @app.route("/showtimes/<date>", methods=['GET'])
    def showtimes_record(date):
        if date not in showtimes:
            raise NotFound
        print(showtimes[date])
        return nice_json(showtimes[date])
    
    if __name__ == "__main__":
        app.run(port=5002, debug=True)