Skip to content

Instantly share code, notes, and snippets.

@Jun-Dai
Last active August 29, 2015 14:04
Show Gist options
  • Save Jun-Dai/cf730e48a8a50a5cb396 to your computer and use it in GitHub Desktop.
Save Jun-Dai/cf730e48a8a50a5cb396 to your computer and use it in GitHub Desktop.
Polling in Duolingo

One way to extract polling data from Duolingo. Ask each user to write what they want in their comment in the form:

I vote for Tamil.

Then, with the script below, you can extract the vote for each user into a CSV output. If you want to run this and save to a CSV so you can upload it to Google spreadsheets, you can do this (on a mac):

ruby get_poll_results.rb 'https://www.duolingo.com/comments/3938897' > poll_results.csv

where 3938897 is the ID of the thread in question. From there you have each person's answer in first column and each person's vote in the second column. It should be pretty easy to consolidate from there?

Pros:

  • Only one vote per user (people can vote-fix by creating multiple users, but that's probably more effort than they'll go through).

Cons:

  • Votes are public, not private (does this matter?)
  • Only Duolingo members can vote.

Example output from running the script against the thread 3938897:

User, Language
LilyQuince, Norwegian
mitchell_mollet, Icelandic
AureliaUK, Persian
stwel, Catalan
Thsar999999, Afrikaans
Jlesnick, Hebrew
flint72, from the same library
Jillianimal, multiple languages
SeasWouldRise, for

(obviously this is against people not realising their voting :-), but it gives an idea). Using wikipedia (or omniglot or ethnologue) links would require a slight modification to the Ruby script, but would at least limit people to a fixed name for a given language.

require 'open-uri'
require 'json'
comments = JSON.parse(open(ARGV[0]).read)
votes_by_user = {}
comments["comments"].each do |comment|
if comment["message"] =~ /voted? (?:for )?([^.!,?)"]+)([.!,?)"]|$)/i
language = $1
if language =~ /(.*) (because|as|for)/
language = $1
end
votes_by_user[comment["user"]["username"]] = language
end
end
puts "User, Language"
votes_by_user.each do |user, language|
puts "#{user}, #{language}"
end
# If needed, it should be easy to adjust the result formatting so that case, etc., match. Also, it wouldn't be too hard to collate to a list of common names for known languages (Scots Gaelic, Scottish Gaelic, Gaelic could all map to one language that way), or you could just ask people to post a link to Wikipedia page for the language.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment