sunweather 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74ce93abd217f69b927922cb69b857699810c3f5
4
- data.tar.gz: 460c4ac85a395ea184fb621cfb9efa132a6fe88c
3
+ metadata.gz: 2ca51bd687910ce30b1ed0723f7184483620d95c
4
+ data.tar.gz: c436170147ab0cd4f608dca0af7c730a5e8372fb
5
5
  SHA512:
6
- metadata.gz: f3849b914b070724e309ffb2b2840585dc2e4437e9ceb49db1118f207c33194735ed287756262591a3eb93a7d1a6eabe931dd353cc1395f98835a8cf7bd7f226
7
- data.tar.gz: f7713dcf2adb8158f542ee30a831cb3b2e1313743d56a7630233f78844d607d439fb25d4b927bf245072e6ad89af50926e10ae4905085651d82b7f20278a8070
6
+ metadata.gz: a8807130f624a19b61bb949d612a784fba4381d7f2561d4eb6f525291facfe4f5061831f27ecbaa7c4c8fc0ff47ab33688f705fea56e130f4eef9ea055bbab0d
7
+ data.tar.gz: 753ef1d2e8a0455c690f8b3dcd906ac89efaa75884bea46f8a6480b61ad10f86848d3f473f85c43ca11ed722258d48a90f4e00a6b953fa9329a05d6e8795f64f
data/README.rdoc CHANGED
@@ -1,8 +1,26 @@
1
- = sunweather
1
+ = Sunweather
2
2
 
3
- Description goes here.
3
+ Sunweather
4
4
 
5
- == Contributing to sunweather
5
+ Sunweather produces information about dawn and dusk times as well as temperature and weather information for a requested location.
6
+
7
+ Thanks go to Ruby Geocoder for looking up geocoordinates from queries. Ruby Geocoder uses the Google Maps API as default.
8
+
9
+ Thanks also go to Wunderground. Sunweather consults the Wunderground Astronomy and Conditions APIs for sunrise/sunset times and weather information.
10
+
11
+ Finally, thanks go to EarthTools. EarthTools provides information about the durations of dawn and dusk.
12
+
13
+ == Usage notes
14
+
15
+ Sunweather is not yet in a state meant for use. However, you can provide a Wunderground API key as an environment variable, so that Ruby can access it via ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]. If you do, a query on the console goes like
16
+
17
+ $ sunweather Berlin
18
+ Dawn from 7:14 to 7:53.
19
+ Dusk from 15:56 to 16:35.
20
+ Temperature: 5.8°C, feels like 4.0°C.
21
+ Weather: Overcast, Winds from the wnw at 4.4 mph gusting to 6.4 mph, direction WNW.
22
+
23
+ == Contributing to Sunweather
6
24
 
