sviatoslav-lebediev / anki-quizlet-importer-extended

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'NoneType' object is not subscriptable

kjanus9931 opened this issue · comments

Hi! Today I wanted to download one deck and I this information in the title. Below I will add every piece of information that I have in the window that opens.
I downloaded this deck yesterday and it was fine. Today I have a problem.
My Quizlet deck: https://quizlet.com/pl/686287672/kwiecien-zdania-do-nauki-flash-cards/
I reinstalled add-on but still isn;t working. Bts great work!

Below all text from errow window:

'NoneType' object is not subscriptable

and below there is code but i couldnt add it because it was too long.

I was facing the same issue, it seems that Quizlet changed the structure of JSON data.

I tried to fix it by rewriting the mapItems method and it works fine for my sets (I'm not using any rich text there, so I didn't bother with it). Use with caution, it is the first Python code I ever wrote! :-)

def mapItems(jsonData):
    studiableItems = itemgetter('studiableItems')(jsonData['studiableDocumentData'])

    result = []

    for studiableItem in studiableItems:
        #print(json.dumps(studiableItem, indent=4))
        
        termAudio = None
        definitionAudio = None
        image = None

        for side in studiableItem["cardSides"]:
            if (side["label"] == "word"):
                for media in side["media"]:
                    if media["type"] == 1:
                        term = media["plainText"]
                        if media["ttsUrl"]:
                            termAudio = media["ttsUrl"]
      

            if (side["label"] == "definition"):
                for media in side["media"]:
                    if media["type"] == 1:
                        definition = media["plainText"]
                        if media["ttsUrl"]:
                            definitionAudio = media["ttsUrl"]
          
                    if media["type"] == 2:
                        image = media["url"]
            
        result.append({
            "id": studiableItem["id"],
            "term": term,
            "termAudio": termAudio,
            "definition": definition,
            "definitionAudio": definitionAudio,
            "imageUrl": image
        })

    
    #print(json.dumps(result, indent=4))

    return result

The above code fixed for me as well!

Hi @shooter28 , @mhujer ,
would you like to tell me how I can do it, just step by step? I'm a total rookie but I'd love to fix it

Yeah, I also don't know how to implement this code so it would be amazing if you could tell us :)

@baazko @kjanus9931 Hi!

  1. You need to locate the plugin directory, for me it is Anki\AnkiData\addons21\1362209126\ (but I have custom setup with the portable data dir).
  2. There is a file called __init__.py which you need to open in Notepad++ (or similar)
  3. Next in that file you need to locate the line def mapItems(jsonData):
  4. Replace this line and all the following lines up to class QuizletDownloader(QThread): (keep that one!) with the code in the comment above

@baazko @kjanus9931

Another way to locate the add-on file is to open up Anki and click on "tools". From the drop down menu, select "add ons". When the add-ons menu pops up, click on "view files" as shown in the picture. As @mhujer said, open up the init.py file in something like Notepad. I actually cntrl+F searched for the function "def MapItems" and then completely replaced the function with the code above. After you've made the change, save the file and close it. Close Anki and then restart it, and the importer should work. Hope that helps!

ViewFiles

@shooter28 , @mhujer
Thank you so much, guys! It really works 😃

@mhujer thx, I've updated add-on.

@sviatoslav-lebediev Maybe it will need some more tweaking, because I completely ignored the rich text in my patch (as I'm not using it in my sets).

I'm not sure that I did anything with the rich text before :) will take a look.

I understand that rich text (highlighting and bolding) is still in the process of getting fixed.

Currently, I am facing an issue where the pictures merge but for cards that don't have a picture, the last card that did have a picture recycles that image on the following text only cards inserting images until the next card comes along with a different picture. This keeps going for the rest of the deck.

Not sure if I am explaining it right. Do apologize in advance. I have no idea how to fix it :(

@KashGu please provide a link for your deck otherwise I will not be able to help

@sviatoslav-lebediev Here is an example of one of mine. TIA for looking into this.

Edit: also wanted to add that I just noticed the same thing was happening with audio. For example, whenever a card has a lot of text quizlet will not do text to speech translation. So on anki that card shouldn't play any audio but it plays the audio of the previous card similar to the aforementioned image issue.

[https://quizlet.com/690496704/45-parasitic-respiratory-infections-flash-cards/]

@KashGu try to update addon, should be fixed

@sviatoslav-lebediev Just updated! Seems to have fixed both the image and audio issues from my end. Thank you so much for all the help! Appreciate it :)