inwx_domains_owner: Preise je TLD aus domain_price in Summen
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
de 5,00
|
||||||
+50
-7
@@ -16,6 +16,7 @@ from inwx_common import get_client, call_api
|
|||||||
PAGE_LIMIT = 100 # Domains pro API-Seite
|
PAGE_LIMIT = 100 # Domains pro API-Seite
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
OWNER_FILE = os.path.join(BASE_DIR, "domain_owner")
|
OWNER_FILE = os.path.join(BASE_DIR, "domain_owner")
|
||||||
|
PRICE_FILE = os.path.join(BASE_DIR, "domain_price")
|
||||||
TXT_PREFIX = "citeq:" # Präfix der Gruppen-TXT-Einträge
|
TXT_PREFIX = "citeq:" # Präfix der Gruppen-TXT-Einträge
|
||||||
|
|
||||||
|
|
||||||
@@ -118,14 +119,54 @@ def tld_of(domain):
|
|||||||
return domain.rsplit('.', 1)[-1].lower() if '.' in domain else domain.lower()
|
return domain.rsplit('.', 1)[-1].lower() if '.' in domain else domain.lower()
|
||||||
|
|
||||||
|
|
||||||
def print_group_sums(recs, ziffer):
|
def load_prices():
|
||||||
|
"""Liest die Preise je Top-Level-Domain aus der Datei domain_price.
|
||||||
|
|
||||||
|
Format pro Zeile: <tld><Whitespace><preis>, z.B. 'de 5,00'. Als Dezimal-
|
||||||
|
trennzeichen wird Komma akzeptiert. Leere Zeilen und Kommentare (#) werden
|
||||||
|
ignoriert. Liefert ein Dict {tld: preis_als_float}.
|
||||||
|
"""
|
||||||
|
prices = {}
|
||||||
|
if not os.path.exists(PRICE_FILE):
|
||||||
|
print(f"⚠️ Datei {PRICE_FILE} nicht gefunden – keine Preise verfügbar.")
|
||||||
|
return prices
|
||||||
|
try:
|
||||||
|
with open(PRICE_FILE, "r") as f:
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
if not line or line.startswith("#"):
|
||||||
|
continue
|
||||||
|
parts = line.split(None, 1)
|
||||||
|
if len(parts) == 2:
|
||||||
|
tld, preis = parts
|
||||||
|
try:
|
||||||
|
prices[tld.strip().lower()] = float(preis.strip().replace(",", "."))
|
||||||
|
except ValueError:
|
||||||
|
print(f"⚠️ Ungültiger Preis in domain_price: {line!r}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Konnte {PRICE_FILE} nicht lesen: {e}")
|
||||||
|
return prices
|
||||||
|
|
||||||
|
|
||||||
|
def fmt_price(value):
|
||||||
|
"""Formatiert einen Betrag im deutschen Format, z.B. 10,00 €."""
|
||||||
|
return f"{value:.2f}".replace(".", ",") + " €"
|
||||||
|
|
||||||
|
|
||||||
|
def print_group_sums(recs, ziffer, prices):
|
||||||
"""Gibt für eine Gruppe die Anzahl Domains pro Top-Level-Domain aus.
|
"""Gibt für eine Gruppe die Anzahl Domains pro Top-Level-Domain aus.
|
||||||
|
|
||||||
Eine Zeile je TLD im Format <ziffer> <tld> <anzahl>, z.B. '10 de 1'.
|
Eine Zeile je TLD im Format <ziffer> <tld> <anzahl> <preis>, z.B.
|
||||||
|
'10 de 1 5,00 €'. Der Preis ergibt sich aus Anzahl × Einzelpreis laut
|
||||||
|
domain_price; fehlt ein Preis, wird ein Hinweis ausgegeben.
|
||||||
"""
|
"""
|
||||||
counts = Counter(tld_of(r['name']) for r in recs)
|
counts = Counter(tld_of(r['name']) for r in recs)
|
||||||
for tld, anzahl in sorted(counts.items()):
|
for tld, anzahl in sorted(counts.items()):
|
||||||
print(f" {ziffer} {tld} {anzahl}")
|
einzel = prices.get(tld)
|
||||||
|
if einzel is None:
|
||||||
|
print(f" {ziffer} {tld} {anzahl} (kein Preis)")
|
||||||
|
else:
|
||||||
|
print(f" {ziffer} {tld} {anzahl} {fmt_price(anzahl * einzel)}")
|
||||||
|
|
||||||
|
|
||||||
def format_domain_line(rec):
|
def format_domain_line(rec):
|
||||||
@@ -149,8 +190,9 @@ def main():
|
|||||||
print("ℹ️ Keine Domains gefunden.")
|
print("ℹ️ Keine Domains gefunden.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Zuordnung Ziffer -> Klarname laden (in Dateireihenfolge)
|
# Zuordnung Ziffer -> Klarname und Preise je TLD laden
|
||||||
owners = load_owners()
|
owners = load_owners()
|
||||||
|
prices = load_prices()
|
||||||
|
|
||||||
# Pro Domain einmal Ziffer (DNS) und Nameserver (API) ermitteln
|
# Pro Domain einmal Ziffer (DNS) und Nameserver (API) ermitteln
|
||||||
records = []
|
records = []
|
||||||
@@ -174,7 +216,7 @@ def main():
|
|||||||
if matching:
|
if matching:
|
||||||
for rec in matching:
|
for rec in matching:
|
||||||
print(format_domain_line(rec))
|
print(format_domain_line(rec))
|
||||||
print_group_sums(matching, ziffer) # Summe direkt unter den Domains
|
print_group_sums(matching, ziffer, prices) # Summe direkt unter den Domains
|
||||||
else:
|
else:
|
||||||
print(" (keine Domains)")
|
print(" (keine Domains)")
|
||||||
print() # Leerzeile zwischen den Gruppen
|
print() # Leerzeile zwischen den Gruppen
|
||||||
@@ -187,10 +229,11 @@ def main():
|
|||||||
ziffer = rec['ziffer']
|
ziffer = rec['ziffer']
|
||||||
hinweis = "" if ziffer is None else f" [citeq:{ziffer} unbekannt]"
|
hinweis = "" if ziffer is None else f" [citeq:{ziffer} unbekannt]"
|
||||||
print(format_domain_line(rec) + hinweis)
|
print(format_domain_line(rec) + hinweis)
|
||||||
print_group_sums(rest, "-") # Summe direkt unter den Domains
|
print_group_sums(rest, "-", prices) # Summe direkt unter den Domains
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print(f"Gesamt: {len(records)} Domain(s)")
|
gesamt_preis = sum(prices.get(tld_of(r['name']), 0.0) for r in records)
|
||||||
|
print(f"Gesamt: {len(records)} Domain(s), {fmt_price(gesamt_preis)}")
|
||||||
|
|
||||||
# Kein logout() -> die Session bleibt gültig und kann wiederverwendet werden.
|
# Kein logout() -> die Session bleibt gültig und kann wiederverwendet werden.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user