This is where i experiment with stupid stuff. If you feel you are in the wrong place feel free to visit my blog or my CV/Resume.
Earthquakes in the last hour
2012-05-19T03:43:45Z M 1.3, Central Alaska 62.904N 148.773W 2012-05-19T03:36:14Z M 1.4, Kenai Peninsula, Alaska 60.027N 151.904W 2012-05-19T03:32:50Z M 1.2, Southern California 33.488N 116.485W 2012-05-19T03:32:26Z M 1.7, Southern California 33.480N 116.494W 2012-05-19T03:02:08Z M 1.1, Central Alaska 63.450N 147.178W 2012-05-19T02:48:00Z M 4.1, Fiji region 17.151S 179.287W
Source code for this experiment
class EarthquakesController < ApplicationController
def get_earthquakes source = "http://earthquake.usgs.gov/earthquakes/catalogs/1hour-M1.xml" # url or local file content = "" # raw content of rss feed will be loaded here open(source) do |s| content = s.read end rss = RSS::Parser.parse(content, false)
earthquakes = "" rss.items.each do |item| data = item.summary.to_s # Extract raw info data = data.scan( /alt\=\"\;([^>]*)\"\;/).last.first # Remove html escaping data = CGI.unescapeHTML(data).gsub("°", "") # Convert into coords lat = data.split(' ')[0] lon = data.split(' ')[1].sub('"', '') # Print it earthquakes << "#{item.updated.content} #{item.title.content} #{lat} #{lon} " end earthquakes end