I'm trying to create a script based on a datepicker in Python and Tkinter.
I can pick a date, start and end date, convert it to unix timestamp, but when I query a sqlite3 database, the response is:
File "/home/frits/Documents/python_datetime/cal.py", line 46, in <module>
c.execute('SELECT * from RecordOne where ct = ?' % unix_timea, (unix_timeb,))
TypeError: not all arguments converted during string formatting
I thought bij converting the unix_time variables to integers solves the problem, but no.
I don't see the error..
Can anyone point out my mistake?
My terrible bad code is:
import datetime
from datetime import timedelta
import time
import sqlite3
def get_date():
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar, DateEntry
def cal_done():
top.withdraw()
root.quit()
root = tk.Tk()
root.withdraw() # keep the root window from appearing
top = tk.Toplevel(root)
cal = Calendar(top,
font="Arial 14", selectmode='day',
cursor="hand1")
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=cal_done).pack()
selected_date = None
root.mainloop()
return cal.selection_get()
selection = get_date()
dt = selection
start = dt - timedelta(days=dt.weekday())
unix_time = time.mktime(start.timetuple())
unix_timea= int(unix_time)
print(unix_timea)
end = start + timedelta(days=6)
unix_time1 = time.mktime(end.timetuple())
unix_timeb = int(unix_time1)
print(unix_timeb)
conn = sqlite3.connect('monitor.db')
c = conn.cursor()
c.execute('SELECT * from RecordOne where ct = ?' % unix_timea, (unix_timeb,))
test = c.fetchall()
for row in test:
print(row)
.