Created
September 13, 2019 21:29
-
-
Save RyanGWU82/2e6d8bdce0b31a3757f98ffed8ff30bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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