
occupytweets
By: a guest on
Mar 25th, 2012 | syntax:
Ruby | size: 1.42 KB | hits: 91 | expires: Never
#Created by Hanna, updated on 3/22/12 by Suzanne
#-------------------------------------------------------------------------------------------------------------
#Input: query, q
#output: a file, aFile
#Description: Given q, extract relevant tweets
#Comments: Very easy to use. However, low recall (restriction of the service used)
#OSX users will need to install gems and json
#Windows users should use the comprehensive ruby installer
#-------------------------------------------------------------------------------------------------------------
require "rubygems"
require "json"
require "open-uri"
output = ""
#use topsy web service to extract tweets
#q=query
topsy = [
"http://otter.topsy.com/search.json?q=nypd+occupy&perpage=100&page=5&type=tweet",
]
puts topsy
#aFile = output file of tweets
aFile = File.new("nypd_occupy.txt", "a+")
topsy.each do |topsy|
trackbacks = JSON.parse(open(topsy).read)
trackbacks["response"]["list"].each do |tweet|
#attribute extraction and comma separation
output += tweet["firstpost_date"].to_s + "\t" +
tweet["content"] + "\t" +
tweet["trackback_total"].to_s + "\t" +
tweet["trackback_author_nick"] + "\t" +
tweet["trackback_author_name"] + "\t" +
tweet["topsy_trackback_url"] + "\n"
puts output #to show that it is working
end #end trackback loop
aFile.syswrite(output)
end #end topsy loop