-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
145 lines (109 loc) · 3.39 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# import json
# from flask import Flask, jsonify, request, render_template
# app = Flask(__name__)
# employees = [
# { 'id': 1, 'name': 'Ashley' },
# { 'id': 2, 'name': 'Kate' },
# { 'id': 3, 'name': 'Joe' },
# {'id': 4, 'name': 'Maria'},
# {'id': 5, 'name': 'neew uswer'}
# ]
"""Json Dumps is used to dump a dict into string, whereas dump is used to dump a dict into a file"""
# nextEmployeeId = 5
# @app.route('/')
# def hello_world():
# return render_template('login.html')
# # @app.route('/employees', methods=['GET'])
# # def get_employees():
# # return jsonify(employees)
# @app.route('/employees/<int:id>', methods=['GET'])
# def get_employee_by_id(id: int):
# employee = get_employee(id)
# if employee is None:
# return jsonify({ 'error': 'Employee does not exist'}), 404
# return jsonify(employee)
# @app.route('/employees', methods=['POST'])
# def create_employee():
# global nextEmployeeId
# employee = json.load(request.data)
# employee['id'] = nextEmployeeId
# nextEmployeeId += 1
# employees.append(employee)
# @app.route('/render', methods= ['POST'])
# def render_file():
# return "hai"
# def get_employee(id):
# return next((e for e in employees if e['id'] == id), None)
'''
1. User management: User acceptance
2. If yes, 200 status, valid
3. He can start purchasing
'''
# if __name__ == '__main__':
# app.run(port=5000)
from flask import Flask, render_template, request, jsonify, json
app = Flask(__name__, template_folder='template')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api-endpoint', methods=['POST', 'GET'])
def handle_api_request():
try:
# Assuming the payload is JSON
data = request.json
# Process the data as needed
# ...
# Return a sample response
response_data = {'status': 'success', 'message': 'Request processed successfully'}
return jsonify(response_data)
except Exception as e:
# Handle exceptions
response_data = {'status': 'error', 'message': str(e)}
return jsonify(response_data), 500
@app.route('/signin', methods=['POST'])
def handle_new_request():
username = request.form['username']
password = request.form['password']
if username and password:
return json.dumps({'validation': validateUser(username, password)})
def validateUser(username, password):
if username == "abuharis":
return True
else:
return True
app.run(debug=True)
# new = {
# "responseStatus": "fail",
# "responseHeader": {
# "now": 1465840430014,
# "status": "fail",
# "requestId": True
# },
# "responseData": {
# "validationErrors": [
# {
# "category": "Vault Existence",
# "rule": "Only service or management vaults may exist",
# "objects": []
# },
# {
# "category": "API",
# "rule": "access pool(s) must change its API type to 'Cloud Storage Object'",
# "objects": [
# {
# "type": "accessPool",
# "id": 8,
# "name": "Access Pool 3"
# }
# ]
# },
# {
# "category": "Mirror",
# "rule": "Container Mode not supported on dsNets with mirrors",
# "objects": []
# }
# ],
# "migrationErrors": []
# }
# }
# print(json.dumps(new['responseData']['validationErrors'][1], indent = 4))