aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2020-08-16 17:44:16 -0300
committerSilvio Rhatto <rhatto@riseup.net>2020-08-16 17:44:16 -0300
commit8d7d159f010b796a830de551a851347eaae7ed0c (patch)
tree743216ed8a63d53fca0c2ed4568065a5060d482f
parent7dbaa53d8ba084ceee5339baea20f1b73f0d1440 (diff)
downloadscripts-8d7d159f010b796a830de551a851347eaae7ed0c.tar.gz
scripts-8d7d159f010b796a830de551a851347eaae7ed0c.tar.bz2
Adds export-koreader-note
-rwxr-xr-xexport-koreader-note46
1 files changed, 46 insertions, 0 deletions
diff --git a/export-koreader-note b/export-koreader-note
new file mode 100755
index 0000000..ae2e0ef
--- /dev/null
+++ b/export-koreader-note
@@ -0,0 +1,46 @@
+#!/usr/bin/env lua
+--
+-- Convert koreader metadata to markdown.
+--
+
+-- Sort by page number
+function compare(a, b)
+ return a.page < b.page
+end
+
+-- Check if a file exists
+-- Thanks https://stackoverflow.com/questions/4990990/check-if-a-file-exists-with-lua#4991602
+function file_exists(name)
+ local f=io.open(name,"r")
+ if f~=nil then io.close(f) return true else return false end
+end
+
+-- Get filename
+file = arg[1]
+
+-- Usage
+if file == nil then
+ print('usage: ' .. arg[0] .. ' <filename>')
+ os.exit(1)
+else
+ if not file_exists(file) then
+ print('file not found: ' .. file)
+ os.exit(1)
+ end
+end
+
+-- Load metadata
+content = assert(loadfile(file))
+data = content()
+bookmarks = data.bookmarks
+
+-- Sort
+table.sort(bookmarks, compare)
+
+-- Iterate over bookmarks
+for key, item in ipairs(bookmarks) do
+ print('Page ' .. item.page .. ':')
+ print('')
+ print('> ' .. item.notes)
+ print('')
+end