Kaynağa Gözat

added logging module. TODO: change prints to logging

Miek Stagl 5 yıl önce
ebeveyn
işleme
6b86ba8e04
3 değiştirilmiş dosya ile 20 ekleme ve 5 silme
  1. 2 0
      .gitignore
  2. 5 3
      CHANGELOG
  3. 13 2
      index.py

+ 2 - 0
.gitignore

@@ -1,2 +1,4 @@
 __pycache__
 *.swp
+*.log
+*.conf

+ 5 - 3
CHANGELOG

@@ -13,12 +13,14 @@ set the address attribute to only the first instance of the word.
 
 [0.1.1] Update .1 WIP
 
+applied hotfix 1
 Added ConfigParser to read landsearch.conf file and gather search criteria from this file.
-FUTURE - add .conf section for results.py to aid in results report generation.
+Added logging module to accept configs from landsearch.conf and log to logfile
+Added checktype to Search class.  This ensures that the word None in landsearch.conf translates to "''" in the qurystring
 
-applied hotfix 1
+FUTURE - allow logging to both logfile AND console
+FUTURE - add .conf section for results.py to aid in results report generation.
 
-Added checktype to Search class.  This ensures that the word None in landsearch.conf translates to "''" in the qurystring
 
 FUTURE GOALS
 - add .conf file

+ 13 - 2
index.py

@@ -12,6 +12,7 @@ import custom_email
 from tabulate import tabulate
 from configparser import ConfigParser
 from os import path
+import logging
 
 ### TO DO ###
 #
@@ -67,10 +68,11 @@ class Search:
     else:
       return ''
 
+
 #  def __init__(self, county: list, lower_price=0, upper_price=500000, \
 #    lower_acres=5, upper_acres=15, type=['farm','land','home'], lower_sqft='', upper_sqft='', \
 #    lower_bedrooms='', upper_bedrooms=''):
-  def __init__(self, file = '../landsearch.conf'):
+  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)
@@ -78,11 +80,20 @@ class Search:
       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.")
 
+    logging.basicConfig(filename=log_params.get('log_file'), \
+        level=log_params.get('logging_level', 30), \
+        format='%(asctime)s %(levelname)-8s %(message)s', \
+        datefmt='%Y-%m-%d %H:%M:%S')  ## Default log level WARNING (30)
+    logging.getLogger("urllib3").setLevel(logging.WARNING) ## Supress Requests method logging
+    logging.debug("Log level set to %s",  logging.root.level)
+
+
     county = search_params.get('county', ['Gwinnett', 'Hall', 'Jackson', 'Walton', 'Barrow'])
     if isinstance(county, str):
       county = county.split(", ")
@@ -114,7 +125,7 @@ class Search:
       assert property_type in self.types, ("Unknown type '" + property_type + "'. Property Type must be of type: " + str(self.types))
     
 ## FOR TESTING, PRINT ALL ATTRIBUTES OF SEARCH ##
-#    print(vars(self))
+    logging.debug(vars(self))
 
     
 class ImproperSearchError(Exception):