-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (47 loc) · 1.39 KB
/
Copy pathapp.py
File metadata and controls
60 lines (47 loc) · 1.39 KB
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
import json
from flask import Flask
import socket
from pymongo import MongoClient
app = Flask(__name__)
def get_db():
client = MongoClient(host='test_mongodb',
port=27017,
username='root',
password='pass',
authSource="admin")
db = client["film"]
return db
# Function to display hostname and IP address
def get_Host_name_IP():
try:
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print("Hostname : ",host_name)
print("IP : ",host_ip)
return host_name, host_ip
except:
print("Unable to get Hostname and IP")
@app.route("/index", methods=["GET"])
def index():
host, ip = get_Host_name_IP()
return f'Up and runnning !!! IN => {host} , AT ADDRESS => {ip} '
@app.route('/insert')
def insert():
try:
js = json.load(open('Film.json','r'))
print(js)
film_db = get_db()
film_coll= film_db["films"]
film_coll.insert_many(js)
return "Success"
except Exception as e:
print(str(e))
return str(e)
@app.route('/get')
def get():
film_db = get_db()
film_coll= film_db["films"]
result = list(film_coll.find({},{"_id":0}))
return {"data":result}
if __name__ == "__main__":
app.run(host ='0.0.0.0', port = 5000, debug = True)