Created
December 11, 2014 04:18
-
-
Save dylandy/ab0df354854e24c10bcd to your computer and use it in GitHub Desktop.
Dcard 回應男女比
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'json' | |
require 'open-uri' | |
start_at = 20000 | |
end_at = JSON.load(open("http://www.dcard.tw/api/forum/all/1/"))[0]["id"] | |
gender = [] | |
(start_at..end_at).each do |i| | |
begin | |
tmp = JSON.load(open("http://www.dcard.tw/api/post/#{i}"))["comment"] | |
tmp.each do |j| | |
gender << j["member"]["gender"] | |
end | |
puts "now post #{i}" | |
next | |
rescue | |
next | |
end | |
end | |
puts "回應男性數:#{gender.count("M")}" | |
puts "回應女性數:#{gender.count("F")}" | |
puts "性別比:#{gender.count("M")/gender.count("F")}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
大約有 30000 筆資料,需要執行時間較長,約 80 分鐘,在 Unix-like 系統下,可以用下列方式計算執行時間