Skip to content

Commit 97769d0

Browse files
Get Raw All for Community Api.
1 parent 58efe81 commit 97769d0

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
keywords=['helldivers2','api']
2323
requires-python = ">=3.8.1"
2424

25-
version = '0.0.1.19.18'
25+
version = '0.0.1.19.19'
2626
dependencies= [
2727
"pydantic>=2.9.2",
2828
"httpx>=0.27.2"

src/hd2api/services/async_comm_service.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import logging
22
from typing import List, Optional, Type, TypeVar, Union
33

4-
from ..api_config import APIConfig
4+
from hd2api.models import DiveharderAll
5+
6+
from ..api_config import APIConfig, HTTPException
57
from ..models import (
68
Assignment,
79
Assignment2,
@@ -40,9 +42,7 @@ async def make_comm_v1_api_request(
4042
path += f"/{index}"
4143

4244
if api_config.client_contact is None:
43-
raise ValueError(
44-
"Attempted to call community api without setting client_contact"
45-
)
45+
raise ValueError("Attempted to call community api without setting client_contact")
4646

4747
data = await make_async_api_request(base_path, path, api_config)
4848

@@ -54,6 +54,7 @@ async def make_comm_raw_api_request(
5454
model: Type[T],
5555
index: Optional[int] = None,
5656
api_config_override: Optional[APIConfig] = None,
57+
params: Optional[dict] = None, # Added parameters for GET requests
5758
) -> Union[T, List[T]]:
5859
"""
5960
Get a raw api object from the Community api.
@@ -65,11 +66,9 @@ async def make_comm_raw_api_request(
6566
if index is not None:
6667
path += f"/{index}"
6768
if api_config.client_contact is None:
68-
raise ValueError(
69-
"Attempted to call community api without setting client_contact"
70-
)
69+
raise ValueError("Attempted to call community api without setting client_contact")
7170

72-
data = await make_async_api_request(base_path, path, api_config)
71+
data = await make_async_api_request(base_path, path, api_config, params)
7372
return make_output(data, model, index)
7473

7574

@@ -109,8 +108,15 @@ async def GetCommApiRawAssignment(
109108

110109

111110
async def GetCommApiRawNewsFeed(
112-
api_config_override: Optional[APIConfig] = None,
111+
api_config_override: Optional[APIConfig] = None, fromTimestamp=None
113112
) -> List[NewsFeedItem]:
113+
if fromTimestamp:
114+
return await make_comm_raw_api_request(
115+
"NewsFeed/801",
116+
NewsFeedItem,
117+
api_config_override=api_config_override,
118+
params={"maxEntries": 1024, "fromTimestamp": fromTimestamp},
119+
)
114120
return await make_comm_raw_api_request(
115121
"NewsFeed/801", NewsFeedItem, api_config_override=api_config_override
116122
)
@@ -135,9 +141,7 @@ async def GetCommApiRawSpaceStation(
135141

136142

137143
async def GetApiV1War(api_config_override: Optional[APIConfig] = None) -> War:
138-
return await make_comm_v1_api_request(
139-
"war", War, api_config_override=api_config_override
140-
)
144+
return await make_comm_v1_api_request("war", War, api_config_override=api_config_override)
141145

142146

143147
async def GetApiV1AssignmentsAll(
@@ -196,9 +200,7 @@ async def GetApiV1PlanetsAll(
196200
)
197201

198202

199-
async def GetApiV1Planets(
200-
index: int, api_config_override: Optional[APIConfig] = None
201-
) -> Planet:
203+
async def GetApiV1Planets(index: int, api_config_override: Optional[APIConfig] = None) -> Planet:
202204
return await make_comm_v1_api_request(
203205
"planets", Planet, index, api_config_override=api_config_override
204206
)
@@ -226,3 +228,30 @@ async def GetApiV1Steam2(
226228
return await make_comm_v1_api_request(
227229
"steam", SteamNews, gid, api_config_override=api_config_override
228230
)
231+
232+
233+
# Get all
234+
235+
236+
async def GetCommApiRawAll(
237+
api_config_override: Optional[APIConfig] = None,
238+
) -> DiveharderAll:
239+
warstatus = await GetCommApiRawWarStatus(api_config_override)
240+
warinfo = await GetCommApiRawWarInfo(api_config_override)
241+
summary = await GetCommApiRawSummary(api_config_override)
242+
assign = await GetCommApiRawAssignment(api_config_override)
243+
try:
244+
news = await GetCommApiRawNewsFeed(
245+
api_config_override, fromTimestamp=warstatus.time - 10000000
246+
)
247+
except HTTPException as e:
248+
hd2api_logger.error("Error raised when calling news feed: %s", e)
249+
news = None
250+
newdive = DiveharderAll(
251+
status=warstatus,
252+
war_info=warinfo,
253+
planet_stats=summary,
254+
major_order=assign,
255+
news_feed=news,
256+
)
257+
return newdive

src/hd2api/services/async_raw_service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
)
1313
from ..models.ABC.model import BaseApiModel
1414
from .async_comm_service import (
15+
GetCommApiRawAll,
1516
GetCommApiRawAssignment,
1617
GetCommApiRawNewsFeed,
1718
GetCommApiRawSpaceStation,
@@ -108,7 +109,9 @@ async def GetApiRawSpaceStation(
108109

109110
async def GetApiRawAll(api_config_override: APIConfig, direct=False) -> DiveharderAll:
110111
"""Retrieve all raw data from the api, optionally using the direct method."""
111-
if direct:
112-
return await GetApiDirectAll(api_config_override)
113-
else:
112+
if api_config_override.use_raw == "community":
113+
return await GetCommApiRawAll(api_config_override)
114+
elif api_config_override.use_raw == "diveharder":
114115
return await GetDhApiRawAll(api_config_override)
116+
elif api_config_override.use_raw == "direct":
117+
return await GetApiDirectAll(api_config_override)

0 commit comments

Comments
 (0)