sksameermujahid commited on
Commit
7414008
Β·
verified Β·
1 Parent(s): 81cf867

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +51 -24
app.py CHANGED
@@ -1102,7 +1102,7 @@ TWILIO_AUTH_TOKEN = "ddba202f5f4a48d08f04fb983a161fa3"
1102
  TWILIO_WHATSAPP_NUMBER = "whatsapp:+14155238886"
1103
  WHATSAPP_CHAR_LIMIT = 1600
1104
  PROPERTY_BASE_URL = "https://hiveprop.com/property/image-slider?id="
1105
- MAX_PROPERTIES_TO_SEND = 5
1106
  HIVEPROP_EMAIL_API_URL = "https://hivepropapi.azurewebsites.net/api/Email/sendPlainText"
1107
 
1108
  def send_email_recommendations(email, first_name, last_name, recommendations):
@@ -1114,31 +1114,57 @@ def send_email_recommendations(email, first_name, last_name, recommendations):
1114
  # Prepare email content
1115
  subject = f"Your Top {MAX_PROPERTIES_TO_SEND} Property Recommendations - HiveProp"
1116
 
1117
- # Create plain text email body (simpler format for testing)
1118
- email_body = f"🏑 Hello {first_name} {last_name}!\n\n"
1119
- email_body += f"Here are your top {MAX_PROPERTIES_TO_SEND} recommended properties in Hyderabad:\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1120
 
1121
  if not top_recommendations:
1122
- email_body += "⚠️ No specific properties found, but you can explore all available properties at https://hiveprop.com\n\n"
 
 
 
 
 
1123
  else:
1124
  for idx, prop in enumerate(top_recommendations, 1):
1125
  property_name = prop.get('propertyName', 'Unnamed Property')
1126
  property_id = prop.get('id', '')
1127
  property_link = f"{PROPERTY_BASE_URL}{property_id}"
1128
-
1129
- # Extract location from address or description
1130
  address = prop.get('address', '')
1131
  location = address.split(',')[-2].strip() if ',' in address else address
1132
 
1133
- email_body += f"{idx}. {property_name}\n"
1134
- email_body += f" πŸ“ Location: {location}\n"
1135
- email_body += f" πŸ”— {property_link}\n\n"
1136
-
1137
- email_body += "---\n"
1138
- email_body += "πŸ”Ž Looking for more options? Explore all listings at https://hiveprop.com\n\n"
1139
- email_body += "Thank you for using HiveProp!\n"
1140
- email_body += "Best regards,\n"
1141
- email_body += "The HiveProp Team"
 
 
 
 
 
 
 
1142
 
1143
  # Send email via HiveProp API using query parameters
