Skip to content

Instantly share code, notes, and snippets.

@asterite
Last active August 29, 2015 14:18
Show Gist options
  • Save asterite/6b68322fbf50c1a4bc86 to your computer and use it in GitHub Desktop.
Save asterite/6b68322fbf50c1a4bc86 to your computer and use it in GitHub Desktop.
require "http/client"
def title(x)
url = "http://www.wunderground.com/cgi-bin/findweather/hdfForecast?query=#{x}"
tag = "<meta property=\"og:title\" content=\""
response = HTTP::Client.get(url).body
title1 = response.index(tag).not_nil!
title2 = response.index("\" />", title1).not_nil! - 1
result = response[(title1 + tag.length)..title2]
result = result.gsub /&deg;/, "°F"
result
end
puts title(19610)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment