Skip to content

Instantly share code, notes, and snippets.

@obi-a
Created May 21, 2011 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obi-a/985001 to your computer and use it in GitHub Desktop.
Save obi-a/985001 to your computer and use it in GitHub Desktop.
Check if there is a travel alert warning for this location #hackdisrupt
require 'open-uri'
require 'rss/1.0'
require 'rss/2.0'
require 'activesupport'
def has_travel_alert(location)
source = "http://travel.state.gov/_res/rss/TWs.xml"
content = "" # raw content of rss feed will be loaded here
open(source) do |s| content = s.read end
rss = RSS::Parser.parse(content, false)
count = 0
x = 0
problem_regions = []
until count == rss.items.size
if rss.items[count].description.index(location.titlecase) != nil
region = { :title => rss.items[count].title , :pubdate => rss.items[count].pubDate, :link => rss.items[count].link}
problem_regions[x] = region
x = x + 1
end
count = count + 1
end
return problem_regions
end
puts has_travel_alert('iraq').inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment