feat: implement specialty content module with expanded Page entity fields, database migrations, and data import utilities
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user