Created
December 18, 2008 13:51
-
-
Save ajturner/37499 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
tag = "ASD" | |
### Don't need to edit below here | |
%w{ rubygems hpricot open-uri }.each {|gem| require gem} | |
next_url = "http://search.twitter.com/search.atom?tag=#{tag}&lang=all&rpp=50" | |
fields = ["id","title", "published","author/name","author/uri"] | |
entries = [fields.join(",") + ",link"] | |
while (next_url) | |
begin | |
puts next_url | |
doc = Hpricot.parse(open(next_url)) | |
entries << (doc/:entry).collect do |entry| | |
fields.collect {|f| (entry/f).inner_text }.join(",") + ",#{(entry/"link").first["href"]}" | |
end | |
next_url = (doc/"link[@rel=next]").first["href"] | |
sleep(0.2) | |
rescue | |
next_url = nil | |
end | |
end | |
File.open("#{tag}.csv","w") do |file| | |
file << entries.join("\n") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment