Skip to content

Commit

Permalink
bf/fix data model
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Sep 1, 2024
1 parent d02e164 commit a003c7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion api/cogs/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ async def get_hiscore_data(label_id: int, limit: int = 5000):
# Continue making requests until all data is retrieved
while True:
data = await retry_request(url=url, params=params)

for d in data:
scraper_data = ScraperDataV3(**d)
skills = {r.skill_name: r.skill_value for r in scraper_data.skills}
Expand All @@ -123,7 +124,10 @@ async def get_hiscore_data(label_id: int, limit: int = 5000):
}
hiscores.append(
HighscoreData(
**skills, **activities, Player_id=scraper_data.player_id
**skills,
**activities,
Player_id=scraper_data.player_id,
name=scraper_data.player_name,
).model_dump()
)

Expand All @@ -144,6 +148,21 @@ async def get_prediction_data(player_id: int = 0, limit: int = 0):
params = {"player_id": player_id, "many": 1, "limit": limit}

data = await retry_request(url=url, params=params)
hiscores = []
for d in data:
scraper_data = ScraperDataV3(**d)
skills = {r.skill_name: r.skill_value for r in scraper_data.skills}
activities = {
r.activity_name: r.activity_value for r in scraper_data.activities
}
hiscores.append(
HighscoreData(
**skills,
**activities,
Player_id=scraper_data.player_id,
name=scraper_data.player_name,
).model_dump()
)
return data


Expand Down
2 changes: 2 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ class ScraperDataV3(BaseModel):
record_date: date
scraper_id: int
player_id: int
player_name: str
skills: list[Skill]
activities: list[Activity]


class HighscoreData(BaseModel):
Player_id: int
name: str
attack: Optional[int] = 0
defence: Optional[int] = 0
strength: Optional[int] = 0
Expand Down

0 comments on commit a003c7d

Please sign in to comment.