-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.py
97 lines (82 loc) · 2.79 KB
/
Helper.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
import requests
import ast
from discord import Color
USER_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/users/"
FACTION_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/factions/"
MAPS_URL="https://cataclysmapi20211218110154.azurewebsites.net/api/maps/"
PINK = Color.from_rgb(255,185,209)
def getAllUsers():
response = requests.get(USER_URL)
if response.status_code != 200:
return None
else:
jsonResponse = ast.literal_eval(str(response.json()))
return jsonResponse
def getUserData(id):
url = USER_URL + str(id)
response = requests.get(url)
if response.status_code != 200:
return None
else:
jsonResponse = ast.literal_eval(str(response.json()))
return jsonResponse
def getAllFactions():
response = requests.get(FACTION_URL)
if response.status_code != 200:
return None
else:
jsonResponse = ast.literal_eval(str(response.json()))
return jsonResponse
def getAllMapTiles():
response = requests.get(MAPS_URL)
if response.status_code != 200:
return None
else:
jsonResponse = ast.literal_eval(str(response.json()))
return jsonResponse
def getMapTile(id):
response = requests.get(MAPS_URL + str(id))
if response.status_code != 200:
return None
else:
jsonResponse = ast.literal_eval(str(response.json()))
return jsonResponse
def claimMapTile(id,newOwner):
response = requests.get(MAPS_URL + str(id))
if response.status_code != 200:
return None
else:
jsonRespnse = ast.literal_eval(str(response.json()))
jsonRespnse["plotOwner"] = newOwner
response = requests.put(MAPS_URL + str(id),json=jsonRespnse)
print(response.content)
if response.status_code != 204:
return None
else:
return True
def getUserFaction(id):
response = getAllFactions()
for x in response:
factionData = ast.literal_eval(str(x))
if ',' in factionData["factionMembers"]:
members = str(factionData["factionMembers"]).split(",")
for y in members:
if y == str(id):
return factionData
else:
if factionData["factionMembers"] == str(id):
return factionData
def updateFaction(faction):
json = {
"id":faction["id"],
"factionName":faction["factionName"],
"factionIncome":faction["factionIncome"],
"factionMembers":faction["factionMembers"],
"factionLogo":faction["factionLogo"],
"attack":faction["attack"],
"defense":faction["defense"],
"utility":faction["utility"],
"balance":faction["balance"]
}
response = requests.put(FACTION_URL+str(faction["id"]),json=json)
return response