Files
adocWP/changelog.py
2026-05-27 14:17:22 +02:00

221 lines
9.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/python3
import requests
import locale
import json
from datetime import datetime, timedelta
import urllib.request
from collections import defaultdict
import re
############################################################################
############################################################################
############################################################################
#Konfiguration OLM
olm_api = 'https://olm.o-byte.com'
olm_USERNAME = 'restapi'
olm_PASSWD = 'CHANGEME'
#Konfiguration sonstige
file_path = '/opt/knowledge/antora/docs-site/build/site/Dokumentationen/0.1/welcome.html'
#folgende OLM NUmmern werden ignoriert
ignoreOLMno = ["olm-10109", "olm-10110"]
#Deutsch für das Datum setzten
locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8')
############################################################################
############################################################################
############################################################################
def get_olm_token(username, passwd):
authRequest = {}
authRequest['username'] = username
authRequest['password'] = passwd
req = urllib.request.Request(
olm_api + '/login', data=json.dumps(authRequest).encode('utf8'),
headers={'Content-type': 'application/json', 'Accept': 'application/json'})
response = urllib.request.urlopen(req)
responseText = response.read().decode('utf8')
return json.loads(responseText)
def sort_by_date(data):
return sorted(data, key=lambda x: datetime.strptime(x[0], "%Y-%m-%d"), reverse=True)
def wrap_with_ul(data):
lines = data.splitlines()
lines_with_li = [f"<li>{line}</li>" for line in lines]
return "<ul>\n" + "\n".join(lines_with_li) + "\n</ul>"
def parse_date(date_string):
return datetime.strptime(date_string, "%Y-%m-%d")
def replace_product_updates(file_path, new_content):
try:
# HTML-Datei öffnen und den Inhalt lesen
with open(file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
# Suchen nach dem Tag ###PRODUKTUPDATES### und Ersetzen durch den neuen Inhalt
updated_html = html_content.replace("###PRODUKTUPDATES###", new_content)
# Überschreiben der HTML-Datei mit dem aktualisierten Inhalt
with open(file_path, 'w', encoding='utf-8') as file:
file.write(updated_html)
print(f"Der Bereich ###PRODUKTUPDATES### wurde erfolgreich durch den neuen Inhalt ersetzt.")
except Exception as e:
print(f"Ein Fehler ist aufgetreten: {e}")
############################################################################
# Auth Tokens
############################################################################
# Auth Token OLM
token_olm = get_olm_token(olm_USERNAME, olm_PASSWD)
############################################################################
# Bearer Headers
############################################################################
headers_olm = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + token_olm['bearerToken']
}
product_ids = []
product_versions = []
page_products = 1
while True:
response = requests.get(olm_api + f"/api/rest/v1/product?page={page_products}&size=1", headers=headers_olm)
data = response.json()
products = data.get('content', [])
if not products:
break
for product in products:
ids = product.get('downloads', [])
for id in ids:
product_ids.append(id["id"])
page_products += 1
for product_id in product_ids:
page_versions = 1
while True:
response = requests.get(olm_api + f"/api/rest/v1/download/field/{product_id}?page={page_versions}&size=1", headers=headers_olm)
data = response.json()
versions = data.get('content', [])
if not versions:
break
for version in versions:
if version["qa"] and version["productVersion"]["product"]["published"] and version["publishedAt"]:
temp = []
if version["productVersion"]["product"]["productNo"] in ignoreOLMno:
continue
#temp.append(version["productVersion"]["createdOn"]) #0
temp.append(version["publishedAt"]) #0
temp.append(version["productVersion"]["product"]["name"]) #1
temp.append(version["changelog"]) #2
temp.append(version["productVersion"]["product"]["productPageURI"]) #3
temp.append(version["productVersion"]["product"]["productNo"]) #4
modul_version = str(version["productVersion"]["major"]) + "." + str(version["productVersion"]["minor"]) + "." + str(version["bugfixVersion"])
starface_min = str(version["productVersion"]["minStarfaceVersion"]["major"]) + "." + str(version["productVersion"]["minStarfaceVersion"]["minor"]) + "." + str(version["productVersion"]["minStarfaceVersion"]["build"]) + "." + str(version["productVersion"]["minStarfaceVersion"]["revision"])
starface_max = str(version["productVersion"]["maxStarfaceVersion"]["major"]) + "." + str(version["productVersion"]["maxStarfaceVersion"]["minor"]) + "." + str(version["productVersion"]["maxStarfaceVersion"]["build"]) + "." + str(version["productVersion"]["maxStarfaceVersion"]["revision"])
temp.append(modul_version) #5
temp.append(starface_min) #6
temp.append(starface_max) #7
temp.append(version["downloadField"]["name"]) #8
temp.append(version["downloadField"]["starfaceModule"]) #9
#print(temp)
product_versions.append(temp)
page_versions += 1
sorted_data = sort_by_date(product_versions)
aktuelles_datum = datetime.now()
drei_monate_zurueck = aktuelles_datum.replace(day=1) - timedelta(days=1)
drei_monate_zurueck = drei_monate_zurueck.replace(day=1) - timedelta(days=1)
drei_monate_zurueck = drei_monate_zurueck.replace(day=1) - timedelta(days=1)
drei_monate_zurueck = drei_monate_zurueck.replace(day=1) - timedelta(days=1)
anfang_vier_monate = drei_monate_zurueck.replace(day=1)
gefilterte_changelogs = []
for eintrag in sorted_data:
datum = parse_date(eintrag[0])
if anfang_vier_monate <= datum <= aktuelles_datum:
gefilterte_changelogs.append(eintrag)
sorted_data = gefilterte_changelogs
# Dictionary zum Gruppieren der Einträge nach Monat und Jahr
monthly_data = defaultdict(list)
# Daten in Monatsgruppen einordnen
for entry in sorted_data:
date_str = entry[0]
date_obj = datetime.strptime(date_str, "%Y-%m-%d")
month_year = date_obj.strftime("%B %Y") # z.B. "September 2023"
monthly_data[month_year].append(entry)
#print("4")
# Erstellen der HTML-Datei
# Sortiere die Monatsblöcke von neu nach alt und füge sie der HTML hinzu
html = "
"
for month_year, entries in sorted(monthly_data.items(), key=lambda x: datetime.strptime(x[0], "%B %Y"), reverse=True):
# Monats-Überschrift in einem separaten Table-Block
html += f"""
<table width="100%" style="background-color: #00a7e6; border-collapse: separate; border-spacing: 0; border-radius: 10px; overflow: hidden;"
<tr>
<td><h3>{month_year}</h3></td>
</tr>
</table>
"""
# Tabelle für die Produkte
for entry in entries:
date_obj = datetime.strptime(entry[0], "%Y-%m-%d")
date = date_obj.strftime("%d.%m.%Y")
if entry[9]:
produktname = entry[1]
else:
produktname = entry[1] + " - " + entry[8]
changelog = entry[2].replace("\n", "
\n")
changelog = wrap_with_ul(changelog)
html += f"""
<table width="100%" style="border-collapse: separate; border-spacing: 0; border-radius: 10px; overflow: hidden; border: 1px solid #ddd;">
<tr style="background-color: #ddd;">
<td ><b>{produktname} ({entry[5]})</b></td>
<td style="text-align: right;"><b>{date}</b>&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<u>Änderungen:</u>
{changelog}
</td>
</tr>
<tr>
<td style="border-top: 1px solid #ddd;" width="300px">kompatibel mit STARFACE Version:
</td>
<td style="border-top: 1px solid #ddd;">{entry[6]} - {entry[7]}
</td>
</tr>
<tr>
<td>Dokumentation
</td>
<td><a href='{entry[3]}' target='_blank' >{entry[3]}</a>
</td>
</tr>
<tr>
<td>Download
</td>
<td><a href='https://get.o-byte.com?olm={entry[4]}' target='_blank' >https://get.o-byte.com</a>
</td>
</tr>
</table>
"""
html += "
"
html += "
"
replace_product_updates(file_path, html)