Skip to content

Commit

Permalink
🎨 Deleting unused debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
lleans committed Feb 9, 2024
1 parent df01397 commit 7cbfa3b
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions LyricsFindScrapper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def _errors(self):
403: "Forbidden,or unvalid",
429: "Too many request",
500: "Server error",
100: "No response from API. Also, request was could not found"
}

return http_error.get(self.http_code, f"Unknown error, please report to the project maintainer. HTTP code {self.http_code}")
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(self, session=None, *, lib='asyncio', loop=None, teritory: str = No
}
self.session = session or ClientSession(loop=loop, headers=headers)

def ensure_teritory(func):
def __ensure_teritory(func):
async def decor(self, *args, **kwargs):
if not self.teritory:
ip: str = await get_current_ip(session=self.session)
Expand All @@ -57,7 +58,7 @@ async def decor(self, *args, **kwargs):
return await func(self, *args, **kwargs)
return decor

@ensure_teritory
@__ensure_teritory
async def get_tracks(self, query: str) -> list[Track]:
'''
Get List of all tracks from database, based by keyword
Expand All @@ -72,11 +73,11 @@ async def get_tracks(self, query: str) -> list[Track]:
if data['tracks']:
return [Track(x) for x in data['tracks']]
else:
raise LFException(http_code=resp.status)
raise LFException("Your query was not found", was_generic=True)
else:
raise LFException(http_code=resp.status)

@ensure_teritory
@__ensure_teritory
async def get_track(self, trackid: str):
'''
Get a track from database, specifically by using metadata/trackid.
Expand All @@ -96,11 +97,11 @@ async def get_track(self, trackid: str):
if data['track']:
return Track(data['track'])
else:
raise LFException(http_code=resp.status)
raise LFException(http_code=resp['respons']['code'])
else:
raise LFException(http_code=resp.status)

@ensure_teritory
@__ensure_teritory
async def get_lyrics(self, lfid: str) -> SongData:
'''
Get lyric from database, by given track
Expand All @@ -111,13 +112,15 @@ async def get_lyrics(self, lfid: str) -> SongData:
async with self.session.get(url=url, params=params) as resp:
if resp.status < 400:
data: dict = await resp.json()
print(data)

return SongData(data=data['track'])
if data['track']:
return SongData(data=data['track'])
else:
raise LFException(http_code=resp['respons']['code'])
else:
raise LFException(http_code=resp.status)

@ensure_teritory
@__ensure_teritory
async def get_translation(self, track: Track, lang: str) -> Translation:
'''
Get translated lyric from database, by given track and language.
Expand All @@ -137,6 +140,9 @@ async def get_translation(self, track: Track, lang: str) -> Translation:
async with self.session.get(url=url, params=params) as resp:
if resp.status < 400:
data: dict = await resp.json()
return Translation(data=data['track'])
if data['track']:
return Translation(data=data['track'])
else:
raise LFException(http_code=resp['respons']['code'])
else:
raise LFException(http_code=resp.status)

0 comments on commit 7cbfa3b

Please sign in to comment.