Created
February 12, 2012 19:40
-
-
Save makaroni4/1810435 to your computer and use it in GitHub Desktop.
Get all the events in location from last.fom
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
#ruby | |
require "rubygems" | |
require "net/http" | |
require 'nokogiri' | |
#API | |
PARAMS = %w(title website description) | |
API_KEY = "YOUR KEY" | |
LOCATION = "moscow" | |
def hash_to_url(params) | |
params.to_a.map{|s| s.join('=')}.join('&') | |
end | |
def get_event_params event | |
PARAMS.map{|param| event.search(param).first.to_s} | |
end | |
params = { | |
:method => "geo.getevents", | |
:location => LOCATION, | |
:api_key => API_KEY | |
} | |
page = Net::HTTP.get('ws.audioscrobbler.com', "/2.0/?#{hash_to_url(params)}") | |
xml_data = Nokogiri::XML(page) | |
xml_data.search("//events/event").each do |event| | |
p get_event_params(event) | |
end | |
#RSS | |
puts agent. | |
get("http://ws.audioscrobbler.com/2.0/geo/spain/events.rss").content | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment