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.
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":[]} |
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.
I'd like this package to be optional
There was a problem hiding this comment.
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", |
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.
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": []} |
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.
You can do without counter at all by using for counter, s in enumerate(temp[1:]):
There was a problem hiding this comment.
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.
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)