Fixed HTML escape.
Browse files
scrape.py
CHANGED
@@ -10,6 +10,7 @@ import aiofiles
|
|
10 |
import argparse
|
11 |
import concurrent
|
12 |
from PIL import Image
|
|
|
13 |
from bs4 import BeautifulSoup
|
14 |
|
15 |
MAX_TASKS = 50
|
@@ -80,15 +81,16 @@ async def process_link(image_url, image_ids_to_ignore, session, thread_pool):
|
|
80 |
rating = image_container["data-rating"]
|
81 |
tags.append("nsfw" if rating in {"explicit", "questionable"} else "sfw")
|
82 |
random.shuffle(tags)
|
|
|
|
|
|
|
83 |
async with session.get(original_link) as img_response:
|
84 |
img_data = await img_response.read()
|
85 |
-
image_path = os.path.join(IMAGE_DIR, image_id + image_ext)
|
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(
|
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
|
|
|
10 |
import argparse
|
11 |
import concurrent
|
12 |
from PIL import Image
|
13 |
+
import html as libhtml
|
14 |
from bs4 import BeautifulSoup
|
15 |
|
16 |
MAX_TASKS = 50
|
|
|
81 |
rating = image_container["data-rating"]
|
82 |
tags.append("nsfw" if rating in {"explicit", "questionable"} else "sfw")
|
83 |
random.shuffle(tags)
|
84 |
+
image_path = os.path.join(IMAGE_DIR, image_id + image_ext)
|
85 |
+
tags_path = os.path.join(IMAGE_DIR, image_id + ".txt")
|
86 |
+
tags_text = ", ".join(libhtml.unescape(tag).replace("_", " ") for tag in tags)
|
87 |
async with session.get(original_link) as img_response:
|
88 |
img_data = await img_response.read()
|
|
|
89 |
os.makedirs(IMAGE_DIR, exist_ok=True)
|
90 |
async with aiofiles.open(image_path, "wb") as f:
|
91 |
await f.write(img_data)
|
|
|
92 |
async with aiofiles.open(tags_path, "w", encoding="utf8") as f:
|
93 |
+
await f.write(tags_text)
|
94 |
future = thread_pool.submit(validate_image, image_path, tags_path)
|
95 |
future.add_done_callback(lambda x: handle_validation_result(x, image_path, tags_path))
|
96 |
return
|