News: normalize category select values; fix Studio news editor category persistence; add CSV→SQL generator and news_dates.sql

This commit is contained in:
2026-05-03 09:12:38 +02:00
parent a9dfa6ea11
commit 44354e5bea
4 changed files with 1860 additions and 170 deletions

30
scripts/csv_to_sql.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import csv
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
CSV_PATH = ROOT / 'news_dates.csv'
OUT_PATH = ROOT / 'news_dates.sql'
def main():
with CSV_PATH.open(newline='', encoding='utf-8') as f:
reader = csv.DictReader(f)
rows = list(reader)
with OUT_PATH.open('w', encoding='utf-8', newline='\n') as out:
out.write('-- Generated from news_dates.csv\n')
out.write('-- Sets published_at, created_at, updated_at to CSV date\n')
out.write('BEGIN;\n')
for row in rows:
news_id = (row.get('news_id') or '').strip().strip('"')
date = (row.get('update_date') or '').strip().strip('"')
if not news_id or not date:
continue
date = date.replace("'", "''")
out.write(
f"UPDATE news_articles SET published_at = '{date}', created_at = '{date}', updated_at = '{date}' WHERE news_id = {news_id};\n"
)
out.write('COMMIT;\n')
if __name__ == '__main__':
main()