From 5e1fe5cb5a8c93ec49487a20ebc1228588fa1524 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Sat, 27 Dec 2025 10:33:49 +0000 Subject: [PATCH] refactor: update fetch-scans.py --- emblem5/ai/fetch-scans.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/emblem5/ai/fetch-scans.py b/emblem5/ai/fetch-scans.py index a72f620..92ee9f2 100755 --- a/emblem5/ai/fetch-scans.py +++ b/emblem5/ai/fetch-scans.py @@ -13,6 +13,7 @@ from common import * import io from tqdm import tqdm import datetime +from urllib.parse import quote data_dir = 'data' @@ -51,7 +52,7 @@ class ScanDataFetcher(object): data = r.json() fetch_backlog = [] for item in data['items']: - if 'code' not in item or 'id' not in item or not item.get('labels') or 'image' not in item: + if 'code' not in item or 'id' not in item or not item.get('labels') or 'image' not in item or not item.get('image'): continue if item['id'] in local_scan_data: local_labels = local_scan_data[item['id']]['labels'] @@ -97,12 +98,13 @@ class ScanDataFetcher(object): metadata_path = os.path.join(scan_dir, 'metadata.json') metadata_str = json.dumps(scan, indent=2) - frame_img_url = f'https://themblem.com/api/v1/oss-image/?token={self.token}&name={scan["image"]}' + frame_img_url = f'https://themblem.com/api/v1/oss-image/?token={self.token}&name={quote(scan["image"])}' frame_img_file = os.path.join(scan_dir, 'frame.jpg') if not os.path.exists(frame_img_file): - frame_img_bytes = requests.get(frame_img_url).content + r = requests.get(frame_img_url) + r.raise_for_status() # Raise an exception for bad status codes with open(frame_img_file, 'wb') as f: - f.write(frame_img_bytes) + f.write(r.content) std_img_file = os.path.join(scan_dir, 'std.jpg') if not os.path.exists(std_img_file): std_img = Image.open(io.BytesIO(get_qr_image_bytes(scan['code'])))