from nc_py_api import Nextcloud import json from datetime import datetime import config # Initialize Nextcloud client nc = Nextcloud( nextcloud_url=config.NEXTCLOUD_URL, nc_auth_user=config.NEXTCLOUD_USERNAME, nc_auth_pass=config.NEXTCLOUD_PASSWORD ) NEXTCLOUD_NOTES_PATH = "/gpu_poor_release_notes.json" LOCAL_CACHE_FILE = "release_notes.json" def load_release_notes(): """Load release notes from Nextcloud with local file fallback.""" try: # Try to load from Nextcloud remote_data = nc.files.download(NEXTCLOUD_NOTES_PATH) if remote_data: notes = json.loads(remote_data.decode('utf-8')) # Update local cache with open(LOCAL_CACHE_FILE, 'w') as f: json.dump(notes, f, indent=2) return notes except Exception as e: print(f"Could not load release notes from Nextcloud: {e}") # Try local cache try: with open(LOCAL_CACHE_FILE, 'r') as f: return json.load(f) except Exception as e: print(f"Could not load from local cache: {e}") # Return empty notes if both attempts fail return { "last_updated": datetime.now().isoformat(), "notes": [] } def get_release_notes_html(): """Generate HTML display of release notes.""" notes_data = load_release_notes() html = f""" <style> .release-notes {{ font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; }} .release-note {{ background: rgba(255, 255, 255, 0.05); border-radius: 8px; padding: 15px; margin-bottom: 20px; }} .note-date {{ font-size: 0.9em; color: #888; margin-bottom: 8px; }} .note-content {{ white-space: pre-wrap; line-height: 1.6; }} .last-updated {{ font-size: 0.8em; color: #666; text-align: right; margin-top: 20px; font-style: italic; }} </style> <div class="release-notes"> """ # Add notes in reverse chronological order for note in sorted(notes_data["notes"], key=lambda x: x["date"], reverse=True): html += f""" <div class="release-note"> <div class="note-date">📅 {note["date"]}</div> <div class="note-content">{note["content"]}</div> </div> """ html += f""" <div class="last-updated"> Last updated: {notes_data["last_updated"].split("T")[0]} </div> </div> """ return html