-
Notifications
You must be signed in to change notification settings - Fork 14
Importing Anki Decks #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
drillsrs/cmd/import_.py
Outdated
| q = etree.HTML(s[0]) | ||
| card["question"] = etree.tostring(q, encoding='unicode', method='text') | ||
| a = etree.HTML(s[1]) | ||
| card["answers"] = [" "] if a is None else [etree.tostring(a, encoding='unicode', method='text')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some time when tranformaing answer from html to plain text it return none and lxml etree give me
TypeError: Type 'NoneType' cannot be serialized.
so i left as empty answer for now
I need to find better solution
drillsrs/cmd/import_.py
Outdated
| x = {"name":temp[1][3], "description":None, "tags":[], "cards":[]} | ||
| counter = 1 | ||
| for s in temp[1:]: | ||
| card = {"active":False,"activation_date":None,"tags":[],"user_answers":[]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad formatting, no spaces after :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, Fixed it
drillsrs/cmd/import_.py
Outdated
| from typing import IO, Any, Optional | ||
|
|
||
| from dateutil.parser import parse as parse_date | ||
| from anki_export import ApkgReader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this package to be optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now Optional and also lxml package since it's only used in there
drillsrs/cmd/import_.py
Outdated
| help="path to import from; if omitted, standard input is used", | ||
| ) | ||
| parser.add_argument( | ||
| "-a", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--anki
drillsrs/cmd/import_.py
Outdated
|
|
||
| def run(self, args: argparse.Namespace) -> None: | ||
| path: Optional[str] = args.path | ||
| anki: Optional[bool] = args.a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding --anki above you can now refer to this option as args.anki which is more readable
drillsrs/cmd/import_.py
Outdated
| with ApkgReader(filepath) as apkg: | ||
| temp = apkg.export() | ||
| temp = temp[list(temp)[0]] | ||
| x = {"name": temp[1][3], "description": None, "tags": [], "cards": []} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name this variable ret
drillsrs/cmd/import_.py
Outdated
| temp = apkg.export() | ||
| temp = temp[list(temp)[0]] | ||
| x = {"name": temp[1][3], "description": None, "tags": [], "cards": []} | ||
| counter = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do without counter at all by using for counter, s in enumerate(temp[1:]):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's all done now
if there anything else can be imporved please tell me
rr-
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LMK if you want to do anything about that space
Basic Support for Importing apkg Anki Deck files
still having some problems like
sometime when trying to get plain text from html i get None so for now when it happen i put empty string but i will try to solve it soon (it happened very few times with me)