foxapi 1.6.7__tar.gz → 1.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {foxapi-1.6.7 → foxapi-1.7.1}/PKG-INFO +3 -3
- {foxapi-1.6.7 → foxapi-1.7.1}/README.md +2 -2
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/__init__.py +1 -1
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/foxapi.py +88 -92
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi.egg-info/PKG-INFO +3 -3
- {foxapi-1.6.7 → foxapi-1.7.1}/LICENSE +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/10.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/11.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/12.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/13.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/14.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/15.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/16.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/17.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/18.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/19.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/20.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/21.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/22.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/23.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/27.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/28.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/29.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/30.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/32.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/33.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/34.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/35.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/37.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/38.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/39.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/40.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/41.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/45.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/46.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/47.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/5.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/51.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/52.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/53.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/54.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/56.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/57.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/58.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/59.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/6.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/60.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/61.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/62.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/7.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/70.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/71.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/72.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/75.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/8.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/83.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/84.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/9.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/DebugIcon.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconCivicCenter.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconFortCursed.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconForwardBase1.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconScorchedTown.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconTownHall.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapIcons/MapIconVictory.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapAcrithiaHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapAllodsBightHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapAshFieldsHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapBasinSionnachHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapCallahansPassageHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapCallumsCapeHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapClahstraHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapClansheadValleyHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapDeadLandsHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapDrownedValeHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapEndlessShoreHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapFarranacCoastHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapFishermansRowHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapGodcroftsHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapGreatMarchHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapHeartlandsHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapHomeRegionC.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapHomeRegionW.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapHowlCountyHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapKalokaiHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapKingsCageHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapLinnMercyHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapLochMorHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapMarbanHollow.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapMooringCountyHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapMorgensCrossingHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapNevishLineHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapOarbreakerHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapOriginHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapReachingTrailHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapReaversPassHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapRedRiverHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapSableportHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapShackledChasmHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapSpeakingWoodsHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapStemaLandingHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapStlicanShelfHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapStonecradleHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapTempestIslandHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapTerminusHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapTheFingersHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapUmbralWildwoodHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapViperPitHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapWeatheredExpanseHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/Images/MapsHex/MapWestgateHex.png +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi/utils.py +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi.egg-info/SOURCES.txt +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi.egg-info/dependency_links.txt +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi.egg-info/requires.txt +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/foxapi.egg-info/top_level.txt +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/setup.cfg +0 -0
- {foxapi-1.6.7 → foxapi-1.7.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: foxapi
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.1
|
|
4
4
|
Summary: A wrapper for the foxhole API
|
|
5
5
|
Home-page: https://github.com/ThePhoenix78/FoxAPI
|
|
6
6
|
Download-URL: https://github.com/ThePhoenix78/FoxAPI/tarball/master
|
|
@@ -151,11 +151,11 @@ load_hexagon_map(hexagon: str) -> pillow.Image
|
|
|
151
151
|
- Loads the PNG map for the specified hexagon.
|
|
152
152
|
|
|
153
153
|
```py
|
|
154
|
-
make_map_png(hexagon: str,
|
|
154
|
+
make_map_png(hexagon: str, icons: str | list = "all", colored: bool = False, dynamic: dict = None, static: dict = None) -> pillow.Image
|
|
155
155
|
```
|
|
156
156
|
- Generates a PNG image of the hexagon map with all the icons associated to each faction in their respective colors (included fields and town base). Only public data will be present.
|
|
157
157
|
- colored -> display each region in the team's color
|
|
158
|
-
-
|
|
158
|
+
- icons -> display selected building in their team's color
|
|
159
159
|
|
|
160
160
|
```py
|
|
161
161
|
calculate_death_rate(hexagon: str = None, war_report: dict = None): -> dict
|
|
@@ -120,11 +120,11 @@ load_hexagon_map(hexagon: str) -> pillow.Image
|
|
|
120
120
|
- Loads the PNG map for the specified hexagon.
|
|
121
121
|
|
|
122
122
|
```py
|
|
123
|
-
make_map_png(hexagon: str,
|
|
123
|
+
make_map_png(hexagon: str, icons: str | list = "all", colored: bool = False, dynamic: dict = None, static: dict = None) -> pillow.Image
|
|
124
124
|
```
|
|
125
125
|
- Generates a PNG image of the hexagon map with all the icons associated to each faction in their respective colors (included fields and town base). Only public data will be present.
|
|
126
126
|
- colored -> display each region in the team's color
|
|
127
|
-
-
|
|
127
|
+
- icons -> display selected building in their team's color
|
|
128
128
|
|
|
129
129
|
```py
|
|
130
130
|
calculate_death_rate(hexagon: str = None, war_report: dict = None): -> dict
|
|
@@ -75,7 +75,7 @@ class FoxAPI():
|
|
|
75
75
|
self.session.close()
|
|
76
76
|
|
|
77
77
|
"""
|
|
78
|
-
REQUESTS SYNC
|
|
78
|
+
---------------------------------------- REQUESTS SYNC ----------------------------------------
|
|
79
79
|
"""
|
|
80
80
|
|
|
81
81
|
def get_data_sync(self, endpoint: str, etag: str = None, use_cache: bool = None) -> APIResponse:
|
|
@@ -93,7 +93,7 @@ class FoxAPI():
|
|
|
93
93
|
headers: dict = {"etag": ""}
|
|
94
94
|
|
|
95
95
|
with self.session.get(f"{self.base_api}{endpoint}", headers=headers) as data:
|
|
96
|
-
self.etag[endpoint]
|
|
96
|
+
self.etag[endpoint] = data.headers.get("ETag", self.etag.get(endpoint))
|
|
97
97
|
|
|
98
98
|
if data.status_code == 200:
|
|
99
99
|
self.cache[endpoint] = data.json()
|
|
@@ -109,7 +109,7 @@ class FoxAPI():
|
|
|
109
109
|
return data
|
|
110
110
|
|
|
111
111
|
"""
|
|
112
|
-
REQUESTS ASYNC
|
|
112
|
+
---------------------------------------- REQUESTS ASYNC ----------------------------------------
|
|
113
113
|
"""
|
|
114
114
|
|
|
115
115
|
async def get_data(self, endpoint: str, session: aiohttp.ClientSession = None, etag: str = None, use_cache: bool = None):
|
|
@@ -129,7 +129,7 @@ class FoxAPI():
|
|
|
129
129
|
if session is None:
|
|
130
130
|
async with aiohttp.ClientSession() as session:
|
|
131
131
|
async with session.get(f"{self.base_api}{endpoint}", headers=headers) as data:
|
|
132
|
-
self.etag[endpoint]
|
|
132
|
+
self.etag[endpoint] = data.headers.get("ETag", self.etag.get(endpoint))
|
|
133
133
|
data_json = await data.json()
|
|
134
134
|
|
|
135
135
|
if data.status == 200:
|
|
@@ -142,11 +142,11 @@ class FoxAPI():
|
|
|
142
142
|
return APIResponse(headers=data.headers, json=data_json, status_code=data.status, hexagon=hexagon, is_cache=False)
|
|
143
143
|
else:
|
|
144
144
|
async with session.get(f"{self.base_api}{endpoint}", headers=headers) as data:
|
|
145
|
-
self.etag[endpoint]
|
|
145
|
+
self.etag[endpoint] = data.headers.get("ETag", self.etag.get(endpoint))
|
|
146
146
|
data_json: dict = await data.json()
|
|
147
147
|
|
|
148
148
|
if data.status == 200:
|
|
149
|
-
self.cache[endpoint]
|
|
149
|
+
self.cache[endpoint] = data_json
|
|
150
150
|
return APIResponse(headers=data.headers, json=data_json, status_code=data.status, hexagon=hexagon, is_cache=False)
|
|
151
151
|
|
|
152
152
|
elif data.status == 304:
|
|
@@ -160,7 +160,7 @@ class FoxAPI():
|
|
|
160
160
|
return data
|
|
161
161
|
|
|
162
162
|
"""
|
|
163
|
-
TOOLS
|
|
163
|
+
---------------------------------------- URL TOOLS ----------------------------------------
|
|
164
164
|
"""
|
|
165
165
|
|
|
166
166
|
def _get_valid_endpoints(self):
|
|
@@ -186,16 +186,14 @@ class FoxAPI():
|
|
|
186
186
|
if hexagon in self._available_hexagons[i]:
|
|
187
187
|
return self.available_hexagons[i]
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
def _retrieve_hexagon_from_endpoint(self, endpoint: str):
|
|
189
|
+
def _retrieve_hexagon_from_endpoint(self, endpoint: str) -> str:
|
|
192
190
|
if endpoint.startswith("/"):
|
|
193
191
|
endpoint = endpoint[1:]
|
|
194
192
|
|
|
195
193
|
if "maps/" in endpoint or "warReport/" in endpoint:
|
|
196
194
|
return endpoint.split("/")[1]
|
|
197
195
|
|
|
198
|
-
def _format_endpoint(self, endpoint: str):
|
|
196
|
+
def _format_endpoint(self, endpoint: str) -> str:
|
|
199
197
|
if "maps/" in endpoint or "warReport/" in endpoint:
|
|
200
198
|
old_hexa: str = self._retrieve_hexagon_from_endpoint(endpoint)
|
|
201
199
|
hexagon: str = self._format_hexagon(old_hexa)
|
|
@@ -203,10 +201,14 @@ class FoxAPI():
|
|
|
203
201
|
|
|
204
202
|
return endpoint
|
|
205
203
|
|
|
206
|
-
|
|
204
|
+
"""
|
|
205
|
+
---------------------------------------- ADDITIONAL TOOLS ----------------------------------------
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
def calc_distance(self, p1: tuple, p2: tuple) -> float:
|
|
207
209
|
return math.sqrt((abs(p1[0] - p2[0]) ** 2) + (abs(p1[1] - p2[1]) ** 2))
|
|
208
210
|
|
|
209
|
-
def bissectrice(self, p1: tuple, p2: tuple):
|
|
211
|
+
def bissectrice(self, p1: tuple, p2: tuple) -> tuple:
|
|
210
212
|
mx, my = (p1[0] + p2[0]) / 2, (p1[1] + p2[1]) / 2
|
|
211
213
|
|
|
212
214
|
dx, dy = p2[0] - p1[0], p2[1] - p1[1]
|
|
@@ -218,7 +220,22 @@ class FoxAPI():
|
|
|
218
220
|
else:
|
|
219
221
|
return None, mx
|
|
220
222
|
|
|
221
|
-
def
|
|
223
|
+
def _calc_death_rate(self, hexagon: str, war_report: dict) -> dict[str, int]:
|
|
224
|
+
war_c: int = war_report['colonialCasualties']
|
|
225
|
+
war_w: int = war_report['wardenCasualties']
|
|
226
|
+
|
|
227
|
+
if self._cpt_rate > self._cpt_rate_total or not self._death_rate_c.get(hexagon):
|
|
228
|
+
self._death_rate_c[hexagon] = war_c
|
|
229
|
+
self._death_rate_w[hexagon] = war_w
|
|
230
|
+
self._cpt_rate: int = 0
|
|
231
|
+
|
|
232
|
+
return {"colonials": war_c - self._death_rate_c[hexagon], "wardens": war_w - self._death_rate_w[hexagon], "hexagon": hexagon}
|
|
233
|
+
|
|
234
|
+
"""
|
|
235
|
+
---------------------------------------- IMAGE TOOLS ----------------------------------------
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
def load_hexagon_map(self, hexagon: str) -> Image:
|
|
222
239
|
if self._safe_mode:
|
|
223
240
|
hexagon: str = self._format_hexagon(hexagon)
|
|
224
241
|
|
|
@@ -226,7 +243,7 @@ class FoxAPI():
|
|
|
226
243
|
|
|
227
244
|
return Image.open(img_path).convert("RGBA")
|
|
228
245
|
|
|
229
|
-
def color_icon(self, image: Image, team: str = None)
|
|
246
|
+
def color_icon(self, image: Image, team: str = None):
|
|
230
247
|
f: int = 50
|
|
231
248
|
g: int = 165
|
|
232
249
|
|
|
@@ -254,7 +271,7 @@ class FoxAPI():
|
|
|
254
271
|
image.putpixel((x, y), new_color)
|
|
255
272
|
|
|
256
273
|
|
|
257
|
-
def color_regions(self, image: Image, dynamic: dict, static: dict)
|
|
274
|
+
def color_regions(self, image: Image, dynamic: dict, static: dict):
|
|
258
275
|
captured_towns: dict = self.get_captured_towns_sync(dynamic=dynamic, static=static)
|
|
259
276
|
map_info = [data for data in static["mapTextItems"] if data["mapMarkerType"] == "Major"]
|
|
260
277
|
|
|
@@ -292,13 +309,22 @@ class FoxAPI():
|
|
|
292
309
|
new_color: tuple = (current_pixel[0]//2 + color[0], current_pixel[1]//2 + color[1], current_pixel[2]//2 + color[2])
|
|
293
310
|
image.putpixel((x, y), new_color)
|
|
294
311
|
|
|
295
|
-
def add_icons(self, image: Image, dynamic: dict):
|
|
312
|
+
def add_icons(self, image: Image, icons: str | list, dynamic: dict):
|
|
296
313
|
icon_size: tuple = self._icon_size
|
|
297
314
|
|
|
315
|
+
if isinstance(icons, list):
|
|
316
|
+
icons: list[str] = [str(i) for i in icons]
|
|
317
|
+
|
|
298
318
|
for data in dynamic["mapItems"]:
|
|
299
319
|
icon: str = data['iconType']
|
|
300
320
|
team: str = data["teamId"].strip()
|
|
301
321
|
|
|
322
|
+
if icons == "all":
|
|
323
|
+
pass
|
|
324
|
+
|
|
325
|
+
elif str(icon) not in icons:
|
|
326
|
+
continue
|
|
327
|
+
|
|
302
328
|
try:
|
|
303
329
|
img_path: str = os.path.join(self._img_dir, "MapIcons", f"{icon}.png")
|
|
304
330
|
img2 = Image.open(img_path).convert("RGBA").resize(icon_size)
|
|
@@ -310,8 +336,27 @@ class FoxAPI():
|
|
|
310
336
|
|
|
311
337
|
image.paste(img2, (int(data["x"] * self.img_width), int(data["y"] * self.img_height)), mask=img2)
|
|
312
338
|
|
|
339
|
+
def associate_towns(self, dynamic: dict, static: dict) -> dict:
|
|
340
|
+
captured_towns: dict = {}
|
|
341
|
+
icons: list = [45, 46, 47, 56, 57, 58] # Town halls and relics
|
|
342
|
+
|
|
343
|
+
for s in static['mapTextItems']:
|
|
344
|
+
deltas: list = []
|
|
345
|
+
faction: list = []
|
|
346
|
+
|
|
347
|
+
if s['mapMarkerType'] == 'Major':
|
|
348
|
+
for d in dynamic['mapItems']:
|
|
349
|
+
if d['iconType'] in icons:
|
|
350
|
+
faction.append(d['teamId'])
|
|
351
|
+
deltas.append(self.calc_distance((s['x'], s['y']), (d['x'], d['y'])))
|
|
352
|
+
|
|
353
|
+
captured_towns[s['text']] = faction[deltas.index(min(deltas))]
|
|
354
|
+
|
|
355
|
+
return captured_towns
|
|
356
|
+
|
|
357
|
+
|
|
313
358
|
"""
|
|
314
|
-
ASYNC METHODS
|
|
359
|
+
---------------------------------------- ASYNC METHODS ----------------------------------------
|
|
315
360
|
"""
|
|
316
361
|
|
|
317
362
|
async def get_maps(self, use_cache: bool = True):
|
|
@@ -344,10 +389,10 @@ class FoxAPI():
|
|
|
344
389
|
return data.json
|
|
345
390
|
|
|
346
391
|
"""
|
|
347
|
-
ADDITIONAL ASYNC METHODS
|
|
392
|
+
---------------------------------------- ADDITIONAL ASYNC METHODS ----------------------------------------
|
|
348
393
|
"""
|
|
349
394
|
|
|
350
|
-
async def get_captured_towns(self, hexagon: str = None, dynamic: dict = None, static: dict = None):
|
|
395
|
+
async def get_captured_towns(self, hexagon: str = None, dynamic: dict = None, static: dict = None) -> dict[str, str]:
|
|
351
396
|
if hexagon is not None and static is None and dynamic is None:
|
|
352
397
|
static: dict = await self.get_static(hexagon, use_cache=True)
|
|
353
398
|
dynamic: dict = await self.get_dynamic(hexagon)
|
|
@@ -355,25 +400,10 @@ class FoxAPI():
|
|
|
355
400
|
if static is None or dynamic is None:
|
|
356
401
|
raise FoxAPIError("Please pass the required parameters (hexagon or (static and dynamic))")
|
|
357
402
|
|
|
358
|
-
|
|
359
|
-
icons: list = [45, 46, 47, 56, 57, 58] # Town halls and relics
|
|
403
|
+
return self.associate_towns(dynamic=dynamic, static=static)
|
|
360
404
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
faction: list = []
|
|
364
|
-
|
|
365
|
-
if s['mapMarkerType'] == 'Major':
|
|
366
|
-
for d in dynamic['mapItems']:
|
|
367
|
-
if d['iconType'] in icons:
|
|
368
|
-
faction.append(d['teamId'])
|
|
369
|
-
deltas.append(self.calc_distance((s['x'], s['y']), (d['x'], d['y'])))
|
|
370
|
-
|
|
371
|
-
captured_towns[s['text']]: str = faction[deltas.index(min(deltas))]
|
|
372
|
-
|
|
373
|
-
return captured_towns
|
|
374
|
-
|
|
375
|
-
async def make_map_png(self, hexagon: str, show_icons: bool = True, colored: bool = False, dynamic: dict = None, static: dict = None):
|
|
376
|
-
if dynamic is None and (show_icons or colored):
|
|
405
|
+
async def make_map_png(self, hexagon: str, icons: str | list[int | str] = "all", colored: bool = False, dynamic: dict = None, static: dict = None):
|
|
406
|
+
if dynamic is None and (icons or colored):
|
|
377
407
|
dynamic: dict = await self.get_dynamic(hexagon=hexagon)
|
|
378
408
|
|
|
379
409
|
if static is None and colored:
|
|
@@ -384,8 +414,8 @@ class FoxAPI():
|
|
|
384
414
|
if colored:
|
|
385
415
|
self.color_regions(image=img1, dynamic=dynamic, static=static)
|
|
386
416
|
|
|
387
|
-
if
|
|
388
|
-
self.add_icons(image=img1, dynamic=dynamic)
|
|
417
|
+
if icons:
|
|
418
|
+
self.add_icons(image=img1, icons=icons, dynamic=dynamic)
|
|
389
419
|
|
|
390
420
|
return img1
|
|
391
421
|
|
|
@@ -399,15 +429,7 @@ class FoxAPI():
|
|
|
399
429
|
if war_report is None:
|
|
400
430
|
raise FoxAPIError("Please pass the required parameters (hexagon or war_report)")
|
|
401
431
|
|
|
402
|
-
|
|
403
|
-
war_w: int = war_report['wardenCasualties']
|
|
404
|
-
|
|
405
|
-
if self._cpt_rate > self._cpt_rate_total or not self._death_rate_c.get(hexagon):
|
|
406
|
-
self._death_rate_c[hexagon]: int = war_c
|
|
407
|
-
self._death_rate_w[hexagon]: int = war_w
|
|
408
|
-
self._cpt_rate: int = 0
|
|
409
|
-
|
|
410
|
-
return {"colonials": war_c - self._death_rate_c[hexagon], "wardens": war_w - self._death_rate_w[hexagon], "hexagon": hexagon}
|
|
432
|
+
return self._calc_death_rate(hexagon=hexagon, war_report=war_report)
|
|
411
433
|
|
|
412
434
|
async def get_hexagon_data(self, hexagon: str, use_cache: bool = None):
|
|
413
435
|
if self._safe_mode:
|
|
@@ -423,7 +445,7 @@ class FoxAPI():
|
|
|
423
445
|
return HexagonObject(hexagon=hexagon, war_report=war_report, static=static, dynamic=dynamic, captured_towns=captured_towns, casualty_rate=casualty_rate)
|
|
424
446
|
|
|
425
447
|
"""
|
|
426
|
-
SYNC METHODS
|
|
448
|
+
---------------------------------------- SYNC METHODS ----------------------------------------
|
|
427
449
|
"""
|
|
428
450
|
|
|
429
451
|
def get_maps_sync(self, use_cache: bool = True):
|
|
@@ -451,10 +473,10 @@ class FoxAPI():
|
|
|
451
473
|
return self.get_data_sync(endpoint=f"/warReport/{hexagon}", use_cache=use_cache).json
|
|
452
474
|
|
|
453
475
|
"""
|
|
454
|
-
ADDITIONAL SYNC METHODS
|
|
476
|
+
---------------------------------------- ADDITIONAL SYNC METHODS ----------------------------------------
|
|
455
477
|
"""
|
|
456
478
|
|
|
457
|
-
def get_captured_towns_sync(self, hexagon: str = None, dynamic: dict = None, static: dict = None):
|
|
479
|
+
def get_captured_towns_sync(self, hexagon: str = None, dynamic: dict = None, static: dict = None) -> dict[str, str]:
|
|
458
480
|
if hexagon is not None and static is None and dynamic is None:
|
|
459
481
|
static: dict = self.get_static_sync(hexagon, use_cache=True)
|
|
460
482
|
dynamic: dict = self.get_dynamic_sync(hexagon)
|
|
@@ -462,25 +484,10 @@ class FoxAPI():
|
|
|
462
484
|
if static is None or dynamic is None:
|
|
463
485
|
raise FoxAPIError("Please pass the required parameters (static and dynamic or hexagon)")
|
|
464
486
|
|
|
465
|
-
|
|
466
|
-
icons: list = [45, 46, 47, 56, 57, 58] # Town halls and relics
|
|
487
|
+
return self.associate_towns(dynamic=dynamic, static=static)
|
|
467
488
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
faction: list = []
|
|
471
|
-
|
|
472
|
-
if s['mapMarkerType'] == 'Major':
|
|
473
|
-
for d in dynamic['mapItems']:
|
|
474
|
-
if d['iconType'] in icons:
|
|
475
|
-
faction.append(d['teamId'])
|
|
476
|
-
deltas.append(self.calc_distance((s['x'], s['y']), (d['x'], d['y'])))
|
|
477
|
-
|
|
478
|
-
captured_towns[s['text']]: str = faction[deltas.index(min(deltas))]
|
|
479
|
-
|
|
480
|
-
return captured_towns
|
|
481
|
-
|
|
482
|
-
def make_map_png_sync(self, hexagon: str, show_icons: bool = True, colored: bool = False, dynamic: dict = None, static: dict = None):
|
|
483
|
-
if dynamic is None and (show_icons or colored):
|
|
489
|
+
def make_map_png_sync(self, hexagon: str, icons: str | list[int | str] = "all", colored: bool = False, dynamic: dict = None, static: dict = None):
|
|
490
|
+
if dynamic is None and (icons or colored):
|
|
484
491
|
dynamic: dict = self.get_dynamic_sync(hexagon=hexagon)
|
|
485
492
|
|
|
486
493
|
if static is None and colored:
|
|
@@ -491,8 +498,8 @@ class FoxAPI():
|
|
|
491
498
|
if colored:
|
|
492
499
|
self.color_regions(image=img1, dynamic=dynamic, static=static)
|
|
493
500
|
|
|
494
|
-
if
|
|
495
|
-
self.add_icons(image=img1, dynamic=dynamic)
|
|
501
|
+
if icons:
|
|
502
|
+
self.add_icons(image=img1, icons=icons, dynamic=dynamic)
|
|
496
503
|
|
|
497
504
|
return img1
|
|
498
505
|
|
|
@@ -506,18 +513,7 @@ class FoxAPI():
|
|
|
506
513
|
if war_report is None:
|
|
507
514
|
raise FoxAPIError("Please pass the required parameters (hexagon or war_report)")
|
|
508
515
|
|
|
509
|
-
|
|
510
|
-
war_w: int = war_report['wardenCasualties']
|
|
511
|
-
|
|
512
|
-
dph_c: int = war_c
|
|
513
|
-
dph_w: int = war_w
|
|
514
|
-
|
|
515
|
-
if self._cpt_rate > self._cpt_rate_total or not self._death_rate_c.get(hexagon):
|
|
516
|
-
self._death_rate_c[hexagon]: int = war_c
|
|
517
|
-
self._death_rate_w[hexagon]: int = war_w
|
|
518
|
-
self._cpt_rate: int = 0
|
|
519
|
-
|
|
520
|
-
return {"colonials": dph_c - self._death_rate_c[hexagon], "wardens": dph_w - self._death_rate_w[hexagon], "hexagon": hexagon}
|
|
516
|
+
return self._calc_death_rate(hexagon=hexagon, war_report=war_report)
|
|
521
517
|
|
|
522
518
|
def get_hexagon_data_sync(self, hexagon: str, use_cache: bool = None):
|
|
523
519
|
if self._safe_mode:
|
|
@@ -533,7 +529,7 @@ class FoxAPI():
|
|
|
533
529
|
return HexagonObject(hexagon=hexagon, war_report=war_report, static=static, dynamic=dynamic, captured_towns=captured_towns, casualty_rate=casualty_rate)
|
|
534
530
|
|
|
535
531
|
"""
|
|
536
|
-
CRAWLER ASYNC
|
|
532
|
+
---------------------------------------- CRAWLER ASYNC ----------------------------------------
|
|
537
533
|
"""
|
|
538
534
|
|
|
539
535
|
async def _listener(self):
|
|
@@ -556,7 +552,7 @@ class FoxAPI():
|
|
|
556
552
|
await asyncio.sleep(self._refresh)
|
|
557
553
|
|
|
558
554
|
"""
|
|
559
|
-
CRAWLER SYNC
|
|
555
|
+
---------------------------------------- CRAWLER SYNC ----------------------------------------
|
|
560
556
|
"""
|
|
561
557
|
|
|
562
558
|
def _listener_sync(self):
|
|
@@ -588,7 +584,7 @@ class FoxAPI():
|
|
|
588
584
|
# threading.Thread(target=self.start_async_thread).start()
|
|
589
585
|
|
|
590
586
|
"""
|
|
591
|
-
ASYNC TOOLS
|
|
587
|
+
---------------------------------------- ASYNC TOOLS ----------------------------------------
|
|
592
588
|
"""
|
|
593
589
|
def add_task(self, function: callable, args: any = "no_args"):
|
|
594
590
|
self.waiting_list.append([function, args])
|
|
@@ -670,7 +666,7 @@ class FoxAPI():
|
|
|
670
666
|
loop.call_soon_threadsafe(loop.stop)
|
|
671
667
|
|
|
672
668
|
"""
|
|
673
|
-
|
|
669
|
+
----------------------------------------EVENT WRAPPER ----------------------------------------
|
|
674
670
|
"""
|
|
675
671
|
|
|
676
672
|
def on_api_update(self, callback: callable = None, endpoints: list = None):
|
|
@@ -686,7 +682,7 @@ class FoxAPI():
|
|
|
686
682
|
|
|
687
683
|
if self._safe_mode:
|
|
688
684
|
for i in range(len(endpoints)):
|
|
689
|
-
endpoints[i]
|
|
685
|
+
endpoints[i] = self._format_endpoint(endpoints[i])
|
|
690
686
|
|
|
691
687
|
for i in range(len(endpoints)):
|
|
692
688
|
if not self._is_valid_endpoint(endpoints[i]):
|
|
@@ -696,7 +692,7 @@ class FoxAPI():
|
|
|
696
692
|
self._check_listener(asyncio.iscoroutinefunction(func))
|
|
697
693
|
|
|
698
694
|
for endpoint in endpoints:
|
|
699
|
-
self._to_call[endpoint]
|
|
695
|
+
self._to_call[endpoint] = func
|
|
700
696
|
|
|
701
697
|
return func
|
|
702
698
|
|
|
@@ -718,7 +714,7 @@ class FoxAPI():
|
|
|
718
714
|
|
|
719
715
|
if self._safe_mode:
|
|
720
716
|
for i in range(len(hexagons)):
|
|
721
|
-
hexagons[i]
|
|
717
|
+
hexagons[i] = self._format_hexagon(hexagons[i])
|
|
722
718
|
|
|
723
719
|
if not self._is_valid_hexagon(hexagons[i]):
|
|
724
720
|
raise HexagonError("Please enter a valid hexagon (FoxAPi.available_hexagons")
|
|
@@ -730,7 +726,7 @@ class FoxAPI():
|
|
|
730
726
|
ends: list = [f"/warReport/{hexagon}", f"/maps/{hexagon}/dynamic/public", f"/maps/{hexagon}/static"]
|
|
731
727
|
|
|
732
728
|
for hexa in ends:
|
|
733
|
-
self._to_call[hexa]
|
|
729
|
+
self._to_call[hexa] = func
|
|
734
730
|
self._hex_call.append(hexa)
|
|
735
731
|
|
|
736
732
|
return func
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: foxapi
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.1
|
|
4
4
|
Summary: A wrapper for the foxhole API
|
|
5
5
|
Home-page: https://github.com/ThePhoenix78/FoxAPI
|
|
6
6
|
Download-URL: https://github.com/ThePhoenix78/FoxAPI/tarball/master
|
|
@@ -151,11 +151,11 @@ load_hexagon_map(hexagon: str) -> pillow.Image
|
|
|
151
151
|
- Loads the PNG map for the specified hexagon.
|
|
152
152
|
|
|
153
153
|
```py
|
|
154
|
-
make_map_png(hexagon: str,
|
|
154
|
+
make_map_png(hexagon: str, icons: str | list = "all", colored: bool = False, dynamic: dict = None, static: dict = None) -> pillow.Image
|
|
155
155
|
```
|
|
156
156
|
- Generates a PNG image of the hexagon map with all the icons associated to each faction in their respective colors (included fields and town base). Only public data will be present.
|
|
157
157
|
- colored -> display each region in the team's color
|
|
158
|
-
-
|
|
158
|
+
- icons -> display selected building in their team's color
|
|
159
159
|
|
|
160
160
|
```py
|
|
161
161
|
calculate_death_rate(hexagon: str = None, war_report: dict = None): -> dict
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|