yusufgundogdu commited on
Commit
6debd21
·
verified ·
1 Parent(s): 77970b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -29
app.py CHANGED
@@ -1,9 +1,8 @@
1
- from flask import Flask, request, jsonify
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
- "account": None,
35
- "error": "Platform must be either IOS or AND"
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
- "account": {
44
- "id": account["id"],
45
- "timestamp": account["timestamp"],
46
- "udid": account["udid"],
47
- "platform": account["platform"],
48
- "credit": account["credit"]
 
 
49
  },
50
  "error": None
51
  })
@@ -61,12 +50,14 @@ def get_or_create_account(platform, udid):
61
 
62
  return jsonify({
63
  "success": True,
64
- "account": {
65
- "id": new_account["id"],
66
- "timestamp": new_account["timestamp"],
67
- "udid": new_account["udid"],
68
- "platform": new_account["platform"],
69
- "credit": new_account["credit"]
 
 
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