7
25
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
26
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/lib/data.rb ADDED
@@ -0,0 +1,86 @@
1
+ require 'xmlsimple'
2
+ require 'open-uri'
3
+ require 'date'
4
+
5
+ module Sunweather
6
+ class Data
7
+ attr_reader :data_astro_conditions, :data_forecast, :data_twilight
8
+
9
+ def initialize lat, lng
10
+ file = open("http://api.wunderground.com/api/#{ENV["SUNWEATHER_DEV_WUNDERGROUND_API"]}/astronomy/conditions/q/#{lat},#{lng}.xml")
11
+ @data_astro_conditions = XmlSimple.xml_in(file)
12
+ file = open("http://api.worldweatheronline.com/free/v1/weather.ashx?q=#{lat},#{lng}&format=xml&extra=localObsTime&num_of_days=5&includelocation=yes&key=#{ENV['SUNWEATHER_DEV_WWO_API']}")
13
+ @data_forecast = XmlSimple.xml_in(file)
14
+ file = open("http://www.earthtools.org/sun/#{lat}/#{lng}/#{Time.now.mday}/#{Time.now.mon}/99/0")
15
+ @data_twilight = XmlSimple.xml_in(file)
16
+ end
17
+
18
+ def temperature
19
+ Float(self.data_astro_conditions["current_observation"][0]["temp_c"][0])
20
+ end
21
+
22
+ def feels_like
23
+ Float(self.data_astro_conditions["current_observation"][0]["feelslike_c"][0])
24
+ end
25
+
26
+ def observation_time
27
+ Time.at(Integer(self.data_astro_conditions["current_observation"][0]["observation_epoch"][0]))
28
+ end
29
+
30
+ def conditions
31
+ self.data_astro_conditions["current_observation"][0]["weather"][0]
32
+ end
33
+
34
+ def wind_speed
35
+ self.data_astro_conditions["current_observation"][0]["wind_string"][0]
36
+ end
37
+
38
+ def wind_direction
39
+ self.data_astro_conditions["current_observation"][0]["wind_dir"][0]
40
+ end
41
+
42
+ def sunrise
43
+ Time.new(1970,1,1,self.data_astro_conditions["sun_phase"][0]["sunrise"][0]["hour"][0],self.data_astro_conditions["sun_phase"][0]["sunrise"][0]["minute"][0])
44
+ end
45
+
46
+ def sunset
47
+ Time.new(1970,1,1,self.data_astro_conditions["sun_phase"][0]["sunset"][0]["hour"][0],self.data_astro_conditions["sun_phase"][0]["sunset"][0]["minute"][0])
48
+ end
49
+
50
+ def sunrise_earthtools
51
+ DateTime.parse(self.data_twilight["morning"][0]["sunrise"][0]).to_time
52
+ end
53
+
54
+ def sunset_earthtools
55
+ DateTime.parse(self.data_twilight["evening"][0]["sunset"][0]).to_time
56
+ end
57
+
58
+ def start_of_dawn_earthtools
59
+ DateTime.parse(self.data_twilight["morning"][0]["twilight"][0]["civil"][0]).to_time
60
+ end
61
+
62
+ def end_of_dusk_earthtools
63
+ DateTime.parse(self.data_twilight["evening"][0]["twilight"][0]["civil"][0]).to_time
64
+ end
65
+
66
+ def dawn_length
67
+ Time.at(self.sunrise_earthtools - self.start_of_dawn_earthtools)
68
+ end
69
+
70
+ def dusk_length
71
+ Time.at(self.end_of_dusk_earthtools - self.sunset_earthtools)
72
+ end
73
+
74
+ def start_of_dawn
75
+ Time.at(self.sunrise - self.dawn_length)
76
+ end
77
+
78
+ def end_of_dusk
79
+ Time.at(self.sunset.to_i + self.dawn_length.to_i)
80
+ end
81
+
82
+ def hours_minutes time
83
+ "#{time.hour}:#{time.minute+time.second/30}"
84
+ end
85
+ end
86
+ end
data/lib/runner.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require_relative 'geo'
2
- require_relative 'sun'
3
- require_relative 'weather'
2
+ require_relative 'data'
4
3
 
5
4
  module Sunweather
6
5
  class Runner
@@ -10,12 +9,11 @@ module Sunweather
10
9
 
11
10
  def run
12
11
  @geo = (ARGV[0] ? Geo.new(ARGV[0]) : Geo.new)
13
- @sun = Sun.new(@geo.lat, @geo.lng)
14
- @weather = Weather.new(@geo.lat, @geo.lng)
15
- puts "Dawn from #{hours_minutes(@sun.start_of_dawn)} to #{hours_minutes(@sun.sunrise)}."
16
- puts "Dusk from #{hours_minutes(@sun.sunset)} to #{hours_minutes(@sun.end_of_dusk)}."
17
- puts "Temperature: #{@weather.temperature}°C, feels like #{@weather.feels_like}°C."
18
- puts "Weather: #{@weather.conditions}, Winds #{@weather.wind_speed.downcase}, direction #{@weather.wind_direction}."
12
+ @data = Data.new(@geo.lat, @geo.lng)
13
+ puts "Dawn from #{hours_minutes(@data.start_of_dawn)} to #{hours_minutes(@data.sunrise)}."
14
+ puts "Dusk from #{hours_minutes(@data.sunset)} to #{hours_minutes(@data.end_of_dusk)}."
15
+ puts "Temperature: #{@data.temperature}°C, feels like #{@data.feels_like}°C."
16
+ puts "Weather: #{@data.conditions}, Winds #{@data.wind_speed.downcase}, direction #{@data.wind_direction}."
19
17
  end
20
18
 
21
19
  def hours_minutes time