Skip to content

Update Note attributes and fetch pinyin from MDBG#3

Draft
SamtoonChateaPro wants to merge 2 commits into
cadnza:masterfrom
SamtoonChateaPro:Hotfix/Replace-obsolete-Note-attributes
Draft

Update Note attributes and fetch pinyin from MDBG#3
SamtoonChateaPro wants to merge 2 commits into
cadnza:masterfrom
SamtoonChateaPro:Hotfix/Replace-obsolete-Note-attributes

Conversation

@SamtoonChateaPro
Copy link
Copy Markdown

*Replace obsolete Note attributes to maintain compatibility with the current version of Anki.
*Switch from using Wiktionary to MDBG for fetching pinyin due to access restrictions on Wikimedia resources.

The Note class no longer has a '_model' attribute. The 'note_type()' method
achieves the same functionality and allows the addon to remain compatible
with the current version of Anki.
Wikimedia has restricted the access for web crawlers to fetch data from
their resources. MDBG remains as a free alternative for fetching pinyin
for Chinese characters.
@cadnza
Copy link
Copy Markdown
Owner

cadnza commented Dec 28, 2025

@SamtoonChateaPro Thanks for putting in this PR--I've had ±0 time to work on this over the last few years 😂 It's been a really long time since I've used Anki, so I'll ask you: in your testing, does this sort #2?

@SamtoonChateaPro
Copy link
Copy Markdown
Author

@SamtoonChateaPro Thanks for putting in this PR--I've had ±0 time to work on this over the last few years 😂 It's been a really long time since I've used Anki, so I'll ask you: in your testing, does this sort #2?

Hey! Thanks for the quick reply and thanks for ever coming up with this awesome idea of a project! And yeah, when I discovered this addon last night and found out that your last reply was years ago but you still were active with other projects, I supposed you must've been busy with other projects. I even didn't have much hope for you to even check the PR, but the fact that you did and this fast really means a lot.
Regarding the issue, yes, it should work. To be blatantly honest this is my first time checking the code of an Anki Addon or even Anki, and my experience with Python is fairly basic, but as soon as I read the error that came up to me I supposed it probably had something to do with the versions of Anki. When I checked the Note class from the notes, I confirmed that the attribute "_model" effectively doesn't exist anymore. There's a "model" attribute, but it threw another error when I tried to use it. Copilot (which to be fair is the true hero here) analyzed the class and pointed out that the "note_type()" method or the "_note_type" attribute might be the dictionaries we were looking for. I tried with the method and it worked! Now I've been fidgetting a bit with the code to make it more in line with my particular templates, but all the tests, at least regarding that line, have been succesful.
Again, Wiktionary seems to have restricted the access to web scraping since you developed this, as an almost empty page with little but this link is all we get from the BeautifulSoup. I looked for other dictionaries but almost all seemed to have similar restrictions, except for mdbg, so I used it as replacement.
The audio and character auto-completion features weren't tested, as I don't have an API Key for Forvo (it's paid) and I personally begin my chinese notes writing the characters, respectively.

@cadnza
Copy link
Copy Markdown
Owner

cadnza commented Dec 28, 2025

Looks good! Okay, feel free to merge it in whenever it's in a ready state (unless I have to pull the trigger, in which case just let me know)

@SamtoonChateaPro SamtoonChateaPro marked this pull request as draft December 29, 2025 02:46
@SamtoonChateaPro
Copy link
Copy Markdown
Author

Looks good! Okay, feel free to merge it in whenever it's in a ready state (unless I have to pull the trigger, in which case just let me know)

Now that you mention it, I guess I could apply some optimizations I did to prevent the functions from running when there is already something in the fields or the chinese characters field is empty, but first, would it be ok if I commented out this line?
Captura de pantalla 2025-12-28 214537
I'm not sure if you still remember why you applied that regex 😆 , but as of right now it substracts even the components, which are the ones inserted at the animations field, causing it to refresh the gifs on every unfocus event and overall slowing down the application innecessarily.

PS: And yes, you do need to authorize it, so as soon as you approve this I'll push one last commit and let you know to make the merge.

@SamtoonChateaPro
Copy link
Copy Markdown
Author

Also, I could replace the insert_char source from Wiktionary to MDBG as well, but I'm still not convinced of it's practicality. Take for example the pinyin syllable "tang2": if I search it on MDBG, these are the first entries:
image
As you can see, knowing what characters to pick could be a problem here.
Of course, the same could be said about a character having more than one pronunciation, but these are far fewer and have fewer variations in comparison of the number of characters that share the same pinyin.

@cadnza
Copy link
Copy Markdown
Owner

cadnza commented Dec 30, 2025

would it be ok if I commented out this line?

Yeah that can go for now. I wrote all this as a first foray into Python myself, and I'm not convinced my regex proficiency was that good either :-D

Regarding the MDBG issue--you're right, that gets difficult. I wonder how you'd feel about implementing some way to choose?

@SamtoonChateaPro
Copy link
Copy Markdown
Author

would it be ok if I commented out this line?

Yeah that can go for now. I wrote all this as a first foray into Python myself, and I'm not convinced my regex proficiency was that good either :-D

Regarding the MDBG issue--you're right, that gets difficult. I wonder how you'd feel about implementing some way to choose?

Well, the only way I can think of would require some sort of interface or window. That would take me quite some time tho, as I would need to have a better understanding of Anki's code and events to implement it. For the time being, in order to revive this addon ASAP, what about adding a new configurable field to allow the user to choose if they wish to fetch the metadata from the hanzi, from the pinyin or from both? We could then add a warning on the Addons page indicating that in case MDBG got multiple results from the hanzi or the pinyin input, it will fill the fields with the metadata from the first result.

@cadnza
Copy link
Copy Markdown
Owner

cadnza commented Jan 17, 2026

Okay just getting back to this—I had a lot more time for this over Christmas :-D

Honestly putting in some kind of configuration variable would probably fine; no need to put in a full-blown UI to choose (also I'm not sure Anki even lets you spawn a custom UI). And in interest of simplicity, it'd probably be fine to just set a default and then add configuration instructions to the readme if you'd like 🤷‍♂️

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