Created
September 2, 2010 13:18
-
-
Save deathbob/562273 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
| require 'rubygems' | |
| require 'socket' | |
| gem 'twitter' # necessary if you have twitter4r installed as well as twitter | |
| require 'twitter' | |
| IP = "192.168.2.27" | |
| PORT = 2000 | |
| tweets = [] | |
| socket = TCPSocket.open(IP, PORT) | |
| search_type = "geo" | |
| feed = Thread.new do | |
| while true | |
| if (search_type == "geo") | |
| Twitter::Search.new.geocode("37.546", "-77.443", "1mi").each do |tweet| | |
| puts "got search results" | |
| #<#Hashie::Mash created_at="Wed, 01 Sep 2010 23:16:10 +0000" from_user="ExRea" from_user_id=2071244 geo=nil id=22749454497 iso_language_code="en" metadata=<#Hashie::Mash result_type="recent"> profile_image_url="http://a0.twimg.com/profile_images/1095188580/1fd47096-3acd-4d3f-a671-b4d9d48dcceb_normal.png" source="<a href="http://83degrees.com/to/powertwitter" rel="nofollow">Power Twitter</a>" text="RT @betseyross RT @RoseD1st IS JOHN CUSACK'S TWEET, HATE SPEECH? Why is he allowed to spew this kinda hate speech w/out any repercussions???" to_user_id=nil> | |
| if (tweets.select {|t| t.text == tweet.text}.empty?) | |
| puts "storing tweet #{tweet.text}" | |
| if (tweets.size < 50) | |
| tweets.push(tweet) | |
| end | |
| end | |
| end | |
| search_type = "search" | |
| else | |
| Twitter::Search.new("vcu rva").each do |tweet| | |
| puts "got search results" | |
| if (tweets.select {|t| t.text == tweet.text}.empty?) | |
| puts "storing tweet #{tweet.text}" | |
| if (tweets.size < 50) | |
| tweets.push(tweet) | |
| end | |
| end | |
| end | |
| search_type = "geo" | |
| end | |
| puts "feed thread" | |
| sleep(10) | |
| end | |
| end | |
| publisher = Thread.new do | |
| while true | |
| unless (tweets.empty?) | |
| index = rand(tweets.size) | |
| tweet = tweets.delete_at(index) | |
| puts("#{tweet.from_user},#{tweet.profile_image_url},#{tweet.text}") | |
| socket.print("#{tweet.from_user},#{tweet.profile_image_url},#{tweet.text}") | |
| sleep(10) | |
| end | |
| end | |
| end | |
| feed.join | |
| publisher.join | |
| #socket.close() | |
| # | |
| while (true) | |
| sleep(1) | |
| # ? | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment