45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import oracledb
|
|
import json
|
|
|
|
def convert_all():
|
|
conn = oracledb.connect(user="sisvietnam", password="sisvietnam", dsn="localhost:1521/sisvietnam")
|
|
cursor = conn.cursor()
|
|
cursor.execute("SELECT slug, content FROM sis_page WHERE page_type = 'CUSTOM'")
|
|
rows = cursor.fetchall()
|
|
|
|
count = 0
|
|
for row in rows:
|
|
slug = row[0]
|
|
content = row[1].read() if hasattr(row[1], 'read') else row[1]
|
|
|
|
if not content:
|
|
continue
|
|
|
|
try:
|
|
json.loads(content)
|
|
# Already JSON
|
|
continue
|
|
except ValueError:
|
|
# Not JSON, convert to Editor.js Raw block
|
|
editor_json = {
|
|
"time": 1620000000,
|
|
"blocks": [
|
|
{
|
|
"type": "raw",
|
|
"data": {
|
|
"html": content
|
|
}
|
|
}
|
|
],
|
|
"version": "2.22.2"
|
|
}
|
|
new_content = json.dumps(editor_json)
|
|
cursor.execute("UPDATE sis_page SET content = :1 WHERE slug = :2", [new_content, slug])
|
|
count += 1
|
|
|
|
conn.commit()
|
|
print(f"Converted {count} pages to Editor.js JSON.")
|
|
|
|
if __name__ == "__main__":
|
|
convert_all()
|