Skip to content
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

Importing Anki Decks #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

alhassanaraouf
Copy link

@alhassanaraouf alhassanaraouf commented Sep 13, 2020

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)

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')]
Copy link
Owner

Choose a reason for hiding this comment

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

Why a space?

Copy link
Author

@alhassanaraouf alhassanaraouf Sep 13, 2020

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

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":[]}
Copy link
Owner

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 :

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, Fixed it

from typing import IO, Any, Optional

from dateutil.parser import parse as parse_date
from anki_export import ApkgReader
Copy link
Owner

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

Copy link
Author

@alhassanaraouf alhassanaraouf Sep 14, 2020

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

@@ -70,11 +106,21 @@ def decorate_arg_parser(self, parser: argparse.ArgumentParser) -> None:
nargs="?",
help="path to import from; if omitted, standard input is used",
)
parser.add_argument(
"-a",
Copy link
Owner

Choose a reason for hiding this comment

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

--anki


def run(self, args: argparse.Namespace) -> None:
path: Optional[str] = args.path
anki: Optional[bool] = args.a
Copy link
Owner

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

with ApkgReader(filepath) as apkg:
temp = apkg.export()
temp = temp[list(temp)[0]]
x = {"name": temp[1][3], "description": None, "tags": [], "cards": []}
Copy link
Owner

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

temp = apkg.export()
temp = temp[list(temp)[0]]
x = {"name": temp[1][3], "description": None, "tags": [], "cards": []}
counter = 1
Copy link
Owner

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:]):

Copy link
Author

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

Copy link
Owner

@rr- rr- left a 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

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