Ruby 使用 Ruby 查询天气

luobojuhua · May 05, 2022 · Last by shiweifu replied at May 05, 2022 · 461 hits
require "net/http"
require "json"

uri=URI.parse("https://yiketianqi.com/api?unescape=1&version=v6&appid=46245721&appsecret=sKA9gzik")
response = Net::HTTP.get_response(uri)
data=JSON.parse(response.body)

puts data["city"]+"今日天气预报:今天是:"+data["date"]+","+data["week"]+",天气情况为"+data["wea"] 

lz 编辑一下 appid 和 appsecret 吧,最好不要直接暴露着发出来

You need to Sign in before reply, if you don't have an account, please Sign up first.