Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  1. igrigorik revised this gist . 1 changed file with 5 additions and 1 deletion.
    View
    6 ted-postrank.rb
    @@ -41,4 +41,8 @@
    data.each do |a|
    csv << [a['title'], a['url'], *columns.map{|c| a[c] || 0}]
    end
    -end
    +end
    +
    +
    +# Blog post: http://blog.postrank.com/2010/05/and-the-most-engaging-ted-talk-is/
    +# Google spreadsheet data: https://spreadsheets0.google.com/ccc?key=tWri7T3f4Ex6-uVU8i9-FFQ&hl=en
  2. igrigorik revised this gist . 1 changed file with 1 addition and 0 deletions.
    View
    1  ted-postrank.rb
    @@ -30,6 +30,7 @@
    puts "processed page #{page}"
    end
    +# output a CSV file with the results
    FasterCSV.open("ted.csv", "w") do |csv|
    columns = data.collect{|d| d.keys}.flatten.uniq.sort
    columns.delete('title')
  3. igrigorik created this gist .
    View
    43 ted-postrank.rb
    @@ -0,0 +1,43 @@
    +require 'rubygems'
    +require 'nokogiri'
    +require 'open-uri'
    +require 'digest/md5'
    +require 'fastercsv'
    +require 'json'
    +require 'curb'
    +require 'pp'
    +
    +data = []
    +(1..69).each do |page|
    +
    + # fetch ted talks from each page
    + doc = Nokogiri.parse(open("http://www.ted.com/talks/list/page/#{page}").read)
    + talks = doc.search('dd a').inject({}) do |hash,a|
    + hash["http://www.ted.com#{a.attributes['href'].value}"] = a.attributes['title'].value
    + hash
    + end
    +
    + # fetch postrank metrics data
    + metrics = Curl::Easy.http_post('http://api.postrank.com/v2/entry/metrics?appkey=TEDdemo',
    + talks.keys.map{|t| "url[]=#{Digest::MD5.hexdigest(t)}"}.join("&"))
    + metrics.perform
    + metrics = JSON.parse(metrics.body_str)
    +
    + talks.keys.each do |url|
    + data.push({'title' => talks[url], 'url' => url}.merge(metrics[Digest::MD5.hexdigest(url)]))
    + end
    +
    + puts "processed page #{page}"
    +end
    +
    +FasterCSV.open("ted.csv", "w") do |csv|
    + columns = data.collect{|d| d.keys}.flatten.uniq.sort
    + columns.delete('title')
    + columns.delete('url')
    +
    + csv << ["Title", "URL", *columns]
    +
    + data.each do |a|
    + csv << [a['title'], a['url'], *columns.map{|c| a[c] || 0}]
    + end
    +end
Something went wrong with that request. Please try again.