Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
-
from flask import Flask,
|
| 2 |
import time
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
# Fake database
|
| 7 |
fake_db = {
|
| 8 |
"accounts": []
|
| 9 |
}
|
|
@@ -13,39 +12,29 @@ def generate_new_id():
|
|
| 13 |
return 1
|
| 14 |
return max(account["id"] for account in fake_db["accounts"]) + 1
|
| 15 |
|
| 16 |
-
@app.route('/')
|
| 17 |
-
def home():
|
| 18 |
-
return "stablediffusionapi test"
|
| 19 |
-
|
| 20 |
-
@app.route('/users', methods=['GET'])
|
| 21 |
-
def get_all_accounts():
|
| 22 |
-
return jsonify({
|
| 23 |
-
"success": True,
|
| 24 |
-
"users": fake_db["accounts"],
|
| 25 |
-
"error": None
|
| 26 |
-
})
|
| 27 |
-
|
| 28 |
@app.route('/account/<platform>/<udid>', methods=['GET'])
|
| 29 |
def get_or_create_account(platform, udid):
|
| 30 |
platform = platform.upper()
|
| 31 |
if platform not in ["IOS", "AND"]:
|
| 32 |
return jsonify({
|
| 33 |
"success": False,
|
| 34 |
-
"
|
| 35 |
-
"error": "
|
| 36 |
}), 400
|
| 37 |
-
|
| 38 |
account = next((acc for acc in fake_db["accounts"] if acc["udid"] == udid), None)
|
| 39 |
|
| 40 |
if account:
|
| 41 |
return jsonify({
|
| 42 |
"success": True,
|
| 43 |
-
"
|
| 44 |
-
"
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
},
|
| 50 |
"error": None
|
| 51 |
})
|
|
@@ -61,12 +50,14 @@ def get_or_create_account(platform, udid):
|
|
| 61 |
|
| 62 |
return jsonify({
|
| 63 |
"success": True,
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
},
|
| 71 |
"error": None
|
| 72 |
}), 201
|
|
|
|
| 1 |
+
from flask import Flask, jsonify
|
| 2 |
import time
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
|
|
|
| 6 |
fake_db = {
|
| 7 |
"accounts": []
|
| 8 |
}
|
|
|
|
| 12 |
return 1
|
| 13 |
return max(account["id"] for account in fake_db["accounts"]) + 1
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
@app.route('/account/<platform>/<udid>', methods=['GET'])
|
| 16 |
def get_or_create_account(platform, udid):
|
| 17 |
platform = platform.upper()
|
| 18 |
if platform not in ["IOS", "AND"]:
|
| 19 |
return jsonify({
|
| 20 |
"success": False,
|
| 21 |
+
"object": None,
|
| 22 |
+
"error": "Invalid platform"
|
| 23 |
}), 400
|
| 24 |
+
|
| 25 |
account = next((acc for acc in fake_db["accounts"] if acc["udid"] == udid), None)
|
| 26 |
|
| 27 |
if account:
|
| 28 |
return jsonify({
|
| 29 |
"success": True,
|
| 30 |
+
"object": {
|
| 31 |
+
"account": [{
|
| 32 |
+
"id": account["id"],
|
| 33 |
+
"timestamp": account["timestamp"],
|
| 34 |
+
"udid": account["udid"],
|
| 35 |
+
"platform": account["platform"],
|
| 36 |
+
"credit": account["credit"]
|
| 37 |
+
}]
|
| 38 |
},
|
| 39 |
"error": None
|
| 40 |
})
|
|
|
|
| 50 |
|
| 51 |
return jsonify({
|
| 52 |
"success": True,
|
| 53 |
+
"object": {
|
| 54 |
+
"account": [{
|
| 55 |
+
"id": new_account["id"],
|
| 56 |
+
"timestamp": new_account["timestamp"],
|
| 57 |
+
"udid": new_account["udid"],
|
| 58 |
+
"platform": new_account["platform"],
|
| 59 |
+
"credit": new_account["credit"]
|
| 60 |
+
}]
|
| 61 |
},
|
| 62 |
"error": None
|
| 63 |
}), 201
|