-
Notifications
You must be signed in to change notification settings - Fork 0
/
rest.py
41 lines (32 loc) · 1.21 KB
/
rest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from flask import Flask
from flask import jsonify
from flask import request
from flask_pymongo import PyMongo
from flask import abort
app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'filmweb_base'
app.config['MONGO_URI'] = 'mongodb://localhost:27017/filmweb_base'
mongo = PyMongo(app)
@app.route('/movies', methods=['GET'])
def get_all_movies():
movies = mongo.db.movies
output = []
for movie in movies.find():
output.append({'title' : movie['title'], 'title_pl' : movie['title_pl'],
'image' : movie['image'], 'director' : movie['director'],
'year' : movie['year'], 'plot' : movie['plot'], 'genres' : movie['genres']})
return jsonify({'movies' : output})
@app.route('/movie', methods = ["GET"])
def get_one_movie():
title = request.headers.get("title")
movies = mongo.db.movies
movie = movies.find_one({'title': title})
if movie:
output = {'title' : movie['title'], 'title_pl' : movie['title_pl'],
'image' : movie['image'], 'director' : movie['director'],
'year' : movie['year'], 'plot' : movie['plot'], 'genres' : movie['genres']}
else:
abort(400)
return jsonify(output)
if __name__ == '__main__':
app.run(debug=True)