Skip to content

Instantly share code, notes, and snippets.

@zetavg
Created March 8, 2015 15:48
Show Gist options
  • Select an option

  • Save zetavg/304eac2b10927c373e8b to your computer and use it in GitHub Desktop.

Select an option

Save zetavg/304eac2b10927c373e8b to your computer and use it in GitHub Desktop.
班代感謝祭_抽獎資料
require 'net/http'
require 'json'
require 'time'
post_id = ARGV[0]
access_token = ARGV[1]
uri = URI("https://graph.facebook.com/v2.2/#{post_id}/comments?limit=5000&access_token=#{access_token}")
body = Net::HTTP.get(uri)
data = JSON.parse(body)
end_time = Time.new(2015, 3, 8, 10, 0, 0, '+08:00')
processed_data = data['data']
processed_data.reject! { |c| t = Time.parse(c['created_time']); t > end_time }
commenters = processed_data.map { |d| d['from'] }
commenters.reject! { |c| !c['category'].nil? }
commenters.map! { |c| { fbid: c['id'], name: c['name'] } }
commenters.uniq!
target = File.new('data.js', 'w')
target.write("var data = #{commenters.to_json} ;")
target.close
p 'ok'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment