Skip to content

Commit

Permalink
Update proxycache.py
Browse files Browse the repository at this point in the history
  • Loading branch information
moraroy authored Dec 10, 2024
1 parent ad248dd commit 8ba5bb7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion proxycache/proxycache.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,22 @@ def handle_artwork(self, game_id, art_type, dimensions):
logger.info(f"Sending request to: {url}")
response = limited_request(url, headers)
data = response.json()
api_cache[cache_key] = {'data': data, 'timestamp': datetime.now()}

# Check for image quality, dimension, or alternate style information and store all metadata
artwork_data = {
'images': [{
'url': image['url'],
'width': image.get('width'),
'height': image.get('height'),
'style': image.get('style', 'default'),
} for image in data.get('data', [])],
'other_metadata': {
'image_quality': data.get('quality', 'high'),
'last_updated': data.get('last_updated', str(datetime.now())),
}
}

api_cache[cache_key] = {'data': artwork_data, 'timestamp': datetime.now()}
logger.info(f"Storing in cache: {cache_key}")
except Exception as e:
logger.error(f"Error making API call: {e}")
Expand All @@ -190,8 +205,16 @@ def handle_artwork(self, game_id, art_type, dimensions):
self.send_response(500)
self.end_headers()
self.wfile.write(b'Invalid response from API')
logger.error(f"Artwork for Game ID {game_id} ({art_type}) with dimensions {dimensions} not found. Error: No 'data' in response.")
return

# Log why artwork wasn't found (if any)
if not data.get('data', []):
logger.error(f"Artwork for Game ID {game_id} ({art_type}) with dimensions {dimensions} not found. Error: No artwork data.")
self.send_response(404)
self.end_headers()
self.wfile.write(b'Artwork not found')

self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(data).encode())
Expand Down

0 comments on commit 8ba5bb7

Please sign in to comment.