Skip to content

Instantly share code, notes, and snippets.

@RyanGWU82
Created September 13, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanGWU82/2e6d8bdce0b31a3757f98ffed8ff30bc to your computer and use it in GitHub Desktop.
Save RyanGWU82/2e6d8bdce0b31a3757f98ffed8ff30bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.6
from datetime import datetime
import random
import sqlite3
import time
def main():
prev_ts = time.time()
time.sleep(0.600)
conn = sqlite3.connect('example.db')
while True:
c = conn.cursor()
c.execute("SELECT foo FROM data")
rows = c.fetchall()
assert(len(rows) == 1)
curr_ts = rows[0][0]
if not isinstance(curr_ts, float):
print(f"{time.time()}: timestamp is not a float --> {curr_ts}")
elif curr_ts == prev_ts:
pass
elif curr_ts < prev_ts:
print(f"{time.time()}: timestamp moved backwards --> {prev_ts} to {curr_ts}")
elif curr_ts > (prev_ts + 0.603):
print(f"{time.time()}: timestamp moved forward too far --> {prev_ts} to {curr_ts}")
else:
print(f"{time.time()}: OK, timestamp advanced to {curr_ts}")
prev_ts = curr_ts
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment