What about the Event table in KoboReader.sqlite, as copied just after a reboot to avoid the "Runtime error: database disk image is malformed (11)"?
Code:
sqlite> .schema Event
CREATE TABLE Event (
EventType INTEGER NOT NULL,
FirstOccurrence TEXT,
LastOccurrence TEXT,
EventCount INTEGER DEFAULT 0,
ContentID TEXT,
ExtraData BLOB, Checksum TEXT,
PRIMARY KEY (EventType, ContentID) );
SELECT DISTINCT ContentID FROM Event ORDER BY LastOccurrence DESC LIMIT 10
Code:
import sqlite3, re
conn = sqlite3.connect("KoboReader.sqlite")
cur = conn.cursor()
pattern = re.compile("^file:///mnt/onboard/(.+)$")
cur.execute("SELECT DISTINCT ContentID FROM Event WHERE ContentID IS NOT '' ORDER BY LastOccurrence LIMIT 10")
for row in cur.fetchall():
book = m.group(1) if (m := pattern.search(row[0])) else "(not found)"
print(book)
conn.close()
The wxPython version:
Code:
import sys,os, wx
import sqlite3
import re
class ListBoxFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super().__init__(None, title='Books read on Kobo', size=(600, 800))
self.Centre()
panel = wx.Panel(self, id=wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
self.lb1 = wx.ListBox(panel, style=(wx.LB_SINGLE | wx.LB_ALWAYS_SB))
sizer.Add(self.lb1,1, wx.ALL | wx.EXPAND ,5)
self.run_btn = wx.Button(panel, label="Read")
sizer.Add(self.run_btn,0, wx.EXPAND)
self.run_btn.Bind(wx.EVT_BUTTON, self.OnRunButtonClick)
panel.SetSizer(sizer)
panel.Layout()
def OnRunButtonClick(self,event):
#clear, just in case
self.lb1.SetItems([])
self.run_btn.Disable()
conn = sqlite3.connect("KoboReader.sqlite")
cur = conn.cursor()
pattern = re.compile("^file:///mnt/onboard/(.+)$")
#ignore any .PNG and .TXT
cur.execute("SELECT DISTINCT ContentID FROM Event WHERE ContentID IS NOT '' AND ContentID NOT LIKE '%.png' AND ContentID NOT LIKE '%.txt' ORDER BY LastOccurrence")
for row in cur.fetchall():
book = m.group(1) if (m := pattern.search(row[0])) else "(not found)"
self.lb1.Append(book)
conn.close()
self.run_btn.Enable()
app = wx.App()
ListBoxFrame().Show()
app.MainLoop()
Query DB for string in title:
Code:
#Read string from clipboard, find if book in Kobo
import pyperclip
import sqlite3
book = pyperclip.paste()
conn = sqlite3.connect("KoboReader.sqlite")
cur = conn.cursor()
cur.execute(f"SELECT DISTINCT ContentID FROM Event WHERE ContentID LIKE '%{book}%'")
for row in cur.fetchall():
print(row[0])
conn.close()