-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
95 lines (67 loc) · 2.21 KB
/
app.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# importing the module
from bson import json_util
import json
import imdb
from pymongo import MongoClient
from flask import Flask, jsonify, request
from flask import Flask
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
app.config["DEBUG"] = True
PORT = 3030
HOST = '0.0.0.0'
# creating instance of IMDb
ia = imdb.IMDb()
# getting top 250 movies
search = ia.get_top250_movies()
top25Movies = []
for i in range(25):
top25Movies.append(search[i]['title'])
# connectiong to the DataBase
client = MongoClient(
"mongodb+srv://sai:X977Y58d5QXE4EM&@cluster0.4eabc.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
db = client["assignment"]
BookingColl = db["bookings"]
latest_shows = db["latest_shows"]
post = {"_id": 0, "moviesList": top25Movies}
latest_shows.update_one({"_id": 0}, {"$set": {"moviesList": top25Movies}})
class List(Resource):
def get(self):
result = {}
temp = latest_shows.find_one({"_id": 0})
result["latest shows"] = temp["moviesList"]
return jsonify(result)
class test(Resource):
def get(self):
return jsonify({'message': 'test'})
class Booking(Resource):
def get(self):
return jsonify({'message': 'Booking'})
def post(self):
data = request.get_json()
post = {"user": data["user"],
"show": data["show"], "status": "success"}
BookingColl.insert_one(post)
result = {}
result["status"] = "Booking successful"
return jsonify(result)
class latest_booking(Resource):
def get(self):
return jsonify({'message': 'test'})
def post(self):
data = request.get_json()
DBdata = BookingColl.find({"user": data["user"],
"show": data["show"]})
latesShows = []
for i in DBdata:
latesShows.append(i)
result = {}
result["data"] = json.loads(json_util.dumps(latesShows))
return jsonify(result)
api.add_resource(List, '/list')
api.add_resource(test, '/test')
api.add_resource(Booking, '/booking')
api.add_resource(latest_booking, '/get_latest_booking')
if __name__ == '__main__':
app.run(threaded=True, host='0.0.0.0', port=PORT, debug=True)