Skip to content

Commit

Permalink
Merge pull request #2 from Phalcode/tyler-dev
Browse files Browse the repository at this point in the history
Error check the BG URL and return something good.
  • Loading branch information
Toylerrr authored May 22, 2024
2 parents 9d0495f + 2319dbd commit 85f4728
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,36 @@ def get_game_tags(app_id):
logger.error("Failed to retrieve tags.")
return None

def test_url(url):
try:
response = requests.get(url, timeout=5)
return response.status_code == 200
except requests.RequestException:
return False

def fix_bg_url(game_data):
bg_option1 = game_data["background_raw"]
bg_option2 = game_data["background"]
bg_option3 = game_data["screenshots"][0]["path_full"]

if test_url(bg_option1):
return bg_option1
elif test_url(bg_option2):
return bg_option2
elif test_url(bg_option3):
return bg_option3
else:
return None



def map_game(game_data, app_id):
def map_game(game_data, app_id):
new_background_image = fix_bg_url(game_data)
return {
"id": game_data["steam_appid"],
"name": clean_string(game_data["name"]),
"slug": clean_string(game_data["name"]).lower().replace(" ", "-"),
"background_image": game_data.get("background_raw") or (game_data.get("screenshots", []) and game_data["screenshots"][0].get("path_full")) or game_data.get("header_image") or None,
"background_image": new_background_image,
"box_image": f"https://steamcdn-a.akamaihd.net/steam/apps/{app_id}/library_600x900_2x.jpg",
"description_raw": clean_string(game_data.get("detailed_description", "")),
"metacritic": game_data.get("metacritic", {}).get("score", None),
Expand Down

0 comments on commit 85f4728

Please sign in to comment.