AKKI-AFK commited on
Commit
00a5d67
·
verified ·
1 Parent(s): dae8bd7

Update notify.py

Browse files
Files changed (1) hide show
  1. notify.py +30 -32
notify.py CHANGED
@@ -1,11 +1,12 @@
1
- import os
2
- import os
3
  import smtplib
4
  from email.mime.text import MIMEText
5
  from email.mime.multipart import MIMEMultipart
6
  from dotenv import load_dotenv
7
  from pyairtable import Table
8
 
 
 
9
  load_dotenv()
10
  # Airtable settings
11
  AIRTABLE_BASE = os.getenv("AIRTABLE_BASE")
@@ -55,38 +56,35 @@ def update_airtable(isbn, status, confidence, issues, overlay_url, validation_me
55
  record = table.create(fields)
56
  return record
57
 
58
-
59
  def send_email(isbn, status, issues, overlay_url, confidence, to_email):
60
- subject = f"Cover Validation Result — {isbn} ({status})"
61
- if status == "PASS":
62
- body = f"""
63
- <p>Hello,</p>
64
- <p>Status: PASS</p>
65
- <p>Your cover passed all checks.</p>
66
- <p>Confidence: {confidence:.1f}%</p>
67
- <p><a href="{overlay_url}">View Overlay</a></p>
68
- <p>Thank you,<br>BookLeaf Publishing</p>
69
- """
70
- else:
71
- body = f"""
72
- <p>Hello,</p>
73
- <p>Status: ❌ REVIEW NEEDED</p>
74
- <p>Issues: {issues}</p>
75
- <p>Confidence: {confidence:.1f}%</p>
76
- <p><a href="{overlay_url}">View Overlay</a></p>
77
- <p>Please correct and re-upload your file.</p>
78
- """
79
 
80
- msg = MIMEMultipart("alternative")
81
- msg["Subject"] = subject
82
- msg["From"] = FROM_EMAIL
83
- msg["To"] = to_email
84
- msg.attach(MIMEText(body, "html"))
 
 
 
 
85
 
86
  try:
87
- with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
88
- server.starttls()
89
- server.login(SMTP_USER, SMTP_PASS)
90
- server.send_message(msg)
91
  except Exception as e:
92
- print(f"Email send failed: {e}")
 
1
+ import os, requests
 
2
  import smtplib
3
  from email.mime.text import MIMEText
4
  from email.mime.multipart import MIMEMultipart
5
  from dotenv import load_dotenv
6
  from pyairtable import Table
7
 
8
+ MAKE_WEBHOOK = os.getenv("MAKE_WEBHOOK")
9
+
10
  load_dotenv()
11
  # Airtable settings
12
  AIRTABLE_BASE = os.getenv("AIRTABLE_BASE")
 
56
  record = table.create(fields)
57
  return record
58
 
 
59
  def send_email(isbn, status, issues, overlay_url, confidence, to_email):
60
+ if not MAKE_WEBHOOK:
61
+ print("Make webhook not configured.")
62
+ return
63
+
64
+ payload = {
65
+ "isbn": isbn,
66
+ "status": status,
67
+ "issues": issues,
68
+ "overlay_url": overlay_url,
69
+ "confidence": confidence,
70
+ "to_email": to_email,
71
+ "subject": f"BookLeaf Cover Validation: {status}",
72
+ "body": f"""
73
+ Hello,
 
 
 
 
 
74
 
75
+ Status: {'✅ PASS' if status == 'PASS' else '❌ REVIEW NEEDED'}
76
+ Issues: {', '.join(issues) if isinstance(issues, list) else issues}
77
+ Confidence: {confidence}%
78
+
79
+ View Overlay: {overlay_url or 'N/A'}
80
+
81
+ Please correct and re-upload your file if needed.
82
+ """,
83
+ }
84
 
85
  try:
86
+ r = requests.post(MAKE_WEBHOOK, json=payload, timeout=10)
87
+ r.raise_for_status()
88
+ print("Make webhook triggered successfully.")
 
89
  except Exception as e:
90
+ print(f"Make webhook send failed: {e}")