Skip to content

Commit

Permalink
Few fixes to achievement viewer
Browse files Browse the repository at this point in the history
Use utf-8-sig encoding for JSON file loading
Enhance achievement text retrieval logic
  • Loading branch information
50t0r25 committed Jan 10, 2025
1 parent b65d719 commit 9554e8c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion achievement_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ def convert_from_unixtime(unix_time):

# Function to load JSON data from a file
def load_json(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, 'r', encoding='utf-8-sig') as f:
return json.load(f)

# Function to get the achievement text in the preferred language, with a fallback to English
def get_achievement_text(recent_achievement, key):
# Check if the key is a string, return it directly
if isinstance(recent_achievement.get(key), str):
return recent_achievement[key]
# Otherwise, attempt to get the text for the preferred language or fallback
return recent_achievement.get(key, {}).get(preferred_language) or \
recent_achievement.get(key, {}).get('english', 'Unknown')

Expand Down

0 comments on commit 9554e8c

Please sign in to comment.