10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/whenissunrise.rb', line 10
def self.sunrise
puts "-----"
puts "Time to find out your sunrise!"
puts "-----"
puts "You will need a latitude and longitude, which you can get by going to https://maps.google.com and selecting 'What's here?' after right-clicking on the map. If you're really lazy you can use 45.249814 and -75.7700702 for Ottawa or 53.2839064 and -9.0837658 for Galway :)"
puts "-----"
puts "Enter your latitude"
lat = gets.chomp
puts "Enter your longitude"
long = gets.chomp
puts "getting data..."
url = "https://api.sunrise-sunset.org"
date = "today"
data = HTTParty.get("#{url}/json?lat=#{lat}&lng=#{long}&date=#{date}")
dataHash = JSON[data.body]['results']
sunrise = dataHash['sunrise']
sunset = dataHash['sunset']
puts "Sunrise is at #{sunrise}"
puts "Sunset is at #{sunset}"
puts "-----"
puts "Thank you to https://sunrise-sunset.org for providing the data :)"
end
|