daily pastebin goal
25%
SHARE
TWEET

occupytweets

a guest Mar 25th, 2012 239 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Created by Hanna, updated on 3/22/12 by Suzanne
  2. #-------------------------------------------------------------------------------------------------------------
  3. #Input: query, q
  4. #output: a file, aFile
  5. #Description: Given q, extract relevant tweets
  6. #Comments: Very easy to use.  However, low recall (restriction of the service used)
  7. #OSX users will need to install gems and json
  8. #Windows users should use the comprehensive ruby installer
  9. #-------------------------------------------------------------------------------------------------------------
  10. require "rubygems"
  11. require "json"
  12. require "open-uri"
  13.  
  14. output = ""
  15.  
  16. #use topsy web service to extract tweets
  17. #q=query
  18. topsy = [
  19.                 "http://otter.topsy.com/search.json?q=nypd+occupy&perpage=100&page=5&type=tweet",  
  20.                 ]
  21. puts topsy
  22.  
  23. #aFile = output file of tweets
  24. aFile = File.new("nypd_occupy.txt", "a+")
  25.  
  26. topsy.each do |topsy|
  27.  
  28.  
  29.         trackbacks = JSON.parse(open(topsy).read)
  30.                
  31.                 trackbacks["response"]["list"].each do |tweet|
  32.  
  33. #attribute extraction and comma separation
  34.                         output +=   tweet["firstpost_date"].to_s + "\t" +
  35.                                                 tweet["content"] + "\t" +
  36.                                                 tweet["trackback_total"].to_s + "\t" +
  37.                                                 tweet["trackback_author_nick"] + "\t" +
  38.                                                 tweet["trackback_author_name"] + "\t" +
  39.                                                 tweet["topsy_trackback_url"] + "\n"
  40.                        
  41.                         puts output     #to show that it is working    
  42.                
  43.                 end #end trackback loop
  44.  
  45. aFile.syswrite(output)
  46.  
  47. end  #end topsy loop
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top