Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- conn = sqlite3.connect('mydatabase.db')
- with conn:
- conn.row_factory = sqlite3.Row
- cur = conn.cursor()
- cur.execute("""CREATE TABLE IF NOT EXISTS `Peaks` (
- `state` TINYINT UNSIGNED,
- `tact` SMALLINT UNSIGNED,
- `recorded` DATETIME UNSIGNED NOT NULL)
- """)
- super_state = None
- tact_cycle = 1
- record_time = datetime.now().strftime('%Y-%m-%d %H')
- cur.execute("SELECT * FROM Peaks WHERE STRFTIME('%Y-%m-%d', recorded) == STRFTIME('%Y-%m-%d', 'now') ORDER BY STRFTIME('%Y-%m-%d %H', recorded) DESC LIMIT 1")
- data = cur.fetchone()
- if data is None:
- cur.execute("INSERT INTO Peaks (state, tact, recorded) VALUES (?, ?, ?)",
- (super_state, tact_cycle, record_time))
- else:
- cur.execute("UPDATE Peaks set state=? WHERE STRFTIME('%Y-%m-%d', recorded) == STRFTIME('%Y-%m-%d', 'now') ORDER BY STRFTIME('%Y-%m-%d %H', recorded) DESC LIMIT 1",
- (super_state))
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement