Created
October 17, 2021 17:53
-
-
Save bemitc/9704e3db75f6398ba602f0633646726b to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
import duolingo | |
import json | |
import csv | |
import time | |
csvfile = open("duolingo_import.csv", "w") | |
duolingo_csv = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL) | |
lingo = duolingo.Duolingo('myname', ...) | |
vocab = lingo.get_vocabulary(language_abbr='es') | |
vocab = vocab["vocab_overview"] | |
v = vocab[0] | |
f=open('lexeme.ids') | |
ids = [line.rstrip('\n') for line in f.readlines()] | |
f.close() | |
for v in vocab: | |
lexeme = v["lexeme_id"] | |
if lexeme not in ids: | |
print("processing new lexeme {}".format(lexeme)) | |
dictionarypage_url = "https://www.duolingo.com/api/1/dictionary_page?lexeme_id={}&from_language_id=en".format(lexeme) | |
get = lingo._make_req(dictionarypage_url) | |
d = get.json() | |
d = d["alternative_forms"] | |
for sent in d: | |
duolingo_csv.writerow([sent["text"], sent["translation_text"], "[sound:" + sent["tts"] + "]"]) | |
with open('lexeme.ids', 'a') as f: | |
f.write(lexeme + "\n") | |
time.sleep(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment