-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.py
More file actions
65 lines (51 loc) · 1.76 KB
/
ex2.py
File metadata and controls
65 lines (51 loc) · 1.76 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
61
62
63
64
65
from flask import Flask
from flask import jsonify
from flask import request
app = Flask(__name__)
about = {
"version": "0.1",
"name": "5G UDR Service"
}
subscriber_list = []
@app.route('/', methods=['GET'])
def default():
return "This is a 5G UDR Service!"
@app.route('/about', methods=['GET'])
def about():
return jsonify({'about': about})
def check_if_subscriber_exists(input_imsi):
print("sub org list", subscriber_list)
# Check is list is empty
if not subscriber_list:
print("List is empty")
return False
print("Checking if this imsi value already exists", input_imsi)
# Loop through list and check if value exists in any "imsi" field
for entry in subscriber_list:
print(entry)
for key, value in entry.items():
if key == 'imsi':
print("The key and value are ({}) = ({})".format(key, value))
print("Compare value and input_imsi: ", value, input_imsi)
if (value == input_imsi):
print("This imsi already exists", input_imsi)
return True
return False
@app.route('/createSubscriber', methods=['POST'])
def createSubscriber():
content_type = request.headers.get('Content-Type')
if (content_type == 'application/json'):
data = request.json
if (check_if_subscriber_exists(data['imsi']) == False):
print("New Subscriber added")
subscriber_list.append(data)
return (data)
else:
return "Subscriber already exists"
else:
return 'Content-Type not supported!'
@app.route('/listSubscriber', methods=['GET'])
def listSubscriber():
return jsonify({'subscriber list': subscriber_list})
if __name__ == "__main__":
app.run(debug=True)