Spaces:
Sleeping
Sleeping
Update notify.py
Browse files
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 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
""
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 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 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
try:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
server.send_message(msg)
|
| 91 |
except Exception as e:
|
| 92 |
-
print(f"
|
|
|
|
| 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}")
|