Skip to content

Instantly share code, notes, and snippets.

@miguelff
Created June 12, 2012 22:20
Show Gist options
  • Save miguelff/2920479 to your computer and use it in GitHub Desktop.
Save miguelff/2920479 to your computer and use it in GitHub Desktop.
Gente hablando en twitter desde Mieres, (Asturias) sobre los mineros.
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