Skip to content

Instantly share code, notes, and snippets.

@bemitc
Created October 17, 2021 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bemitc/9704e3db75f6398ba602f0633646726b to your computer and use it in GitHub Desktop.
Save bemitc/9704e3db75f6398ba602f0633646726b to your computer and use it in GitHub Desktop.
#!/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