0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2024-12-23 22:22:59 +03:00
yandex-music-linux/utility/extract_release_notes.py

43 lines
1.3 KiB
Python
Raw Normal View History

2024-02-09 17:35:17 +03:00
import json
2024-08-29 16:53:47 +03:00
import sys
2024-10-30 12:17:08 +03:00
import requests
2024-02-09 17:35:17 +03:00
2024-10-30 12:17:08 +03:00
if len(sys.argv) < 2:
print("Usage: python extract_release_notes.py <save_file_name>")
2024-02-09 17:35:17 +03:00
sys.exit(1)
2024-10-30 12:17:08 +03:00
save_file_name = sys.argv[1]
2024-08-29 16:52:02 +03:00
2024-02-09 17:35:17 +03:00
def build_html(data, first_launch=False):
html = ""
for i, element in enumerate(data):
if element['type'] == 0:
if first_launch and i == 0:
html += f"<h3>{element['value']}</h3>".replace('\n', '<br/>')
2024-02-09 17:35:17 +03:00
continue
if element['value'] == '\n':
2024-03-14 18:38:33 +03:00
continue
2024-02-09 17:35:17 +03:00
else:
html += f"<span>{element['value']}</span>".replace('\n', '<br/>')
elif element['type'] == 8:
html += f"<{element['value']}>{build_html(element['children'])}</{element['value']}>"
return html
2024-08-29 16:52:02 +03:00
2024-10-30 12:17:08 +03:00
response = requests.get("https://music-desktop-application.s3.yandex.net/stable/release-notes/ru.json")
if not response.ok:
print("Failed to download file")
sys.exit(1)
2024-02-09 17:35:17 +03:00
notes = {}
2024-04-20 14:04:50 +03:00
element_key: str
2024-10-30 12:17:08 +03:00
for element_key in response.json().keys():
2024-04-20 14:04:50 +03:00
if not element_key.startswith("desktop-release-notes."):
continue
2024-10-30 12:17:08 +03:00
notes[element_key] = build_html(response.json()[element_key], True)
2024-02-09 17:35:17 +03:00
with open(save_file_name, "w", encoding='utf-8') as file:
2024-08-29 16:52:02 +03:00
file.write(json.dumps(notes, ensure_ascii=False, indent=4))
2024-10-30 12:17:08 +03:00