Spaces:
Running
Running
Create release_notes.py
Browse files- release_notes.py +96 -0
release_notes.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from nc_py_api import Nextcloud
|
2 |
+
import json
|
3 |
+
from datetime import datetime
|
4 |
+
import config
|
5 |
+
|
6 |
+
# Initialize Nextcloud client
|
7 |
+
nc = Nextcloud(
|
8 |
+
nextcloud_url=config.NEXTCLOUD_URL,
|
9 |
+
nc_auth_user=config.NEXTCLOUD_USERNAME,
|
10 |
+
nc_auth_pass=config.NEXTCLOUD_PASSWORD
|
11 |
+
)
|
12 |
+
|
13 |
+
NEXTCLOUD_NOTES_PATH = "/gpu_poor_release_notes.json"
|
14 |
+
LOCAL_CACHE_FILE = "release_notes.json"
|
15 |
+
|
16 |
+
def load_release_notes():
|
17 |
+
"""Load release notes from Nextcloud with local file fallback."""
|
18 |
+
try:
|
19 |
+
# Try to load from Nextcloud
|
20 |
+
remote_data = nc.files.download(NEXTCLOUD_NOTES_PATH)
|
21 |
+
if remote_data:
|
22 |
+
notes = json.loads(remote_data.decode('utf-8'))
|
23 |
+
# Update local cache
|
24 |
+
with open(LOCAL_CACHE_FILE, 'w') as f:
|
25 |
+
json.dump(notes, f, indent=2)
|
26 |
+
return notes
|
27 |
+
except Exception as e:
|
28 |
+
print(f"Could not load release notes from Nextcloud: {e}")
|
29 |
+
|
30 |
+
# Try local cache
|
31 |
+
try:
|
32 |
+
with open(LOCAL_CACHE_FILE, 'r') as f:
|
33 |
+
return json.load(f)
|
34 |
+
except Exception as e:
|
35 |
+
print(f"Could not load from local cache: {e}")
|
36 |
+
|
37 |
+
# Return empty notes if both attempts fail
|
38 |
+
return {
|
39 |
+
"last_updated": datetime.now().isoformat(),
|
40 |
+
"notes": []
|
41 |
+
}
|
42 |
+
|
43 |
+
def get_release_notes_html():
|
44 |
+
"""Generate HTML display of release notes."""
|
45 |
+
notes_data = load_release_notes()
|
46 |
+
|
47 |
+
html = f"""
|
48 |
+
<style>
|
49 |
+
.release-notes {{
|
50 |
+
font-family: Arial, sans-serif;
|
51 |
+
max-width: 800px;
|
52 |
+
margin: 0 auto;
|
53 |
+
}}
|
54 |
+
.release-note {{
|
55 |
+
background: rgba(255, 255, 255, 0.05);
|
56 |
+
border-radius: 8px;
|
57 |
+
padding: 15px;
|
58 |
+
margin-bottom: 20px;
|
59 |
+
}}
|
60 |
+
.note-date {{
|
61 |
+
font-size: 0.9em;
|
62 |
+
color: #888;
|
63 |
+
margin-bottom: 8px;
|
64 |
+
}}
|
65 |
+
.note-content {{
|
66 |
+
white-space: pre-wrap;
|
67 |
+
line-height: 1.6;
|
68 |
+
}}
|
69 |
+
.last-updated {{
|
70 |
+
font-size: 0.8em;
|
71 |
+
color: #666;
|
72 |
+
text-align: right;
|
73 |
+
margin-top: 20px;
|
74 |
+
font-style: italic;
|
75 |
+
}}
|
76 |
+
</style>
|
77 |
+
<div class="release-notes">
|
78 |
+
"""
|
79 |
+
|
80 |
+
# Add notes in reverse chronological order
|
81 |
+
for note in sorted(notes_data["notes"], key=lambda x: x["date"], reverse=True):
|
82 |
+
html += f"""
|
83 |
+
<div class="release-note">
|
84 |
+
<div class="note-date">📅 {note["date"]}</div>
|
85 |
+
<div class="note-content">{note["content"]}</div>
|
86 |
+
</div>
|
87 |
+
"""
|
88 |
+
|
89 |
+
html += f"""
|
90 |
+
<div class="last-updated">
|
91 |
+
Last updated: {notes_data["last_updated"].split("T")[0]}
|
92 |
+
</div>
|
93 |
+
</div>
|
94 |
+
"""
|
95 |
+
|
96 |
+
return html
|