diff --git a/ReadMe.md b/ReadMe.md index 1f3714a..7764919 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,15 +2,16 @@ CLI tracker to prioritize your limited time by ELO ranking media. ## Initial Ideas -- [ ] Mark books read/unread/in-progress. +- [x] Mark books read/unread/in-progress. - [x] Show top 10 / bottom 10. Show only in-progress or unread. - [ ] Rank only in-progress or unread. - [x] Track books by title, author, and series. Default is to recognize "by" or "(series)" and automatically sort into relevant fields. - [x] But also almost nothing is actually *needed*. -- [x] Store progress as a numerical value? (Unread = 0, read = 1, in-progress in-between? Too easy to forget how it works?) - [x] Store pages as an option, - - [ ] allow a weighted priority based on remaining percentage or whatever. + - [x] allow a weighted priority based on remaining percentage or whatever. - [x] Store items as an array instead of object, because that makes the JSON output more consistent -> smaller JSON commit differences. + - [ ] I am not sure this actually helps much when EACH ITEM is still an + object. I need to make the JSON export sort its keys. - [ ] Re-implement ELO ranking. - [ ] Display filter/sort options to output lists. (Focus only on top 10 items?) @@ -22,6 +23,12 @@ I accept pull requests and issues, but management of the code is handled there. Licensing? I don't care. Do whatever you want. IP rights are stupid. +## Ideas +- [ ] When importing, allow user to make a choice when duplicates are detected + instead of rejecting them automatically. +- [ ] When importing, a duplicate should still be checked for missing data, and + merge rather than ignore. + ## Book Data Structure ```json { diff --git a/asymptome.lua b/asymptome.lua index f03abdf..e4e85c0 100755 --- a/asymptome.lua +++ b/asymptome.lua @@ -249,14 +249,35 @@ local update_book = function(book) return update_progress_prompt(book) end +local book_exists = function(data, book) + for i = 1, #data.books do + local current = data.books[i] + if not (book.title == current.title) then + break + end + if not (book.author == current.author) then + break + end + if not (book.series == current.series) then + break + end + if not (book.genre == current.genre) then + break + end + return current -- we return the object instead of true so it can be updated if desired + end + return false +end + local import_json = function(data, file_name) import = load_json(file_name) if import.books then for i = 1, #import.books do - data.books[#data.books + 1] = import.books[i] - -- TODO detect and ignore duplicates (would be better to provide user an option for what to do with duplicates) - -- default should accept highest progress of duplicates? + -- TODO allow updating metadata instead of just ignoring + if not book_exists(data, import.books[i]) then + data.books[#data.books + 1] = import.books[i] + end end else -- assume we are importing from decider.lua's format @@ -292,8 +313,10 @@ local import_json = function(data, file_name) end end - -- TODO detect duplicates before adding them - data.books[#data.books + 1] = book + -- TODO allow updating metadata (this and the above need to be split into its own function) + if not book_exists(data, book) then + data.books[#data.books + 1] = book + end end run() end