Created
May 21, 2011 23:28
-
-
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
This file contains hidden or 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 '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