v2ray commited on
Commit
a9c180f
·
1 Parent(s): 20ea893

Fixed some typo.

Browse files
Files changed (1) hide show
  1. scrape.py +8 -8
scrape.py CHANGED
@@ -30,7 +30,7 @@ def sigint_handler(signum, frame):
30
  print("Script force quit by user, exiting...")
31
  sys.exit(1)
32
 
33
- def validate_image(image_path, tag_path):
34
  try:
35
  with Image.open(image_path) as img:
36
  img.verify()
@@ -39,7 +39,7 @@ def validate_image(image_path, tag_path):
39
  print(f"Error validating image {image_path}: {e}")
40
  return False
41
 
42
- def handle_validation_result(future, image_path, tag_path):
43
  if future.result():
44
  return
45
  try:
@@ -47,8 +47,8 @@ def handle_validation_result(future, image_path, tag_path):
47
  except Exception as e:
48
  print(f"Error deleting image file: {e}")
49
  try:
50
- os.remove(tag_path)
51
- print(f"Deleted invalid image and tag files: {image_path}, {tag_path}")
52
  except Exception as e:
53
  print(f"Error deleting tags file: {e}")
54
 
@@ -86,11 +86,11 @@ async def process_link(image_url, image_ids_to_ignore, session, thread_pool):
86
  os.makedirs(IMAGE_DIR, exist_ok=True)
87
  async with aiofiles.open(image_path, "wb") as f:
88
  await f.write(img_data)
89
- tag_path = os.path.join(IMAGE_DIR, image_id + ".txt")
90
- async with aiofiles.open(tag_path, "w", encoding="utf8") as f:
91
  await f.write(", ".join(tag.replace("_", " ") for tag in tags))
92
- future = thread_pool.submit(validate_image, image_path, tag_path)
93
- future.add_done_callback(lambda x: handle_validation_result(x, image_path, tag_path))
94
  return
95
  except Exception as e:
96
  if i > MAX_RETRY:
 
30
  print("Script force quit by user, exiting...")
31
  sys.exit(1)
32
 
33
+ def validate_image(image_path, tags_path):
34
  try:
35
  with Image.open(image_path) as img:
36
  img.verify()
 
39
  print(f"Error validating image {image_path}: {e}")
40
  return False
41
 
42
+ def handle_validation_result(future, image_path, tags_path):
43
  if future.result():
44
  return
45
  try:
 
47
  except Exception as e:
48
  print(f"Error deleting image file: {e}")
49
  try:
50
+ os.remove(tags_path)
51
+ print(f"Deleted invalid image and tags files: {image_path}, {tags_path}")
52
  except Exception as e:
53
  print(f"Error deleting tags file: {e}")
54
 
 
86
  os.makedirs(IMAGE_DIR, exist_ok=True)
87
  async with aiofiles.open(image_path, "wb") as f:
88
  await f.write(img_data)
89
+ tags_path = os.path.join(IMAGE_DIR, image_id + ".txt")
90
+ async with aiofiles.open(tags_path, "w", encoding="utf8") as f:
91
  await f.write(", ".join(tag.replace("_", " ") for tag in tags))
92
+ future = thread_pool.submit(validate_image, image_path, tags_path)
93
+ future.add_done_callback(lambda x: handle_validation_result(x, image_path, tags_path))
94
  return
95
  except Exception as e:
96
  if i > MAX_RETRY: