#!/usr/bin/python3 import mysql.connector import logging from tabulate import tabulate 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()