#!/usr/bin/env python3 import sys from pathlib import Path PROJECT_ROOT = Path(__file__).parent.parent sys.path.insert(0, str(PROJECT_ROOT)) try: from db_helper import update_topic_status from app.database import SessionLocal from app.models import Topic as DBTopic HAVE_DB = True except ImportError: HAVE_DB = False DATA_DIR = PROJECT_ROOT / "automation" / "data" TOPICS_FILE = DATA_DIR / "sustainability_topics.json" def adjust(adjustments): db_ok = False if HAVE_DB: db = SessionLocal() try: for tid, new_score in adjustments.items(): topic = db.query(DBTopic).filter(DBTopic.id == tid).first() if topic: topic.priority_score = new_score topic.updated_at = datetime.datetime.now() db.commit() db_ok = True finally: db.close() try: with open(TOPICS_FILE, 'r', encoding='utf-8') as f: topics = json.load(f) for t in topics: if t['id'] in adjustments: t['priority_score'] = adjustments[t['id']] with open(TOPICS_FILE, 'w', encoding='utf-8') as f: json.dump(topics, f, ensure_ascii=False, indent=2) except: pass return db_ok def main(): adjustments = {'D01': 12} adjust(adjustments) print("D01 priority_score set to 12") if __name__ == "__main__": import json, datetime main()