Miek Stagl 5 éve
szülő
commit
727b67529c
3 módosított fájl, 62 hozzáadás és 59 törlés
  1. 17 20
      custom_email.py
  2. 0 15
      index.py
  3. 45 24
      results.py

+ 17 - 20
custom_email.py

@@ -2,17 +2,18 @@
 
 import smtplib, ssl
 
+
 class simplemail:
 
-  def __init__(self, subject, body, sendto = [], user='stagl.mike@gmail.com', password='cherokee2'):
-    self.subject = subject
-    self.body = body
-    self.sendto = sendto
-    self.user = user
-    self.password = password
+    def __init__(self, subject, body, sendto=[], user='stagl.mike@gmail.com', password='cherokee2'):
+        self.subject = subject
+        self.body = body
+        self.sendto = sendto
+        self.user = user
+        self.password = password
 
-  def sendmail(self):
-    email_text = """\
+    def sendmail(self):
+        email_text = """\
 From: %s
 To: %s
 Subject: %s
@@ -20,15 +21,11 @@ Subject: %s
 %s
 """ % (self.user, self.sendto, self.subject, self.body)
 
-    try:
-      server_ssl = smtplib.SMTP_SSL('smtp.gmail.com', 465)
-      server_ssl.ehlo()
-      server_ssl.login(self.user, self.password)
-      server_ssl.sendmail(self.user, self.sendto, email_text)
-      server_ssl.close()
-    except Exception as e:
-      print('Something went wrong...', e)
-
-
-#myemail = simplemail('Test to multiple addrrsses', 'This is a test to two people.', ['stagl.mike@gmail.com', 'M_Stagl@hotmail.com'])
-#myemail.sendmail()
+        try:
+            server_ssl = smtplib.SMTP_SSL('smtp.gmail.com', 465)
+            server_ssl.ehlo()
+            server_ssl.login(self.user, self.password)
+            server_ssl.sendmail(self.user, self.sendto, email_text)
+            server_ssl.close()
+        except Exception as e:
+            print('Something went wrong...', e)

+ 0 - 15
index.py

@@ -3,9 +3,6 @@ import mysql.connector
 import requests
 from bs4 import BeautifulSoup
 import urllib.parse
-# import re
-# from sys import exit as exit
-# import json
 import datetime
 import custom_email
 from tabulate import tabulate
@@ -87,18 +84,6 @@ class Search:
             return ''
 
     def __init__(self, file='landsearch.conf'):
-        # self.file = file
-        # if not path.exists(self.file):
-        #   raise FileNotFoundError("The config file cannot be opened", self.file)
-        # try:
-        #   config = ConfigParser()
-        #   config.read(self.file)
-        #   search_params = config['Search']
-        #   log_params = config['Logging']
-        # except FileNotFoundError as err:
-        #   print(err, "Using default search parameters.")
-        # except Exception as err:
-        #   print(err, "Using default search parameters.")
         params = Parameters()
         search_params = params.search_params
         log_params = params.log_params

+ 45 - 24
results.py

@@ -1,30 +1,51 @@
 #!/usr/bin/python3
 
 import mysql.connector
+import logging
 from tabulate import tabulate
 
-host='192.168.100.26'
-user='landsearchuser'
-password='1234'
-database='landsearch'
 
-def closedb():
-    """Cleanly close the db."""
-    cursor.close()
-    cnx.close()
-
-cnx = mysql.connector.connect(host=host, user=user, password=password, database=database, buffered=True)
-cursor = cnx.cursor()
-
-cursor.execute('SELECT id, MLS, address, sqft, acres, zoning, price, time_to_school/60, time_to_work/60, link, notes FROM properties WHERE time_to_school < 1800 ORDER BY time_to_school ASC')
-
-results = cursor.fetchall()
-
-print(tabulate(results, headers=['ID', 'MLS', 'Address', 'sqft', 'acres', 'zoning', 'price', 'school (min)', 'work(min)', 'link', 'notes']))
-
-#print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
-
-#for result in results:
-#  print(tabulate([[result[0], result[1]]]))
-
-closedb
+class Results:
+
+    def __init__(self):
+        self.host = '192.168.100.26'
+        self.user = 'landsearchuser'
+        self.password = '1234'
+        self.database = 'landsearch'
+        self.logger = logging.getLogger(__name__)
+        self.logger.setLevel(logging.CRITICAL)
+        # Not working.  INFO and DEBUG messages get masked regardless of logging level
+
+    def connect_db(self):
+        self.logger.WARNING("Connecting to db.")
+        self.cnx = mysql.connector.connect(host=self.host, user=self.user, password=self.password,
+                                           database=self.database, buffered=True)
+        self.cursor = self.cnx.cursor()
+        return self.cursor
+
+    def close_db(self):
+        """Cleanly close the db."""
+        self.cursor.close()
+        self.cnx.close()
+
+
+if __name__ == '__main__':
+    test = Results()
+    print(test.logger.getEffectiveLevel())
+    test.connect_db()
+
+    # cursor.execute(
+    #     'SELECT id, MLS, address, sqft, acres, zoning, price, time_to_school/60, time_to_work/60, link, notes FROM properties WHERE time_to_school < 1800 ORDER BY time_to_school ASC')
+    #
+    # results = cursor.fetchall()
+    #
+    # print(tabulate(results,
+    #                headers=['ID', 'MLS', 'Address', 'sqft', 'acres', 'zoning', 'price', 'school (min)', 'work(min)', 'link',
+    #                         'notes']))
+    #
+    # # print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
+    #
+    # # for result in results:
+    # #  print(tabulate([[result[0], result[1]]]))
+
+    test.close_db()