Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LuCkEr- committed Feb 4, 2022
1 parent e3dd5a4 commit 444741a
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 49 deletions.
17 changes: 7 additions & 10 deletions src/pyscoresaber/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
from asyncio import AbstractEventLoop
from datetime import datetime
from enum import Enum
from pprint import pprint
from typing import Optional, List
from typing import Optional

import aiohttp
from aiohttp import ClientResponse, ClientResponseError

from .models.player import Player
from .errors import ScoreSaberException, NotFoundException, ServerException


Expand Down Expand Up @@ -51,11 +49,12 @@ async def _request(self, *args, **kwargs) -> ClientResponse:
except ClientResponseError as error:
if error.status == 404:
raise NotFoundException(error.status, str(error.request_info.real_url)) from error
elif error.status == 500:

if error.status == 500:
raise ServerException(error.status, str(error.request_info.real_url)) from error
else:
if retries > self.RETRIES:
raise ScoreSaberException(error.status, str(error.request_info.real_url)) from error

if retries > self.RETRIES:
raise ScoreSaberException(error.status, str(error.request_info.real_url)) from error

sleep = 2 ** retries

Expand Down Expand Up @@ -96,7 +95,5 @@ async def get(self, type_, url, params={}, *args, **kwargs):
return data

return type_.from_dict(data)
else:
return typing.get_args(type_)[0].schema().load(data, many=True)


return typing.get_args(type_)[0].schema().load(data, many=True)
1 change: 1 addition & 0 deletions src/pyscoresaber/models/badge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
@dataclass_json
@dataclass
class Badge:
"""Badge info from Score Saber"""
description: str = default()
image: str = default()
2 changes: 1 addition & 1 deletion src/pyscoresaber/models/fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dateutil import parser
from dataclasses import field, Field
from datetime import datetime
from typing import Optional

from dataclasses_json import config
from dateutil import parser
from marshmallow import fields

from .enum import GameMode, BeatmapDifficulty
Expand Down
1 change: 0 additions & 1 deletion src/pyscoresaber/models/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ class Score:
hmd: int = default()
has_replay: bool = default("hasReplay")
time_set: datetime = datetime_field("timeSet")

1 change: 0 additions & 1 deletion src/pyscoresaber/models/score_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
class ScoreCollection:
scores: List[Score]
metadata: Metadata

13 changes: 6 additions & 7 deletions src/pyscoresaber/scoresaber.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ async def leaderboard_info_by_id(self,

@CacheAsync(hours=1)
async def leaderboard_info_by_hash(self,
hash: str,
beatmap_hash: str,
difficulty: BeatmapDifficulty,
game_mode: Optional[GameMode] = None
) -> LeaderboardInfo:
if self.test_mode:
raise RuntimeError("Not implemented!")

url = f"{self._url}/leaderboard/by-hash/{hash}/info"
url = f"{self._url}/leaderboard/by-hash/{beatmap_hash}/info"
params = {
"difficulty": difficulty, "gameMode": game_mode
}
Expand All @@ -110,7 +110,7 @@ async def leaderboard_scores_by_id(self,

@CacheAsync(hours=1)
async def leaderboard_scores_by_hash(self,
hash: str,
beatmap_hash: str,
difficulty: BeatmapDifficulty,
countries: Optional[str] = None,
search: Optional[str] = None,
Expand All @@ -120,7 +120,7 @@ async def leaderboard_scores_by_hash(self,
if self.test_mode:
raise RuntimeError("Not implemented!")

url = f"{self._url}/leaderboard/by-hash/{hash}/scores"
url = f"{self._url}/leaderboard/by-hash/{beatmap_hash}/scores"
params = {
"difficulty": difficulty, "countries": countries, "search": search,
"page": page, "gameMode": game_mode
Expand All @@ -130,12 +130,12 @@ async def leaderboard_scores_by_hash(self,

@CacheAsync(hours=1)
async def leaderboard_difficulties(self,
hash: str
beatmap_hash: str
) -> List[Difficulty]:
if self.test_mode:
raise RuntimeError("Not implemented!")

return await self._http_client.get(List[Difficulty], f"{self._url}/leaderboard/get-difficulties/{hash}")
return await self._http_client.get(List[Difficulty], f"{self._url}/leaderboard/get-difficulties/{beatmap_hash}")

# /player

Expand Down Expand Up @@ -228,4 +228,3 @@ async def player_scores(self,
# TODO: Implement POST /ranking/request/action/nat/replace
# TODO: Implement POST /ranking/request/action/nat/qualify
# TODO: Implement POST /ranking/request/action/nat/deny

1 change: 0 additions & 1 deletion src/pyscoresaber/scoresaber_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,3 @@ def scores(self, count: int = 1) -> List[Score]:
scores.append(self.score())

return scores

23 changes: 0 additions & 23 deletions src/pyscoresaber/utils.py

This file was deleted.

9 changes: 4 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ def event_loop():

@pytest.fixture(scope="session")
async def scoresaber(event_loop):
scoresaber = ScoreSaberAPI(loop=event_loop)
await scoresaber.start()
scoresaber_api = ScoreSaberAPI(loop=event_loop)
await scoresaber_api.start()

yield scoresaber

await scoresaber.close()
yield scoresaber_api

await scoresaber_api.close()

0 comments on commit 444741a

Please sign in to comment.