results.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python3
  2. import mysql.connector
  3. import logging
  4. from tabulate import tabulate
  5. class Results:
  6. def __init__(self):
  7. self.host = '192.168.100.26'
  8. self.user = 'landsearchuser'
  9. self.password = '1234'
  10. self.database = 'landsearch'
  11. self.logger = logging.getLogger(__name__)
  12. self.logger.setLevel(logging.CRITICAL)
  13. # Not working. INFO and DEBUG messages get masked regardless of logging level
  14. def connect_db(self):
  15. self.logger.WARNING("Connecting to db.")
  16. self.cnx = mysql.connector.connect(host=self.host, user=self.user, password=self.password,
  17. database=self.database, buffered=True)
  18. self.cursor = self.cnx.cursor()
  19. return self.cursor
  20. def close_db(self):
  21. """Cleanly close the db."""
  22. self.cursor.close()
  23. self.cnx.close()
  24. if __name__ == '__main__':
  25. test = Results()
  26. print(test.logger.getEffectiveLevel())
  27. test.connect_db()
  28. # cursor.execute(
  29. # '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')
  30. #
  31. # results = cursor.fetchall()
  32. #
  33. # print(tabulate(results,
  34. # headers=['ID', 'MLS', 'Address', 'sqft', 'acres', 'zoning', 'price', 'school (min)', 'work(min)', 'link',
  35. # 'notes']))
  36. #
  37. # # print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
  38. #
  39. # # for result in results:
  40. # # print(tabulate([[result[0], result[1]]]))
  41. test.close_db()