Skip to content

Commit

Permalink
POSIX earned datetime and retroachievment id resolving fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dimone-kun committed Sep 9, 2020
1 parent bf7939d commit 6ebf159
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions plugins/nes_e2c630e1-3cbe-4dbd-9235-5e6a2d2955ad/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ def tick(self):

async def get_unlocked_achievements(self, game_id: str, context: Any) -> List[Achievement]:
if self.ra_client:
ra_id = await self._get_retroachievement_game_id(game_id)
logging.debug('Got retroachievements id %s', ra_id)
rom_hash = self._rom_hash(game_id)
ra_id = await self.ra_client.get_id_by_hash(rom_hash)

if ra_id:
return await self.ra_client.get_earned_achievements(ra_id)
logging.debug('Got retroachievements id %s', ra_id)
if ra_id:
return await self.ra_client.get_earned_achievements(ra_id)

return []

async def _get_retroachievement_game_id(self, game_id: str):
def _rom_hash(self, game_id: str):
if os.path.isfile(self.playlist_path):
with open(self.playlist_path) as playlist_json:
playlist_dict = json.load(playlist_json)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import asyncio
import logging
from datetime import datetime, timezone

from typing import List
from galaxy.http import handle_exception, create_client_session
from galaxy.api.types import Achievement

RA_DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'

class RetroachievementsClient:
def __init__(self, user, api_key):
self._session = create_client_session()
Expand All @@ -22,7 +25,7 @@ def achievement_parser(cheevo) -> Achievement:
return Achievement(
cheevo['ID'],
cheevo['Title'],
cheevo['DateEarned']
int(datetime.strptime(cheevo['DateEarned'], RA_DATETIME_FORMAT).replace(tzinfo=timezone.utc).timestamp())
)

def achievements_parser(response) -> List[Achievement]:
Expand Down

0 comments on commit 6ebf159

Please sign in to comment.