data.py 571 B

1234567891011121314151617181920
  1. import database
  2. import stocks
  3. # Retrieve last and second to last timestamp from the server
  4. db = database.db
  5. cursor = db.cursor()
  6. query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1 OFFSET 1;"""
  7. cursor.execute(query)
  8. one_before_latest_entry_timestamp = cursor.fetchone()[0]
  9. query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1;"""
  10. cursor.execute(query)
  11. latest_entry_timestamp = cursor.fetchone()[0]
  12. print(one_before_latest_entry_timestamp)
  13. print(latest_entry_timestamp)
  14. cursor.close()
  15. db.close()