Created
June 12, 2012 22:20
-
-
Save miguelff/2920479 to your computer and use it in GitHub Desktop.
Gente hablando en twitter desde Mieres, (Asturias) sobre los mineros.
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' | |
gem 'twitter' | |
gem 'geocoder' | |
class Hash | |
def to_url_params | |
elements = [] | |
keys.size.times do |i| | |
elements << "#{keys[i]}=#{values[i]}" | |
end | |
elements.join('&') | |
end | |
end | |
class Query | |
def initialize | |
@options = {:rpp => 10} | |
@q = nil | |
end | |
def from_place(place, radius = "25mi") | |
lat, lon = Geocoder.coordinates place | |
@options[:geocode] = "#{lat},#{lon},#{radius}" | |
self | |
end | |
def per_page(n) | |
@options[:rpp] = n | |
self | |
end | |
def page(n) | |
@options[:page] = n | |
self | |
end | |
def containing(words) | |
@q = words | |
self | |
end | |
def run(&block) | |
block = Proc.new { |status| status } if block.nil? | |
@q ||= "" | |
Twitter.search(@q, @options).map(&block) | |
end | |
end | |
puts Query.new.per_page(100).from_place("Mieres, Asturias").containing("mineros").run{|result| result.from_user}.uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment