Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Call to get daily XP totals for past 7 days #114

Open
saltedlolly opened this issue Feb 12, 2022 · 10 comments
Open

Request: Call to get daily XP totals for past 7 days #114

saltedlolly opened this issue Feb 12, 2022 · 10 comments

Comments

@saltedlolly
Copy link

I want to recreate the Graph that displays the XP score for the last 7 days on a Tidbyt device: https://www.tidbyt.com

Currently the API let's you get the current daily XP score for right now, but I'd really like a call that also returns the total XP achieved for each of the past 7 days. Maybe something like this:

# Sample Response
{
    'xp_1dayago': 105, 
    'xp_2daysago': 48, 
    'xp_3daysago': 207, 
    'xp_4daysago': 0, 
    'xp_5daysago': 86, 
    'xp_6daysago': 54, 
}

Would this be at all possible? Is there any way to get this data from Duolingo?

@igorskh
Copy link
Contributor

igorskh commented Feb 16, 2022

Hi @saltedlolly,

It is possible with duolingo API, but this package doesn't implement this method.

The endpoint is www.duolingo.com/users/{userID}/xp_summaries

It returns an array for the given time range, as following:

Screenshot 2022-02-16 at 10 30 31

Hope it helps.

@saltedlolly
Copy link
Author

Thanks - this is just what I have been looking for! Unfortunately, I'm struggling to make it work. Could you possibly provide me with an example query? Sorry, I'm quite new at this.

I tried https://www.duolingo.com/users/6364229/xp_summaries?startDate=2022-02-16&endDate=2022-02-17&timezone=Europe/London but got nothing.

@igorskh
Copy link
Contributor

igorskh commented Feb 18, 2022

Sorry, my bad. The URL should be https://www.duolingo.com/2017-06-30/users/6364229/xp_summaries?startDate=2022-02-16&endDate=2022-02-17&timezone=Europe/London

The 2017-06-30 is missing. It's just a fixed prefix Duolingo currently use for their API endpoint.

Example:

GET /2017-06-30/users/6364229/xp_summaries?startDate=2022-02-16&endDate=2022-02-17&timezone=Europe%2FLondon HTTP/1.1
Authorization: Bearer <your_jwt_token_here>
Content-Type: text/plain; charset=utf-8
Host: www.duolingo.com

"summaries":[{"gainedXp":87,"frozen":false,"streakExtended":true,"userId":6364229,"dailyGoalXp":50,"date":1645056000,"repaired":false},{"gainedXp":null,"frozen":true,"streakExtended":false,"userId":6364229,"dailyGoalXp":null,"date":1644969600,"repaired":false}]}

@saltedlolly
Copy link
Author

Amazing! Exactly what I needed! And even better it seems I don't even need to be authenticated. Many thanks.

@igorskh
Copy link
Contributor

igorskh commented Feb 19, 2022

You're right, it works even without Authorization header or cookies, didn't realize that before.

@saltedlolly
Copy link
Author

Thanks for all your help. As an aside, is there a query I can make to return the userid of a provided username?

@igorskh
Copy link
Contributor

igorskh commented Feb 21, 2022

Yes, there is an endpoint which returns user information by username, it contains among other fields the userID:

https://www.duolingo.com/2017-06-30/users?username=<username>

e.g.:
https://www.duolingo.com/2017-06-30/users?username= igorskh returns

{
    "users": [
        {
            "joinedClassroomIds": [],
            "streak": 1873,
            
            "id": 14397890
        }
    ]
}

Lot's of other things as well, but you can get ID from here.

@golmschenk
Copy link

Hi @saltedlolly,

It is possible with duolingo API, but this package doesn't implement this method.

The endpoint is www.duolingo.com/users/{userID}/xp_summaries

It returns an array for the given time range, as following:

Screenshot 2022-02-16 at 10 30 31

Hope it helps.

@igorskh, could you tell me where you took that API screenshot? I have previously searched for documentation on Duolingo's API, but had little success. What you have in that screenshot is certainly the kind of thing I would be interested in looking at.

@igorskh
Copy link
Contributor

igorskh commented Apr 4, 2022

@igorskh, could you tell me where you took that API screenshot? I have previously searched for documentation on Duolingo's API, but had little success. What you have in that screenshot is certainly the kind of thing I would be interested in looking at.

@golmschenk I have a repo with openAPI docs https://github.com/igorskh/duolingo-api

@saltedlolly
Copy link
Author

I thought you might be interested to see what I built: https://twitter.com/saltedlolly/status/1512107599747067913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants