Skip to content

fix: update anki api#14

Merged
sysid merged 1 commit intosysid:mainfrom
juanolon:main
May 30, 2024
Merged

fix: update anki api#14
sysid merged 1 commit intosysid:mainfrom
juanolon:main

Conversation

@juanolon
Copy link
Copy Markdown
Contributor

This fixes some api changes and make the tool functional again. currently using the last Anki version:

Version ⁨24.04.1 (ccd9ca1a)⁩
Python 3.11.6 Qt 6.7.0 PyQt 6.7.0

It still show a warning, because collection.sync_collection is being called in the main thread (see https://forums.ankiweb.net/t/unable-to-sync-login-via-anki-python-pkg-to-ankiw)

:: Getting changes from AnkiWeb...
blocked main thread for 1191ms:
  File "/home/juanolon/.pyenv/versions/3.11.6/bin/inka2", line 8, in <module>
    sys.exit(cli())
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/inka2/cli.py", line 556, in collect
    sync(anki_api)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/inka2/cli.py", line 163, in sync
    anki_api.sync()
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/inka2/models/anki_api.py", line 73, in sync
    self._collection.sync_collection(auth, sync_media)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anki/collection.py", line 1111, in sync_collection
    return self._backend.sync_collection(auth=auth, sync_media=sync_media)
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anki/_backend_generated.py", line 103, in sync_collection
    raw_bytes = self._run_command(1, 5, message.SerializeToString())
  File "/home/juanolon/.pyenv/versions/3.11.6/lib/python3.11/site-packages/anki/_backend.py", line 169, in _run_command
    print("".join(traceback.format_stack()))

@sysid
Copy link
Copy Markdown
Owner

sysid commented May 28, 2024

Thank you @juanolon for this contribution, much appreciated !

However, since I am not using Anki sync I am not sure what exactly your changes are effecting. It sounds like inka2 is broken for you?

Would you mind describing why your proposed changes are relevant and how they can be tested. Ideally you could even provide some tests for it. Thank you!

BTW the link you provided gives me: "Oops! That page doesn’t exist or is private."

@juanolon
Copy link
Copy Markdown
Contributor Author

Yes, it was broken. I just install the current Anki client for linux (version in the previous comment) and tried inka2. It didn't run at all, as the python api of Anki apparently changed. You can see in the diff, the changes are more about the modules used:

For example, anki.collection.NoteId doesn't exist any more, and now is anki.notes.NoteId (https://github.com/ankitects/anki/blob/24.04.1/pylib/anki/notes.py#L25). Also, the sync_collection function signature have been changed (https://github.com/ankitects/anki/blob/24.04.1/pylib/anki/collection.py#L1110).

The warning i get about the main thread (https://github.com/ankitects/anki/blob/4ab0db3127af8508317f84174aff9d20faedc41a/pylib/anki/_backend.py#L166) may be also related to the new code? (i see, it was introduced in December: ankitects/anki@6b3381a).

Oh i see, i had a typo in the url. here it is: https://forums.ankiweb.net/t/unable-to-sync-login-via-anki-python-pkg-to-ankiweb/43092

@codecov-commenter
Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@sysid sysid merged commit e8f5a16 into sysid:main May 30, 2024
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.

3 participants