foxapi 1.6.6__tar.gz → 1.7.0__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.
Files changed (118) hide show
  1. {foxapi-1.6.6 → foxapi-1.7.0}/PKG-INFO +2 -2
  2. foxapi-1.7.0/foxapi/__init__.py +27 -0
  3. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/foxapi.py +88 -92
  4. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi.egg-info/PKG-INFO +2 -2
  5. {foxapi-1.6.6 → foxapi-1.7.0}/setup.py +5 -3
  6. foxapi-1.6.6/foxapi/__init__.py +0 -2
  7. {foxapi-1.6.6 → foxapi-1.7.0}/LICENSE +0 -0
  8. {foxapi-1.6.6 → foxapi-1.7.0}/README.md +0 -0
  9. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/10.png +0 -0
  10. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/11.png +0 -0
  11. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/12.png +0 -0
  12. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/13.png +0 -0
  13. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/14.png +0 -0
  14. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/15.png +0 -0
  15. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/16.png +0 -0
  16. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/17.png +0 -0
  17. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/18.png +0 -0
  18. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/19.png +0 -0
  19. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/20.png +0 -0
  20. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/21.png +0 -0
  21. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/22.png +0 -0
  22. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/23.png +0 -0
  23. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/27.png +0 -0
  24. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/28.png +0 -0
  25. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/29.png +0 -0
  26. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/30.png +0 -0
  27. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/32.png +0 -0
  28. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/33.png +0 -0
  29. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/34.png +0 -0
  30. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/35.png +0 -0
  31. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/37.png +0 -0
  32. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/38.png +0 -0
  33. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/39.png +0 -0
  34. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/40.png +0 -0
  35. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/41.png +0 -0
  36. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/45.png +0 -0
  37. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/46.png +0 -0
  38. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/47.png +0 -0
  39. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/5.png +0 -0
  40. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/51.png +0 -0
  41. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/52.png +0 -0
  42. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/53.png +0 -0
  43. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/54.png +0 -0
  44. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/56.png +0 -0
  45. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/57.png +0 -0
  46. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/58.png +0 -0
  47. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/59.png +0 -0
  48. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/6.png +0 -0
  49. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/60.png +0 -0
  50. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/61.png +0 -0
  51. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/62.png +0 -0
  52. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/7.png +0 -0
  53. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/70.png +0 -0
  54. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/71.png +0 -0
  55. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/72.png +0 -0
  56. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/75.png +0 -0
  57. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/8.png +0 -0
  58. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/83.png +0 -0
  59. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/84.png +0 -0
  60. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/9.png +0 -0
  61. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/DebugIcon.png +0 -0
  62. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconCivicCenter.png +0 -0
  63. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconFortCursed.png +0 -0
  64. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconForwardBase1.png +0 -0
  65. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconScorchedTown.png +0 -0
  66. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconTownHall.png +0 -0
  67. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapIcons/MapIconVictory.png +0 -0
  68. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapAcrithiaHex.png +0 -0
  69. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapAllodsBightHex.png +0 -0
  70. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapAshFieldsHex.png +0 -0
  71. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapBasinSionnachHex.png +0 -0
  72. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapCallahansPassageHex.png +0 -0
  73. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapCallumsCapeHex.png +0 -0
  74. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapClahstraHex.png +0 -0
  75. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapClansheadValleyHex.png +0 -0
  76. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapDeadLandsHex.png +0 -0
  77. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapDrownedValeHex.png +0 -0
  78. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapEndlessShoreHex.png +0 -0
  79. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapFarranacCoastHex.png +0 -0
  80. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapFishermansRowHex.png +0 -0
  81. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapGodcroftsHex.png +0 -0
  82. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapGreatMarchHex.png +0 -0
  83. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapHeartlandsHex.png +0 -0
  84. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapHomeRegionC.png +0 -0
  85. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapHomeRegionW.png +0 -0
  86. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapHowlCountyHex.png +0 -0
  87. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapKalokaiHex.png +0 -0
  88. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapKingsCageHex.png +0 -0
  89. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapLinnMercyHex.png +0 -0
  90. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapLochMorHex.png +0 -0
  91. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapMarbanHollow.png +0 -0
  92. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapMooringCountyHex.png +0 -0
  93. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapMorgensCrossingHex.png +0 -0
  94. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapNevishLineHex.png +0 -0
  95. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapOarbreakerHex.png +0 -0
  96. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapOriginHex.png +0 -0
  97. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapReachingTrailHex.png +0 -0
  98. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapReaversPassHex.png +0 -0
  99. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapRedRiverHex.png +0 -0
  100. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapSableportHex.png +0 -0
  101. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapShackledChasmHex.png +0 -0
  102. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapSpeakingWoodsHex.png +0 -0
  103. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapStemaLandingHex.png +0 -0
  104. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapStlicanShelfHex.png +0 -0
  105. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapStonecradleHex.png +0 -0
  106. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapTempestIslandHex.png +0 -0
  107. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapTerminusHex.png +0 -0
  108. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapTheFingersHex.png +0 -0
  109. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapUmbralWildwoodHex.png +0 -0
  110. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapViperPitHex.png +0 -0
  111. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapWeatheredExpanseHex.png +0 -0
  112. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/Images/MapsHex/MapWestgateHex.png +0 -0
  113. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi/utils.py +0 -0
  114. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi.egg-info/SOURCES.txt +0 -0
  115. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi.egg-info/dependency_links.txt +0 -0
  116. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi.egg-info/requires.txt +0 -0
  117. {foxapi-1.6.6 → foxapi-1.7.0}/foxapi.egg-info/top_level.txt +0 -0
  118. {foxapi-1.6.6 → foxapi-1.7.0}/setup.cfg +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: foxapi
3
- Version: 1.6.6
3
+ Version: 1.7.0
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
7
7
  Author: ThePhoenix78
8
8
  Author-email: thephoenix788@gmail.com
9
9
  License: MIT
10
- Keywords: foxhole,foxapi,foxhole-game
10
+ Keywords: foxhole,foxapi,foxhole-game,foxhole-api
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Operating System :: OS Independent
@@ -0,0 +1,27 @@
1
+ from .foxapi import FoxAPI
2
+ from .utils import HexagonObject, FoxAPIError, HexagonError, EndpointError, APIResponse, Task
3
+
4
+ import requests, json
5
+
6
+
7
+ __title__ = 'FoxAPI'
8
+ __author__ = 'ThePhoenix78'
9
+ __license__ = 'MIT'
10
+ __copyright__ = 'Copyright 2024-2025 ThePhoenix78'
11
+ __url__ = 'https://github.com/ThePhoenix78/FoxAPI'
12
+ __newest__ = __version__ = '1.7.0'
13
+
14
+
15
+ try:
16
+ with requests.get("https://pypi.python.org/pypi/FoxAPI/json") as response:
17
+ __newest__ = json.loads(response.text)["info"]["version"]
18
+ except requests.RequestException:
19
+ pass
20
+
21
+ finally:
22
+ del json, requests
23
+
24
+ if __version__ < __newest__:
25
+ print(f"New version of {__title__} available: {__newest__} (Using {__version__})")
26
+ else:
27
+ print(f"version : {__version__}")
@@ -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]: str = data.headers.get("ETag", self.etag.get(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]: str = data.headers.get("ETag", self.etag.get(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]: str = data.headers.get("ETag", self.etag.get(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]: dict = data_json
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
- return None
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
- def calc_distance(self, p1: tuple, p2: tuple):
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 load_hexagon_map(self, hexagon: str):
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) -> Image:
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) -> Image:
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
- captured_towns: dict = {}
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
- for s in static['mapTextItems']:
362
- deltas: list = []
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 show_icons:
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
- war_c: int = war_report['colonialCasualties']
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
- captured_towns: dict = {}
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
- for s in static['mapTextItems']:
469
- deltas: list = []
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 show_icons:
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
- war_c: int = war_report['colonialCasualties']
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
- EVENT WRAPPER
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]: str = self._format_endpoint(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]: callable = func
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]: str = self._format_hexagon(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]: callable = func
729
+ self._to_call[hexa] = func
734
730
  self._hex_call.append(hexa)
735
731
 
736
732
  return func
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: foxapi
3
- Version: 1.6.6
3
+ Version: 1.7.0
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
7
7
  Author: ThePhoenix78
8
8
  Author-email: thephoenix788@gmail.com
9
9
  License: MIT
10
- Keywords: foxhole,foxapi,foxhole-game
10
+ Keywords: foxhole,foxapi,foxhole-game,foxhole-api
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: License :: OSI Approved :: MIT License
13
13
  Classifier: Operating System :: OS Independent
@@ -1,4 +1,5 @@
1
1
  from setuptools import setup, find_packages
2
+ import foxapi
2
3
 
3
4
 
4
5
  with open("README.md", "r") as stream:
@@ -6,8 +7,8 @@ with open("README.md", "r") as stream:
6
7
 
7
8
  setup(
8
9
  name='foxapi',
9
- version="1.6.6",
10
- url='https://github.com/ThePhoenix78/FoxAPI',
10
+ version=foxapi.__version__,
11
+ url=foxapi.__url__,
11
12
  download_url='https://github.com/ThePhoenix78/FoxAPI/tarball/master',
12
13
  license='MIT',
13
14
  author='ThePhoenix78',
@@ -18,7 +19,8 @@ setup(
18
19
  keywords=[
19
20
  'foxhole',
20
21
  'foxapi',
21
- 'foxhole-game'
22
+ 'foxhole-game',
23
+ 'foxhole-api'
22
24
  ],
23
25
  install_requires=[
24
26
  'requests',
@@ -1,2 +0,0 @@
1
- from .foxapi import FoxAPI
2
- from .utils import HexagonObject, FoxAPIError, HexagonError, EndpointError, APIResponse, Task
File without changes
File without changes
File without changes
File without changes