Speed up development with full-stack environments for every branch.

Learn More

OpenWeather API [Ruby]

Forked from Basic Ruby Example.

22 Runs 37 Views 1 Copies
Saved

Saved

nthompson82 1

nthompson82
published 8 days ago

    #puts "What city would you like to see weather for?"
    input = gets.chomp()
    input = input.downcase
    
    callString = "http://api.openweathermap.org/data/2.5/weather?q=" + "#{input}" + "&APPID=5c89010425b4d730b7558f57234ea3c8&units=imperial"
    
    require 'net/http'
    require 'json'
     
    url = callString
    uri = URI(url)
    response = Net::HTTP.get(uri)
    parsed = JSON.parse(response)
    temp = parsed['main']['temp']
    desc = parsed['weather'][0]['description']
    humid = parsed['main']['humidity']
    wind = parsed['wind']['speed']
    
    input = input.capitalize
    puts "Here is your weather for " + "#{input}" + ":"
    puts "It is " + "#{temp}" + " degrees outside with a wind of " + "#{wind}" + "mph."
    puts "Also, it's " "#{desc}" + " and humidity is at " + "#{humid}" + "%."
    Please login/signup to get access to the terminal.

    Your session has timed out.

    Dismiss (the page may not function properly).