mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
incremental exporting of all notes
This commit is contained in:
parent
3b1e05bb7f
commit
6a9adbacca
@ -1,6 +1,7 @@
|
|||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
local LoginDialog = require("ui/widget/logindialog")
|
local LoginDialog = require("ui/widget/logindialog")
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
|
local DocSettings = require("docsettings")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local Screen = require("ui/screen")
|
local Screen = require("ui/screen")
|
||||||
local Event = require("ui/event")
|
local Event = require("ui/event")
|
||||||
@ -33,6 +34,7 @@ function EvernoteExporter:init()
|
|||||||
history_dir = "./history",
|
history_dir = "./history",
|
||||||
}
|
}
|
||||||
self.template = slt2.loadfile(self.path.."/note.tpl")
|
self.template = slt2.loadfile(self.path.."/note.tpl")
|
||||||
|
self.config = DocSettings:open(self.path)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EvernoteExporter:addToMainMenu(tab_item_table)
|
function EvernoteExporter:addToMainMenu(tab_item_table)
|
||||||
@ -230,6 +232,24 @@ function EvernoteExporter:exportCurrentNotes(view)
|
|||||||
self:exportClippings(client, clippings)
|
self:exportClippings(client, clippings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function EvernoteExporter:updateClippings(clippings, new_clippings)
|
||||||
|
for title, booknotes in pairs(new_clippings) do
|
||||||
|
for chapter_index, chapternotes in ipairs(booknotes) do
|
||||||
|
for note_index, note in ipairs(chapternotes) do
|
||||||
|
if clippings[title] == nil or clippings[title][chapter_index] == nil
|
||||||
|
or clippings[title][chapter_index][note_index] == nil
|
||||||
|
or clippings[title][chapter_index][note_index].page ~= note.page
|
||||||
|
or clippings[title][chapter_index][note_index].time ~= note.time
|
||||||
|
or clippings[title][chapter_index][note_index].text ~= note.text
|
||||||
|
or clippings[title][chapter_index][note_index].note ~= note.note then
|
||||||
|
clippings[title] = booknotes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return clippings
|
||||||
|
end
|
||||||
|
|
||||||
function EvernoteExporter:exportAllNotes()
|
function EvernoteExporter:exportAllNotes()
|
||||||
local EvernoteClient = require("EvernoteClient")
|
local EvernoteClient = require("EvernoteClient")
|
||||||
local client = EvernoteClient:new{
|
local client = EvernoteClient:new{
|
||||||
@ -237,10 +257,9 @@ function EvernoteExporter:exportAllNotes()
|
|||||||
authToken = self.evernote_token,
|
authToken = self.evernote_token,
|
||||||
}
|
}
|
||||||
|
|
||||||
local clippings = self.parser:parseMyClippings()
|
local clippings = self.config:readSetting("clippings") or {}
|
||||||
if next(clippings) == nil then
|
clippings = self:updateClippings(clippings, self.parser:parseMyClippings())
|
||||||
clippings = self.parser:parseHistory()
|
clippings = self:updateClippings(clippings, self.parser:parseHistory())
|
||||||
end
|
|
||||||
-- remove blank entries
|
-- remove blank entries
|
||||||
for title, booknotes in pairs(clippings) do
|
for title, booknotes in pairs(clippings) do
|
||||||
-- chapter number is zero
|
-- chapter number is zero
|
||||||
@ -250,45 +269,52 @@ function EvernoteExporter:exportAllNotes()
|
|||||||
end
|
end
|
||||||
--DEBUG("clippings", clippings)
|
--DEBUG("clippings", clippings)
|
||||||
self:exportClippings(client, clippings)
|
self:exportClippings(client, clippings)
|
||||||
|
self.config:saveSetting("clippings", clippings)
|
||||||
|
self.config:flush()
|
||||||
end
|
end
|
||||||
|
|
||||||
function EvernoteExporter:exportClippings(client, clippings)
|
function EvernoteExporter:exportClippings(client, clippings)
|
||||||
local export_count, error_count = 0, 0
|
local export_count, error_count = 0, 0
|
||||||
local export_title, error_title
|
local export_title, error_title
|
||||||
for title, booknotes in pairs(clippings) do
|
for title, booknotes in pairs(clippings) do
|
||||||
local ok, err = pcall(self.exportBooknotes, self, client, title, booknotes)
|
-- skip exported booknotes
|
||||||
|
if booknotes.exported ~= true then
|
||||||
-- error reporting
|
local ok, err = pcall(self.exportBooknotes, self,
|
||||||
if not ok then
|
client, title, booknotes)
|
||||||
DEBUG("Error occurs when exporting book:", title, err)
|
-- error reporting
|
||||||
error_count = error_count + 1
|
if not ok then
|
||||||
error_title = title
|
DEBUG("Error occurs when exporting book:", title, err)
|
||||||
|
error_count = error_count + 1
|
||||||
|
error_title = title
|
||||||
|
else
|
||||||
|
DEBUG("Exported notes in book:", title)
|
||||||
|
export_count = export_count + 1
|
||||||
|
export_title = title
|
||||||
|
booknotes.exported = true
|
||||||
|
end
|
||||||
else
|
else
|
||||||
DEBUG("Exported notes in book:", title)
|
DEBUG("Skip exporting notes in book:", title)
|
||||||
export_count = export_count + 1
|
|
||||||
export_title = title
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local msg = ""
|
local msg = "Not exported anything."
|
||||||
local all_count = export_count + error_count
|
local all_count = export_count + error_count
|
||||||
if export_count > 0 and error_count == 0 then
|
if export_count > 0 and error_count == 0 then
|
||||||
if all_count == 1 then
|
if all_count == 1 then
|
||||||
msg = _("Exported notes in book:") .. "\n" .. export_title
|
msg = _("Exported notes in book:") .. "\n" .. export_title
|
||||||
else
|
else
|
||||||
msg = _("Exported notes in book:") .. "\n" .. export_title
|
msg = _("Exported notes in book:") .. "\n" .. export_title
|
||||||
msg = msg .. "\n" .. _("and ") .. all_count-1 .. _("others.")
|
msg = msg .. "\n" .. _("and ") .. all_count-1 .. _(" others.")
|
||||||
end
|
end
|
||||||
elseif error_count > 0 then
|
elseif error_count > 0 then
|
||||||
if all_count == 1 then
|
if all_count == 1 then
|
||||||
msg = _("Error occurs when exporting book:") .. "\n" .. error_title
|
msg = _("Error occurs when exporting book:") .. "\n" .. error_title
|
||||||
else
|
else
|
||||||
msg = _("Errors occur when exporting book:") .. "\n" .. error_title
|
msg = _("Errors occur when exporting book:") .. "\n" .. error_title
|
||||||
msg = msg .. "\n" .. _("and ") .. error_count-1 .. ("others.")
|
msg = msg .. "\n" .. _("and ") .. error_count-1 .. (" others.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
UIManager:show(InfoMessage:new{ text = msg })
|
UIManager:show(InfoMessage:new{ text = msg })
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function EvernoteExporter:exportBooknotes(client, title, booknotes)
|
function EvernoteExporter:exportBooknotes(client, title, booknotes)
|
||||||
|
Loading…
Reference in New Issue
Block a user