import urllib.parse import xml.etree.ElementTree as ET import oracledb from datetime import datetime import sys import json def wrap_in_editorjs(html_content): editor_json = { "time": int(datetime.now().timestamp() * 1000), "blocks": [ { "type": "raw", "data": { "html": html_content } } ], "version": "2.22.2" } return json.dumps(editor_json) def main(xml_file_path): print(f"Reading {xml_file_path} ...") tree = ET.parse(xml_file_path) root = tree.getroot() ns = { 'wp': 'http://wordpress.org/export/1.2/', 'content': 'http://purl.org/rss/1.0/modules/content/', 'dc': 'http://purl.org/dc/elements/1.1/' } dsn = "localhost:1521/sisvietnam" conn = oracledb.connect(user="sisvietnam", password="sisvietnam", dsn=dsn) cursor = conn.cursor() dt = datetime.now() layout = "SPECIALTY_DETAIL" page_type = "CUSTOM" status = "PUBLISHED" count = 0 warnings = [] for channel in root.findall('channel'): for item in channel.findall('item'): title_tag = item.find('title') title = title_tag.text if title_tag is not None else "Untitled" post_name_tag = item.find('wp:post_name', ns) if post_name_tag is not None and post_name_tag.text: slug = post_name_tag.text else: link_tag = item.find('link') slug = link_tag.text.strip('/').split('/')[-1] if link_tag is not None else "unknown" slug = urllib.parse.unquote(slug) if slug == "khoa-than-kinh-dot-quy-2": slug = "khoa-than-kinh-dot-quy" # No longer skipping khoa-cap-cuu content_tag = item.find('content:encoded', ns) content_text = content_tag.text if content_tag is not None and content_tag.text else "" # Check if missing container if '