Parsing html & core_attachment_upload usage
# upload inline image attachments
for img in html.xpath("//img"):
try:
src = img.get("src")
# if src is None:
# src = img.get("data-src")
try:
local_file = util.download_file("downloads/inline_attachments/", src)
att = zd.api.core_attachment_upload(relation_data={"external_id": util.hash_crc32(src)},
file_path=local_file, inline=True)
img.set("src", att["upload"]["attachment"]["content_url"])
data.inline_tokens.append(att["upload"]["token"])
except Exception as e:
relation_data.update({"entry_type": "ticket"})
ret = zd.api.migration_map.log_error({"internal_error": str(e) + "; ticket still migrated."},
relation_data)
pass
except Exception as e:
note = "Could not set attachment %s for article %s" % (str(img), data.id)
log.critical(note)
relation_data = {"entry_type": "inline_attachment", "external_id": data.id}
ret = zd.api.migration_map.log_error({"internal_error": str(e), "note": note}, relation_data)
pass