aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2023-01-27 15:08:22 -0700
committerJordan <me@jordan.im>2023-01-27 15:08:22 -0700
commit22c5defd229e20376bd8949bd5806d6794838337 (patch)
tree7a351cad23369705a3ba9eac26b81e11eda9ac9b
downloadnoto-22c5defd229e20376bd8949bd5806d6794838337.tar.gz
noto-22c5defd229e20376bd8949bd5806d6794838337.zip
initial commitHEADmaster
-rw-r--r--.gitignore2
-rw-r--r--README7
-rw-r--r--UNLICENSE24
-rwxr-xr-xnoto.py58
4 files changed, 91 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3819313
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+*.swo
diff --git a/README b/README
new file mode 100644
index 0000000..b9a5f3b
--- /dev/null
+++ b/README
@@ -0,0 +1,7 @@
+usage: noto.py [-h] --path PATH
+
+noto: extract highlights from Kobo e-reader data store
+
+options:
+ -h, --help show this help message and exit
+ --path PATH path to KoboReader.sqlite database
diff --git a/UNLICENSE b/UNLICENSE
new file mode 100644
index 0000000..68a49da
--- /dev/null
+++ b/UNLICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <http://unlicense.org/>
diff --git a/noto.py b/noto.py
new file mode 100755
index 0000000..605df62
--- /dev/null
+++ b/noto.py
@@ -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()