KartikTalwar / Duolingo

Unofficial Duolingo API Written in Python
MIT License
826 stars 128 forks source link

This only works for the current language #9

Closed jonoruss closed 9 years ago

jonoruss commented 9 years ago

I've been toying around with this, and I noticed that if I did the following:

lingo  = duolingo.Duolingo('JonRussell2')
print lingo.get_language_progress('pt')
print lingo.get_language_progress('de')

It would produce the following:

C:\Workspaces\python sandbox>python duo.py {'streak': 49, 'language_string': u'Portuguese', 'level_progress': 717, 'level_percent': 65, 'language': u'pt', 'points_rank': 3, 'level_points': 1100, 'next_level': 14, 'points': 5617, 'num_skills_learned': 40, 'level_left': 383} Traceback (most recent call last): File "duo.py", line 46, in print lingo.get_language_progress('de'); File "C:\Python27\lib\site-packages\duolingoinit.py", line 111, in get_language_progress return self._make_dict(fields, self.user_data.language_data[lang]) KeyError: 'de'

Apparently, this "get_language_progress" only gets the progress if we're logged into that language. Once I log into german, it no longer gets portuguese. It's evidently trying to parse the language JSON returned when we load the page, but that only returns one language at a time.

Since this function only gets the current language anyway, why should this take in a language as an input? Instead of this:

def get_language_progress(self, lang):
        fields = ['streak', 'language_string', 'level_progress', 'num_skills_learned',
                'level_percent', 'level_points', 'points_rank', 'next_level',
                'level_left', 'language', 'points']
        return self._make_dict(fields, self.user_data.language_data[lang])

Why not this:

def get_language_progress(self):
        language = duolingo.user_data.language_data.keys()[0]
        fields = ['streak', 'language_string', 'level_progress', 'num_skills_learned',
                'level_percent', 'level_points', 'points_rank', 'next_level',
                'level_left', 'language', 'points']
        return self._make_dict(fields, self.user_data.language_data[language])

I've tested that, and I think it works pretty well. Alternatively, is there a way to get multiple languages' data at once?

KartikTalwar commented 9 years ago

I've commited a new change to the api that allows you to login. It should resolve the language_progress issue

jonoruss commented 9 years ago

Thanks!

On Sun, May 10, 2015 at 8:44 PM Kartik Talwar notifications@github.com wrote:

Closed #9 https://github.com/KartikTalwar/Duolingo/issues/9.

— Reply to this email directly or view it on GitHub https://github.com/KartikTalwar/Duolingo/issues/9#event-301307819.