Pecximenes's picture
Removing diretory and organazing files
94e320d
raw
history blame
1.3 kB
import re
from oac.oac import get_description_of_image
def generate_image_description_with_empty_description(oa_client, websites):
# Expressão regular para encontrar o padrão ![](<link>)
pattern = r'!\[\]\(([^)]+)\)'
def replace_description_image(match):
link = match.group(1)
new_description = get_description_of_image(oa_client, link)
return f'![{new_description}]({link})'
texts_with_images_descriptions = []
error_images_upload = []
for website in websites:
try:
text_with_image_description = re.sub(
pattern,
replace_description_image,
website["text_content"]
)
texts_with_images_descriptions.append({
"id": website["text_id"],
"content": text_with_image_description,
"url": website["url"]
})
except Exception:
error_images_upload.append(
f"{website['text_id']}: {website['text_content']}")
texts_with_images_descriptions.append({
"id": website["text_id"],
"content": website["text_content"],
"url": website["url"]
})
return texts_with_images_descriptions, error_images_upload