Created
September 22, 2022 03:30
-
-
Save SebTota/62a48b8c76ab7e78aaf450de47e4003c to your computer and use it in GitHub Desktop.
DuoLingo Vocabulary Puller For Quizlet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Generate a comma separated list of your DuiLingo vocabulary words and translations to create | |
flashcards in Quizlet. | |
Command: `python3 main.py -u <username> -p <password> -sl <source-language> -tl <target-language>` | |
Ex: `python3 main.py -u Seb001 -p 'SuperStrongPassword1' -sl de -tl en` | |
''' | |
import argparse | |
from typing import Optional | |
import duolingo | |
class DuoLingoVocabGrabber(): | |
def __init__(self, username: str, password: str): | |
self.duo = duolingo.Duolingo(username, password) | |
def get_quizlet_string(self): | |
s = '' | |
for k, v in self.vocab_words.items(): | |
s += f'{k},{", ".join(v)};' | |
return s | |
def set_vocabulary(self, source_lang: str, target_lang: str) -> None: | |
self.vocab_words = {} # Clear vocab dict | |
vocab_response = self.duo.get_vocabulary(language_abbr=source_lang)['vocab_overview'] | |
# Have to capitalize the words or else they wont return a response | |
words = [word['word_string'].capitalize() for word in vocab_response] | |
self.vocab_words = dict(self.duo.get_translations(words, source=source_lang, target=target_lang)) | |
words = [] | |
# If no translation was found for certain words, try the lowercase version of the word | |
words_with_no_translations = [k.lower() for k, v in self.vocab_words.items() if len(v) <= 0] | |
vocab_words_temp = dict(self.duo.get_translations(words_with_no_translations, source=source_lang, target=target_lang)) | |
for k, v in vocab_words_temp.items(): | |
self.vocab_words[k.capitalize()] = v | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Process some integers.') | |
parser.add_argument('-u', '--username', help='DuoLingo username', required=True) | |
parser.add_argument('-p', '--password', help='DuoLingo password', required=True) | |
parser.add_argument('-sl', '--source-language', help='The source (learning) language abbreviation', required=True) | |
parser.add_argument('-tl', '--target-language', help='The target (translated) language', required=True) | |
args = vars(parser.parse_args()) | |
d = DuoLingoVocabGrabber(args['username'], args['password']) | |
d.set_vocabulary(args['source_language'], args['target_language']) | |
print(d.get_quizlet_string()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
certifi==2022.9.14 | |
charset-normalizer==2.1.1 | |
duolingo-api==0.5.4 | |
idna==3.4 | |
requests==2.28.1 | |
urllib3==1.26.12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment