-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprops_api.py
More file actions
38 lines (30 loc) · 1.18 KB
/
Copy pathprops_api.py
File metadata and controls
38 lines (30 loc) · 1.18 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
from flask import Flask, request, jsonify
import redis
import json
app = Flask(__name__)
r = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True)
@app.route('/prop-hunters/<username>', methods=['POST'])
def add_user(username):
data = request.get_json()
hiding = data.get('hiding', False)
model_id = data.get('modelID', 0)
orientation = data.get('orientation', 0)
user_data = {
'username': username,
'hiding': hiding,
'modelID': model_id,
'orientation': orientation
}
r.set(username, json.dumps(user_data))
return jsonify({"message": "User data added successfully!"}), 200
@app.route('/prop-hunters/<username>', methods=['GET'])
def get_user(username):
response_data = []
for user in username.split(','):
user = user.strip()
user_data = r.get(user)
if user_data:
response_data.append(json.loads(user_data))
else:
response_data.append({"username": user, "error": "User not found"})
return jsonify(response_data), 200