Giter Club home page Giter Club logo

duolingo-js's Introduction

@grimille/duolingo-js [2021 UPDATE]

Use the Duolingo API and power up your Node.js application (non-official) This is WIP, feel free to contact me for additions or any issues. 🦉

Installation

Use npm to install this dependency. ⬇️⬇️⬇️

npm install @grimille/duolingo-js

Usage

Start by creating a client :

const { Duolingo } = require('@grimille/duolingo-js');
const client = new Duolingo(<username|email>, <password>);

And use async IFEE :

// ...
(async() => {
	// your code here
	
	let logged  =  await client.login(); // True / false
	let totalXP = client.getTotalXP(); //Get your total XP
	
	await client.setUser('RandomUser');
	
	totalXP = client.getTotalXP(); //Get "RandomUser"'s total XP
})();

Notice: If you don't use async, you'll block your main thread during querying.

Avalaible Methods

Retrieving the data asynchronously

  • loadSelfUserData() - Reload your own Duolingo data is the API. Done by default when login.
  • getUserData(username) - Get the full JSON payload of a Duolingo user.
  • setUser(username) - Load a user into the API (cache the data)

Using the cache when retrieved

  • getXpGoal() - Get the XP Goal (could be undefined)
  • getTotalXP() - Get the total XP earned of all courses
  • getStreak() - Get the current streak
  • getUsername() - Get the username
  • getDisplayName() - Get the display name
  • isPremium() - Get if the user is premium (Duolingo Plus) or not.
  • getId() - Get the id
  • getProfileCountry() - Get the country code
  • getCourses() - Get the courses
# Sample Response
[{ preload: false,
    placementTestAvailable: false,
    authorId: 'duolingo',
    title: 'Spanisch',
    learningLanguage: 'es',
    xp: 18685,
    healthEnabled: true,
    fromLanguage: 'de',
    crowns: 80,
    id: 'DUOLINGO_ES_DE' }]
  • getFriends() - Get the users friends
# Sample Response
{ nextCursor: null,
  totalSubscriptions: 1,
  subscriptions:
   [ { username: 'XXX',
       picture: '//simg-ssl.duolingo.com/avatar/default_2',
       name: 'Vroni',
       monthlyXp: 3527,
       weeklyXp: 811,
       hasRecentActivity15: false,
       totalXp: 7318,
       id: XXX,
       hasPlus: false } ] }

Todos

  • Implement new API calls (Buy a freeze… 👀)
  • More testing and more support
  • Tell me your needs

Links

Contributing

No contributions for the moment as the API is in working progress.

License

MIT

duolingo-js's People

Contributors

grimille avatar knerbel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

knerbel

duolingo-js's Issues

idea

you should add a way to use your google account to log in. i've seen some people do this by using your "token" (jwt_token cookie) or using all of your cookies put into a .json file.

thanks!

Endpoints to complete lessons programmatically

Introducing endpoints to list and complete lessons programmatically would be great to create new clients, for example:
POST https://excess.duolingo.com/challenge_response/batch
Request payload:

[
	{
		"app_version": "...",
		"challenge_response_timestamp": 1647847735414,
		"challenge_response_tracking_properties": {
			"birdbrain_probability": 0.90121436,
			"birdbrain_source": "birdbrain_v2",
			"birdbrain_target": 0.89,
			"content_length": 20,
			"grading_graph_size": 464,
			"is_v2": false
		},
		"client": "web",
		"closest_solution": "Le garçon mange du pain.",
		"compact_translations": [
			"Le garçon mange du pain."
		],
		"content_id": "...",
		"correct": true,
		"from_language": "fr",
		"guess": "Le garçon mange du pain",
		"hinted_words": [],
		"item_type": "translate",
		"learning_language": "de",
		"order_index": 1,
		"prompt": "Der Junge isst Brot.",
		"repetition_number": 0,
		"session_id": "...",
		"session_type": "skill_practice",
		"skill_id": "...",
		"skill_tree_id": "...",
		"skipped": false,
		"tagged_kc_ids": [
			"...",
			"...",
			"...",
			"..."
		],
		"time_taken": 19708,
		"user_id": 540517814
	}
]

Response: Successfully submitted 1 challenge response(s)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.