diff options
Diffstat (limited to 'noto.py')
-rwxr-xr-x | noto.py | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +import argparse +import os +import re +import sqlite3 + +class Noto: + def __init__(self, path): + con = sqlite3.connect(path) + cur = con.cursor() + query = ("select " + "Bookmark.Text," + "Bookmark.ContentID " + "from " + "Bookmark," + "content " + "WHERE " + "Bookmark.ContentID = content.ContentID;") + cur.execute(query) + self.data = cur.fetchall() + cur.close() + con.close() + + def _sanitize(self, name): + name = re.sub(r"[^a-zA-Z0-9_.\ ]", "", name) + name = re.sub(" +", " ", name) + return os.path.splitext(os.path.basename(name))[0] + + def _prepare(self, highlight): + res = highlight.strip() + res = res + '.' if res and res[-1] not in ('.', '!', '?') else res + res = res[0].upper() + res[1:] + return res + + def _write(self, name, highlight): + with open(name + ".txt", "a+") as record: + record.write(highlight) + record.write("\n\n") + + def process(self): + for entry in self.data: + name = os.path.basename(entry[1].split("!!")[0]) + name = self._sanitize(name) + highlight = self._prepare(entry[0]) + + self._write(name, highlight) + +if __name__ == "__main__": + desc = "noto: extract highlights from Kobo e-reader data store" + parser = argparse.ArgumentParser(description=desc) + parser.add_argument("--path", dest="path", type=str, action="store", + help="path to KoboReader.sqlite database", + required=True) + args = parser.parse_args() + + noto = Noto(args.path) + noto.process() |