Yvee1/hascard

Add support to pull questions from quizlet

Closed this issue · 6 comments

g-w1 commented

Hi,
Thanks for the awesome software. Software that I have used like this is studyflash. One thing that I really liked is that it could import questions from quizlet. Since professors sometimes make me write quizlet sets, it is good that I can import them. I think that it is really easy to do it. If you are familiar with python this file is how they do it.

import urllib
import json
def cardsFromQuizlet(self, link, path):
    print(link)
    r = urllib.request.Request(
        url=link,
        headers={
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'
        }
    )
    html = str(urllib.request.urlopen(r).read().decode("utf-8"))
    find1String = "window.Quizlet[\"setPageData\"] = "
    found1 = html.find(find1String)
    html = html[found1 + len(find1String):]
    found2 = html.find("; QLoad(\"Quizlet.setPageData\");")
    html = html[:found2]

    jsonData = json.loads(html)
    return jsonData

in this file https://raw.githubusercontent.com/Alone2/studyFlash/master/scripts/studyflash-quizlet. it seems like they just scrape json off the webpage. There is no need for a html parser, just a json parser. It seems like haskell has a good json parser so this should be fairly easy to impliment.

Thanks

Yvee1 commented

Hello, thanks for the suggestion. Studyflash looks pretty cool, fun to see how others approached it.

I agree that it would be nice to be able to import sets from other places. I've briefly tried doing the same scraping in Haskell as what studyflash does in Python, but without success: I get a HTTP response with a Captcha that needs to be filled in. Perhaps with some more effort I could get it working, but I also don't think that this is the best way to import from Quizlet, since it's a bit hacky. I saw Quizlet has a build-in export function if you're logged in though, so we might as well utilize that.

So I'm thinking of adding a way to convert csv-like files to files compatible with hascard. Something like

hascard import INPUT OUTPUT

which makes a new file OUTPUT.txt from the input file, with the converted syntax. People may want to convert to either definition or open question cards so additionally an option -o, --open would make it an open question card and the default would be a definition card.

What do you think, would this solve your problem?

g-w1 commented

Yes. Thank you. I think quizlet has different options to export it, and the default is not a comma, so it would be good to specify how someone should import it.
image

Yvee1 commented

Yeah that should indeed be made clear. Since commas, backslashes and semicolons can be used in Quizlet to signify that multiple answers are correct, it would be easiest to not use them as delimiters I think. But I'll see when implementing it.

(Adding this functionality requires some restructuring; the CLI currently interprets hascard import ... as reviewing a file called import, but import (or convert, not sure on the name yet) should be made a separate command. I'm thinking of then moving the current functionality, of directly providing files to the application, under another command like run or review. For handling the options it's then also better separate the UI and the CLI, so that shuffling, chunking etc. can be specified in the UI and the CLI options only work under the run command.)

Anyways, this means that it might take a little while until I manage to find the time to implement the above things such that the import feature is available.

g-w1 commented

Ok. Thanks!

Yvee1 commented

This should work now in version 0.4.0.0! The exporting from Quizlet should be done with the default options, so a tab between term and definition, and a new line between rows. Then you can copy the text to a file input.txt and then run hascard import input.txt output.txt. This creates a file output.txt with the converted syntax.

Let me know if this works for you

g-w1 commented

Yes! Thanks so much! I will be contributing to this project in the future. Closing.