1144
  params = {
@@ -1237,20 +1263,21 @@ def create_account_and_send_whatsapp():
1237
 
1238
  # Send via WhatsApp
1239
  try:
1240
- # Take only the top properties
1241
- top_recommendations = recommendations[:MAX_PROPERTIES_TO_SEND]
 
1242
 
1243
  logger.info(f"Total recommendations received: {len(recommendations)}")
1244
- logger.info(f"Top recommendations to send: {len(top_recommendations)}")
1245
 
1246
  # Prepare the WhatsApp message with improved design
1247
- message_header = f"🏑 *Hello {first_name} {last_name}!*\n\nHere are your *top {MAX_PROPERTIES_TO_SEND} recommended properties* in Hyderabad:\n"
1248
 
1249
  message_body = ""
1250
- if not top_recommendations:
1251
  message_body = "⚠️ No specific properties found, but you can explore all available properties at https://hiveprop.com\n\n"
1252
  else:
1253
- for idx, prop in enumerate(top_recommendations, 1):
1254
  property_name = prop.get('propertyName', 'Unnamed Property')
1255
  property_id = prop.get('id', '')
1256
  property_link = f"{PROPERTY_BASE_URL}{property_id}"
@@ -1305,8 +1332,8 @@ def create_account_and_send_whatsapp():
1305
  messages.append(f"WhatsApp error: {str(e)}")
1306
 
1307
  # Send via Email
1308
- logger.info(f"Sending email to {email} with {len(recommendations)} recommendations")
1309
- email_success, email_message = send_email_recommendations(email, first_name, last_name, recommendations)
1310
  messages.append(email_message)
1311
 
1312
  # Determine overall success and response message
 
1102
  TWILIO_WHATSAPP_NUMBER = "whatsapp:+14155238886"
1103
  WHATSAPP_CHAR_LIMIT = 1600
1104
  PROPERTY_BASE_URL = "https://hiveprop.com/property/image-slider?id="
1105
+ MAX_PROPERTIES_TO_SEND = 1 # Send only 1 property in email
1106
  HIVEPROP_EMAIL_API_URL = "https://hivepropapi.azurewebsites.net/api/Email/sendPlainText"
1107
 
1108
  def send_email_recommendations(email, first_name, last_name, recommendations):
 
1114
  # Prepare email content
1115
  subject = f"Your Top {MAX_PROPERTIES_TO_SEND} Property Recommendations - HiveProp"
1116
 
1117
+ # Create optimized HTML email body (under 1800 character limit)
1118
+ email_body = f"""<!DOCTYPE html>
1119
+ <html>
1120
+ <head>
1121
+ <style>
1122
+ body{{font-family:Arial;color:#333;margin:0;padding:20px}}
1123
+ .header{{background:#2c5aa0;color:white;padding:15px;text-align:center;border-radius:5px}}
1124
+ .content{{padding:15px}}
1125
+ .property{{border:1px solid #ddd;padding:10px;margin:10px 0;border-radius:3px;background:#f9f9f9}}
1126
+ .btn{{background:#2c5aa0;color:white;padding:8px 15px;text-decoration:none;border-radius:3px;display:inline-block}}
1127
+ .footer{{background:#f8f9fa;padding:15px;text-align:center;border-radius:3px}}
1128
+ </style>
1129
+ </head>
1130
+ <body>
1131
+ <div class="header">
1132
+ <h1>🏑 Hello {first_name} {last_name}!</h1>
1133
+ </div>
1134
+ <div class="content">
1135
+ <h2>Your Top {len(top_recommendations)} Property Recommendations</h2>"""
1136
 
1137
  if not top_recommendations:
1138
+ email_body += """
1139
+ <div class="property">
1140
+ <h3>⚠️ No specific properties found</h3>
1141
+ <p>We couldn't find specific properties matching your criteria, but you can explore all available properties on our website.</p>
1142
+ <a href="https://hiveprop.com" class="btn">Explore All Properties</a>
1143
+ </div>"""
1144
  else:
1145
  for idx, prop in enumerate(top_recommendations, 1):
1146
  property_name = prop.get('propertyName', 'Unnamed Property')
1147
  property_id = prop.get('id', '')
1148
  property_link = f"{PROPERTY_BASE_URL}{property_id}"
 
 
1149
  address = prop.get('address', '')
1150
  location = address.split(',')[-2].strip() if ',' in address else address
1151
 
1152
+ email_body += f"""
1153
+ <div class="property">
1154
+ <h3>{idx}. {property_name}</h3>
1155
+ <p>πŸ“ {location}</p>
1156
+ <a href="{property_link}" class="btn">View Details</a>
1157
+ </div>"""
1158
+
1159
+ email_body += f"""
1160
+ </div>
1161
+ <div class="footer">
1162
+ <h3>πŸ”Ž Looking for more options?</h3>
1163
+ <p>Explore all listings at <a href="https://hiveprop.com">hiveprop.com</a></p>
1164
+ <p>Thank you for using HiveProp!</p>
1165
+ </div>
1166
+ </body>
1167
+ </html>"""
1168
 
1169
  # Send email via HiveProp API using query parameters
1170
  params = {
 
1263
 
1264
  # Send via WhatsApp
1265
  try:
1266
+ # Take only the top properties (1 for email, 5 for WhatsApp)
1267
+ whatsapp_recommendations = recommendations[:5] # WhatsApp can handle more
1268
+ email_recommendations = recommendations[:MAX_PROPERTIES_TO_SEND] # Email gets 1
1269
 
1270
  logger.info(f"Total recommendations received: {len(recommendations)}")
1271
+ logger.info(f"WhatsApp recommendations to send: {len(whatsapp_recommendations)}")
1272
 
1273
  # Prepare the WhatsApp message with improved design
1274
+ message_header = f"🏑 *Hello {first_name} {last_name}!*\n\nHere are your *top {len(whatsapp_recommendations)} recommended properties* in Hyderabad:\n"
1275
 
1276
  message_body = ""
1277
+ if not whatsapp_recommendations:
1278
  message_body = "⚠️ No specific properties found, but you can explore all available properties at https://hiveprop.com\n\n"
1279
  else:
1280
+ for idx, prop in enumerate(whatsapp_recommendations, 1):
1281
  property_name = prop.get('propertyName', 'Unnamed Property')
1282
  property_id = prop.get('id', '')
1283
  property_link = f"{PROPERTY_BASE_URL}{property_id}"
 
1332
  messages.append(f"WhatsApp error: {str(e)}")
1333
 
1334
  # Send via Email
1335
+ logger.info(f"Sending email to {email} with {len(email_recommendations)} recommendations")
1336
+ email_success, email_message = send_email_recommendations(email, first_name, last_name, email_recommendations)
1337
  messages.append(email_message)
1338
 
1339
  # Determine overall success and response message