119 lines
5.0 KiB
Python
119 lines
5.0 KiB
Python
import sys
|
|
|
|
with open('fotograf-de-scraper/backend/main.py', 'r') as f:
|
|
content = f.read()
|
|
|
|
old_code = """ # 3. Aggregate results by Email
|
|
aggregation = {}
|
|
missing_links_count = 0
|
|
|
|
for c in candidates:
|
|
email = c.email_eltern.lower()
|
|
|
|
# Skip if this email already has a purchase for ANOTHER child
|
|
if exclude_purchased_emails and email in purchased_emails:
|
|
continue
|
|
|
|
# STRICT LINK CHECK: If we don't have a scraped Quick Login URL, skip this child.
|
|
# We don't want to send broken /login/access/ links.
|
|
if not c.quick_login_url:
|
|
missing_links_count += 1
|
|
continue
|
|
|
|
if email not in aggregation:
|
|
aggregation[email] = {
|
|
"email": email,
|
|
"parent_name": c.vorname_eltern if c.vorname_eltern else "Liebe Eltern",
|
|
"children": [],
|
|
"links": []
|
|
}
|
|
|
|
# Add child name
|
|
child_name = c.vorname_kind or ""
|
|
child_label = "Familienbilder" if child_name.lower() == "familie" else child_name
|
|
if child_label and child_label not in aggregation[email]["children"]:
|
|
aggregation[email]["children"].append(child_label)
|
|
|
|
# Add Quick Login Link (Guaranteed to exist here)
|
|
html_link = f'<a href="{c.quick_login_url}">Fotos von {child_label}</a>'
|
|
if html_link not in aggregation[email]["links"]:
|
|
aggregation[email]["links"].append(html_link)
|
|
|
|
# 4. Format for Supermailer/Gmail
|
|
final_result = []
|
|
for email, data in aggregation.items():
|
|
children_str = " und ".join(data["children"]) if len(data["children"]) > 1 else (data["children"][0] if data["children"] else "Eurem Kind")
|
|
links_html = "".join([f"{l}<br>" for l in data["links"]])
|
|
|
|
final_result.append({
|
|
"E-Mail-Adresse Käufer": email,
|
|
"Name Käufer": data["parent_name"],
|
|
"Kindernamen": children_str,
|
|
"Anzahl Kinder": len(data["children"]),
|
|
"LinksHTML": links_html
|
|
})
|
|
|
|
progress_msg = f"Analyse fertig! {len(final_result)} Empfänger identifiziert."
|
|
if missing_links_count > 0:
|
|
progress_msg += f" (Hinweis: {missing_links_count} Kinder ignoriert, da Quick-Login-Link fehlt. Bitte vorher 'Daten abgleichen' drücken!)"
|
|
|
|
task_store[task_id] = {"""
|
|
|
|
new_code = """ # 3. Aggregate results by Email
|
|
aggregation = {}
|
|
|
|
base_url = "https://kinderfoto-erding.fotograf.de" if account_type == "kiga" else "https://kinderfotos-erding.fotograf.de"
|
|
login_url = f"{base_url}/login"
|
|
|
|
for c in candidates:
|
|
email = c.email_eltern.lower()
|
|
|
|
# Skip if this email already has a purchase for ANOTHER child
|
|
if exclude_purchased_emails and email in purchased_emails:
|
|
continue
|
|
|
|
if email not in aggregation:
|
|
aggregation[email] = {
|
|
"email": email,
|
|
"parent_name": c.vorname_eltern if c.vorname_eltern else "Liebe Eltern",
|
|
"children": [],
|
|
"links": []
|
|
}
|
|
|
|
# Add child name
|
|
child_name = c.vorname_kind or ""
|
|
child_label = "Familienbilder" if child_name.lower() == "familie" else child_name
|
|
if child_label and child_label not in aggregation[email]["children"]:
|
|
aggregation[email]["children"].append(child_label)
|
|
|
|
# Add Zugangscode and Login Link
|
|
html_link = f'Fotos von {child_label}: Code <b>{c.zugangscode}</b> (<a href="{login_url}">Hier einloggen</a>)'
|
|
if html_link not in aggregation[email]["links"]:
|
|
aggregation[email]["links"].append(html_link)
|
|
|
|
# 4. Format for Supermailer/Gmail
|
|
final_result = []
|
|
for email, data in aggregation.items():
|
|
children_str = " und ".join(data["children"]) if len(data["children"]) > 1 else (data["children"][0] if data["children"] else "Eurem Kind")
|
|
links_html = "".join([f"{l}<br>" for l in data["links"]])
|
|
|
|
final_result.append({
|
|
"E-Mail-Adresse Käufer": email,
|
|
"Name Käufer": data["parent_name"],
|
|
"Kindernamen": children_str,
|
|
"Anzahl Kinder": len(data["children"]),
|
|
"LinksHTML": links_html
|
|
})
|
|
|
|
progress_msg = f"Analyse fertig! {len(final_result)} Empfänger identifiziert."
|
|
|
|
task_store[task_id] = {"""
|
|
|
|
if old_code in content:
|
|
content = content.replace(old_code, new_code)
|
|
with open('fotograf-de-scraper/backend/main.py', 'w') as f:
|
|
f.write(content)
|
|
print("Patched successfully")
|
|
else:
|
|
print("Old code not found")
|