Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Last active February 18, 2021 14:27
Show Gist options
  • Save camillebaldock/6561716 to your computer and use it in GitHub Desktop.
Save camillebaldock/6561716 to your computer and use it in GitHub Desktop.
Duolingo Dashing widget

Duolingo dashing widget

This is a Dashing job to display Duolingo points for all languages studied by a user

Live demo:

http://camilledashing.herokuapp.com/dashboard

Usage

Put the duolingo.rb file in your /jobs folder

To include the widget in a dashboard, add the following snippet:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="duolingo" data-view="List" data-unordered="true" data-title="Duolingo" data-moreinfo="# of points per language"></div>
</li>

Settings

The only setting you have to change is the username, which you can set by adding the following line in your config.ru file (the whole example of config.ru is available lower in the gist):

set :duolingo_user, 'username'

New photos are gathered every 2 minutes by default, but you can easily change it on line 5 of duolingo.rb.

require 'dashing'
configure do
set :duolingo_user, 'username'
helpers do
def protected!
# Put any authentication code you want in here.
# This method is run before accessing any resource.
end
end
end
map Sinatra::Application.assets_prefix do
run Sinatra::Application.sprockets
end
run Sinatra::Application
require 'net/http'
require 'json'
require 'uri'
SCHEDULER.every '2m' do |job|
uri = URI.parse("http://duolingo.com/users/#{settings.duolingo_user}")
response = Net::HTTP.get_response(uri)
languages_data = JSON.parse(response.body)["languages"]
duolingo_report = Array.new
languages_data.each do |language|
if language["learning"]
duolingo_report.push({ label: language["language_string"], value: language["points"]})
end
end
duolingo_report.sort! { |a,b| b[:value] <=> a[:value] }
send_event('duolingo', { items: duolingo_report })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment