Skip to content

Minor changes - #5

Open
tkrajina wants to merge 5 commits into
flimzy:masterfrom
tkrajina:master
Open

Minor changes#5
tkrajina wants to merge 5 commits into
flimzy:masterfrom
tkrajina:master

Conversation

@tkrajina

Copy link
Copy Markdown

This pull request contains 3 minor changes.

  • Added functions Collections(), Notes() and Cards() are now originally on DB, and the original functions at Apkg are just calling them. The desktop client keeps everything in the database, not in .apkg files and this allows for reading (and eventually manipulating) data directly.
  • exposes the "\x1f" delimiter
  • added a function that allows opening the original database, not a temporary clone (OpenOriginalDB()).

@flimzy flimzy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. This looks promising. I guess the goal is to read Anki collections straight from disk, without the intermediate Export step?

Do you have plans to read files (sounds, images, etc) from disk as well?

Let me know your plans, and if I should consider merging this soon, or after some additional changes.

Aside from that, I've left a couple of inline comments.

Thanks for contributing.

Comment thread sqlite-std.go
}
conf, ok := collection.DeckConfigs[deck.ConfigID]
if !ok {
//return nil, fmt.Errorf("Deck %d references non-existent config %d", deck.ID, deck.ConfigID)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line got commented out during the code move. Was this intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uops. Yes, you're right. The problem is that in one of my local Anki profiles I had a situation where there was no dek for that deck.ConfigID. I don't know how big a problem that incosistency is, but both the desktop Anki client and Ankidroid ignore this feature.

I tried now and it it's not the case any more. I suppose it's probably something left after I removed a deck and it was probably not cleaned immediately but later, after I run the "check database" desktop client.

I'm removing it for now, but if it happens again, I'll investigate more.

Comment thread sqlite-std.go
tmpFile string
}

func (db *DB) Collection() (*Collection, error) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest putting these new *DB methods in a new file, sqlite.go, with no build constraints. By putting them here, they are not available for GopherJS builds (thus the Travis-CI failure).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, thanks. I'll update my pull request later.

@tkrajina tkrajina Sep 23, 2017

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update, I found the situation again.

Deck 1446489859874 references non-existent config 0

Both the AnkiDroid and desktop app work without problems with this collection, so this isn't an error. Maybe just write a warning in stderr instead of returning an error here?

PS. Commented on a wrong code line, this was for the place where I commented the error when a deck isn't found by id.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that means that a default configuration is used in such a case?

Warning to sterr seems reasonable to me.

@tkrajina

Copy link
Copy Markdown
Author

Hey, thanks for your feedback.

So, I have two small side project which both need to read one mf my anki decks. But don't have the .apkg files, I'm reading directly from the files the desktop Anki app uses (in  ~/Library/Application Support/Anki2/ProfileName). The database there is just a file, not zipped in an .apkg/zip archive. And that's why I needed a possibility to open the database directly.

Ideally, the library would work regardless if you open an .apkg file or the extracted directory, but after looking at the code I realised it would be simpler to just add those helper methods in *Db.

For files. No, I don't have plans to read files, but I do add audio files to my decks. An API for doing that would be cool, but I got it to work even without that.

BTW, You can see here how it works. Remember, this is just a quick weekend project and the code is not really high quality, but it works :)

@tkrajina

tkrajina commented Sep 23, 2017

Copy link
Copy Markdown
Author

Ah, and one more thing. I have a plan to create another small open source tool which will allow me to:

  • extract the cards from a deck to a github repository (probably a json or a yml file)
  • create a LaTeX/PDF/README document from all the decks. Specifically, I want to create a downloadable dictionary from words in my Anki Deck.
  • allow users to edit the list in the github repository, send the changes as pull requests, and the tool should sync those changes back to the deck.

So, I'll probably need a better way to edit notes. As you can see in the code I already succeeded in doing it (although the code is still very ugly), but a simpler API for doing it would be a nice addition. What do you think?

PS. Thanks for your great work on the library!

@flimzy

flimzy commented Sep 23, 2017

Copy link
Copy Markdown
Owner

I have a plan to create another small open source tool which will allow me to:

That sounds like a very interesting project... good luck! I'd love to see the finished product.

PS. Thanks for your great work on the library!

No problem; I'm glad someone else found it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants