refactor: update fetch-scans.py
This commit is contained in:
parent
a40d664e09
commit
5e1fe5cb5a
@ -13,6 +13,7 @@ from common import *
|
|||||||
import io
|
import io
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import datetime
|
import datetime
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
data_dir = 'data'
|
data_dir = 'data'
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ class ScanDataFetcher(object):
|
|||||||
data = r.json()
|
data = r.json()
|
||||||
fetch_backlog = []
|
fetch_backlog = []
|
||||||
for item in data['items']:
|
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
|
continue
|
||||||
if item['id'] in local_scan_data:
|
if item['id'] in local_scan_data:
|
||||||
local_labels = local_scan_data[item['id']]['labels']
|
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_path = os.path.join(scan_dir, 'metadata.json')
|
||||||
metadata_str = json.dumps(scan, indent=2)
|
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')
|
frame_img_file = os.path.join(scan_dir, 'frame.jpg')
|
||||||
if not os.path.exists(frame_img_file):
|
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:
|
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')
|
std_img_file = os.path.join(scan_dir, 'std.jpg')
|
||||||
if not os.path.exists(std_img_file):
|
if not os.path.exists(std_img_file):
|
||||||
std_img = Image.open(io.BytesIO(get_qr_image_bytes(scan['code'])))
|
std_img = Image.open(io.BytesIO(get_qr_image_bytes(scan['code'])))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user