Ostatnio aktywny 1724760187

rdsm zrewidował ten Gist 1724760187. Przejdź do rewizji

1 file changed, 22 insertions

weather.rb(stworzono plik)

@@ -0,0 +1,22 @@
1 + require 'net/http'
2 + require 'uri'
3 + require 'json'
4 +
5 + def get_location(city)
6 + url = URI("https://nominatim.openstreetmap.org/search?format=json&q=#{city}&limit=1")
7 +
8 + response = Net::HTTP.get(URI(url))
9 + JSON.parse(response)[0]
10 + end
11 +
12 + def get_weather(latitude, longitude)
13 + url = URI("https://api.open-meteo.com/v1/forecast?latitude=#{latitude}&longitude=#{longitude}&current=temperature_2m&hourly=temperature_2m")
14 +
15 + response = Net::HTTP.get(URI(url))
16 + JSON.parse(response)["current"]["temperature_2m"]
17 + end
18 +
19 + location = get_location(ARGV[0])
20 + latitude = location['lat'].to_s
21 + longitude = location['lon'].to_s
22 + puts get_weather(latitude,longitude)
Nowsze Starsze