forked from AleksandarMuradyan/static_carrier_inventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarrier_inventory.py
116 lines (93 loc) · 4.45 KB
/
carrier_inventory.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from flask import Flask, jsonify, Response, request
import json
import os
import argparse
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
def parseArguments():
# Create argument parser
#parser = argparse.ArgumentParser()
#args = parser.parse_args()
return args
@app.route('/api/locations', methods=['GET', 'POST'])
def locations():
if request.method == 'POST':
with open(os.path.join(basedir, 'locations_post_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
else:
with open(os.path.join(basedir, 'locations_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.route('/api/products', methods=['GET'])
def products():
with open(os.path.join(basedir, 'ports_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.route('/api/prices', methods=['GET'])
def prices():
if request.args.get('service_type') == "ETHERNETPORT":
with open(os.path.join(basedir, 'ports_pricing_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
else:
with open(os.path.join(basedir, 'evc_pricing_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.route('/api/ports', methods=['GET', 'POST'])
def ports():
app.logger.debug('form data: %s', request.json)
if request.method == 'GET':
with open(os.path.join(basedir, 'ports_get.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
else:
if request.json.get('location_id') == "FRLYO-0000149509":
with open(os.path.join(basedir, 'ports_post_data_lyon.json'),'r') as f:
return Response(f.read(), mimetype='application/json')
else:
with open(os.path.join(basedir, 'ports_post_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.route('/api/requests/<int:_id>', methods=['GET', 'POST'])
def requests(_id):
if request.method == 'GET' and _id == 4662:
with open(os.path.join(basedir, 'requests_status_completed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
elif request.method == 'GET' and _id == 4663:
with open(os.path.join(basedir, 'requests_status_failed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
if request.method == 'GET' and _id == 4664:
with open(os.path.join(basedir, 'requests_status_completed_lyon.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
elif args.request_status == "completed" and request.method == 'GET' and _id == '':
with open(os.path.join(basedir, 'requests_status_completed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
else:
with open(os.path.join(basedir, 'requests_status_failed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.route('/api/login', methods=['POST'])
def login():
with open(os.path.join(basedir, 'login_post_data.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
# @app.route('post/api/login')
# def login():
# json_data = request.get_json()
# email = json_data['email']
# password = json_data['password']
# return jsonify(token=generate_token(email, password))
@app.route('/api/connections', methods=['POST'])
def connections():
if args.request_status == "completed":
with open(os.path.join(basedir, 'connections_post_data_completed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
else:
with open(os.path.join(basedir, 'connections_post_data_failed.json'), 'r') as f:
return Response(f.read(), mimetype='application/json')
@app.errorhandler(404)
def page_not_found(e):
return "<h1>404</h1><p>The resource could not be found.</p>", 404
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--request_status", help="completed/failed", type=str)
args = parser.parse_args()
if args.request_status:
print(args.request_status)
print("You are running the script with arguments: ")
for a in args.__dict__:
print(str(a) + ": " + str(args.__dict__[a]))
# Set up the development server on port 8000.
app.run(host='0.0.0.0', port=8000, debug=True)