|
@@ -9,6 +9,7 @@ from tabulate import tabulate
|
|
|
from configparser import ConfigParser
|
|
from configparser import ConfigParser
|
|
|
from os import path
|
|
from os import path
|
|
|
import logging
|
|
import logging
|
|
|
|
|
+from email.mime.text import MIMEText
|
|
|
|
|
|
|
|
|
|
|
|
|
### TO DO ###
|
|
### TO DO ###
|
|
@@ -57,6 +58,7 @@ class Parameters:
|
|
|
self.config.read(self.file)
|
|
self.config.read(self.file)
|
|
|
self.search_params = self.config['Search']
|
|
self.search_params = self.config['Search']
|
|
|
self.log_params = self.config['Logging']
|
|
self.log_params = self.config['Logging']
|
|
|
|
|
+ self.email_params = self.config['Email']
|
|
|
except Exception as err:
|
|
except Exception as err:
|
|
|
print(err, "Using default search Parameters")
|
|
print(err, "Using default search Parameters")
|
|
|
|
|
|
|
@@ -146,6 +148,7 @@ class MLSDATA:
|
|
|
self.new_listings = []
|
|
self.new_listings = []
|
|
|
self.email = self.parameters.search_params.getboolean('email')
|
|
self.email = self.parameters.search_params.getboolean('email')
|
|
|
self.live_google = self.parameters.search_params.getboolean('live_google')
|
|
self.live_google = self.parameters.search_params.getboolean('live_google')
|
|
|
|
|
+ self.recipients = self.parameters.email_params['recipients']
|
|
|
print('Email ' + str(self.email))
|
|
print('Email ' + str(self.email))
|
|
|
|
|
|
|
|
def stringbuilder(self, search: Search, county):
|
|
def stringbuilder(self, search: Search, county):
|
|
@@ -422,18 +425,25 @@ class MLSDATA:
|
|
|
logging.info(str(len(self.new_listings)) + " new listings found.")
|
|
logging.info(str(len(self.new_listings)) + " new listings found.")
|
|
|
|
|
|
|
|
def email_results(self):
|
|
def email_results(self):
|
|
|
- global mymail
|
|
|
|
|
- sendto = ['stagl.mike@gmail.com', 'M_Stagl@hotmail.com']
|
|
|
|
|
|
|
+ global mymail, html
|
|
|
|
|
+ html = ''
|
|
|
|
|
+ # sendto = ['M_Stagl@hotmail.com', 'stagl.mike@gmail.com']
|
|
|
|
|
+ sendto = self.recipients.split(',')
|
|
|
|
|
+ # print(type(self.recipients))
|
|
|
|
|
+ # print(type(sendto))
|
|
|
if self.email:
|
|
if self.email:
|
|
|
''' Send some kind of email! '''
|
|
''' Send some kind of email! '''
|
|
|
# If there are new listings, populate email ##
|
|
# If there are new listings, populate email ##
|
|
|
if len(self.new_listings) > 0:
|
|
if len(self.new_listings) > 0:
|
|
|
body = ''
|
|
body = ''
|
|
|
data = []
|
|
data = []
|
|
|
|
|
+ html = '<html><head></head><body>'
|
|
|
|
|
+ html += '<p>Daily Real Estate Search Report.</p>'
|
|
|
|
|
+ html += '<p>The following properties have been found which may be of interest:</p>'
|
|
|
|
|
+ html += '<table>'
|
|
|
subj = str(len(self.new_listings)) + " New Real Estate Listings for " + str(datetime.date.today())
|
|
subj = str(len(self.new_listings)) + " New Real Estate Listings for " + str(datetime.date.today())
|
|
|
for listing in self.new_listings:
|
|
for listing in self.new_listings:
|
|
|
row = []
|
|
row = []
|
|
|
- body += listing.MLS + " | " + listing.address + " | " + listing.acres + " | " + listing.price + " | " + listing.link + "\n"
|
|
|
|
|
row.append(listing.MLS)
|
|
row.append(listing.MLS)
|
|
|
row.append(listing.address)
|
|
row.append(listing.address)
|
|
|
row.append('{:0,.2f}'.format(float(listing.acres)))
|
|
row.append('{:0,.2f}'.format(float(listing.acres)))
|
|
@@ -442,22 +452,37 @@ class MLSDATA:
|
|
|
row.append(listing.time_to_school / 60 if hasattr(listing, 'time_to_school') else 'NA')
|
|
row.append(listing.time_to_school / 60 if hasattr(listing, 'time_to_school') else 'NA')
|
|
|
row.append(listing.link)
|
|
row.append(listing.link)
|
|
|
data.append(row)
|
|
data.append(row)
|
|
|
- body = """\
|
|
|
|
|
- Daily Real Estate Search Report\n
|
|
|
|
|
- The following properties have been found which may be of interest.\n
|
|
|
|
|
- """
|
|
|
|
|
- results = tabulate(data,
|
|
|
|
|
- headers=['MLS', 'Address', 'Acres', 'sqft', 'Price', 'Time to School', 'link'])
|
|
|
|
|
- body += results
|
|
|
|
|
-
|
|
|
|
|
- mymail = custom_email.simplemail(subj, body, sendto)
|
|
|
|
|
|
|
+ html += '<tr><td colspan=100%><hr></td></tr>'
|
|
|
|
|
+ html += '<tr><th>MLS</th><td>' + listing.MLS + '</td></tr>'
|
|
|
|
|
+ html += '<tr><th>Address</th><td>' + listing.address + '</td></tr>'
|
|
|
|
|
+ html += '<tr><th>Acres</th><td>' + '{:0,.2f}'.format(float(listing.acres)) + '</td></tr>'
|
|
|
|
|
+ html += '<tr><th>Time To School</th><td>' + (listing.time_to_school/60 if hasattr(listing, 'time_to_school') else 'NA') + '</td></tr>'
|
|
|
|
|
+ html += '<tr><th>Price</th><td>' + '${:0,.0f}'.format(int(listing.price)) + '</td></tr>'
|
|
|
|
|
+ html += '<tr><th>Link</th><td><a href=' + listing.link + '>Link</a></td></tr>'
|
|
|
|
|
+ body = """Daily Real Estate Search Report.\n
|
|
|
|
|
+The following properties have been found which may be of interest.\n
|
|
|
|
|
+"""
|
|
|
|
|
+ results = tabulate(data, headers=['MLS', 'Address', 'Acres', 'sqft', 'Price', 'Time to School', 'link'])
|
|
|
|
|
+ body += results
|
|
|
|
|
+
|
|
|
|
|
+ html += '<tr><td colspan=100%><hr></td></tr>'
|
|
|
|
|
+ html += '</table></body></html>'
|
|
|
|
|
+ # htmlformat = MIMEText(html, 'html')
|
|
|
|
|
+
|
|
|
|
|
+ # mymail = custom_email.simplemail(subj, body, sendto)
|
|
|
|
|
+ # mymail = custom_email.simplemail(subj, htmlformat, sendto)
|
|
|
|
|
+
|
|
|
|
|
+ # print(body)
|
|
|
|
|
+ # print(html)
|
|
|
else:
|
|
else:
|
|
|
body = 'No new listings found'
|
|
body = 'No new listings found'
|
|
|
|
|
+ html = 'No new listings found.'
|
|
|
subj = '0 New Real Estate Listings for ' + str(datetime.date.today())
|
|
subj = '0 New Real Estate Listings for ' + str(datetime.date.today())
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
- mymail = custom_email.simplemail(subj, body, sendto)
|
|
|
|
|
- mymail.sendmail()
|
|
|
|
|
|
|
+ mymail = custom_email.simplemail(subj, body, sendto, html=html)
|
|
|
|
|
+ # mymail = custom_email.simplemail(subj, body, sendto)
|
|
|
|
|
+ mymail.sendhtml()
|
|
|
print("Email sent.")
|
|
print("Email sent.")
|
|
|
logging.info('Emails sent to: ' + str(sendto))
|
|
logging.info('Emails sent to: ' + str(sendto))
|
|
|
except Exception as e:
|
|
except Exception as e:
|