results.py 882 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/python3
  2. import mysql.connector
  3. from tabulate import tabulate
  4. host='192.168.100.26'
  5. user='landsearchuser'
  6. password='1234'
  7. database='landsearch'
  8. def closedb():
  9. """Cleanly close the db."""
  10. cursor.close()
  11. cnx.close()
  12. cnx = mysql.connector.connect(host=host, user=user, password=password, database=database, buffered=True)
  13. cursor = cnx.cursor()
  14. 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')
  15. results = cursor.fetchall()
  16. print(tabulate(results, headers=['ID', 'MLS', 'Address', 'sqft', 'acres', 'zoning', 'price', 'school (min)', 'work(min)', 'link', 'notes']))
  17. #print(tabulate([['Alice', 24], ['Bob', 19]], headers=['Name', 'Age']))
  18. #for result in results:
  19. # print(tabulate([[result[0], result[1]]]))
  20. closedb