weather-sage 0.1.0 → 0.1.1
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 +4 -4
- data/lib/weather-sage/cache-entry.rb +13 -0
- data/lib/weather-sage/cache.rb +79 -0
- data/lib/weather-sage/census/geocoder.rb +48 -0
- data/lib/weather-sage/census/match.rb +19 -0
- data/lib/weather-sage/census.rb +7 -0
- data/lib/weather-sage/cli/commands/base-forecast.rb +70 -0
- data/lib/weather-sage/cli/commands/command.rb +42 -0
- data/lib/weather-sage/cli/commands/forecast.rb +28 -0
- data/lib/weather-sage/cli/commands/geocode.rb +51 -0
- data/lib/weather-sage/cli/commands/help.rb +82 -0
- data/lib/weather-sage/cli/commands/hourly.rb +28 -0
- data/lib/weather-sage/cli/commands/now.rb +87 -0
- data/lib/weather-sage/cli/commands/stations.rb +67 -0
- data/lib/weather-sage/cli/commands.rb +15 -0
- data/lib/weather-sage/cli/env/cache.rb +38 -0
- data/lib/weather-sage/cli/env/context.rb +29 -0
- data/lib/weather-sage/cli/env/env.rb +35 -0
- data/lib/weather-sage/cli/env/log.rb +41 -0
- data/lib/weather-sage/cli/env/vars.rb +20 -0
- data/lib/weather-sage/cli/env.rb +14 -0
- data/lib/weather-sage/cli/forecast.rb +70 -0
- data/lib/weather-sage/cli/help.rb +68 -0
- data/lib/weather-sage/cli.rb +29 -0
- data/lib/weather-sage/context.rb +13 -0
- data/lib/weather-sage/http/cache.rb +72 -0
- data/lib/weather-sage/http/error.rb +15 -0
- data/lib/weather-sage/http/fetcher.rb +79 -0
- data/lib/weather-sage/http/parser.rb +46 -0
- data/lib/weather-sage/http.rb +9 -0
- data/lib/weather-sage/weather/base-object.rb +36 -0
- data/lib/weather-sage/weather/forecast.rb +47 -0
- data/lib/weather-sage/weather/observation.rb +33 -0
- data/lib/weather-sage/weather/period.rb +44 -0
- data/lib/weather-sage/weather/point.rb +71 -0
- data/lib/weather-sage/weather/station.rb +43 -0
- data/lib/weather-sage/weather.rb +11 -0
- data/lib/weather-sage.rb +1 -1
- metadata +39 -3
- data/test/make-csvs.sh +0 -10
@@ -0,0 +1,44 @@
|
|
1
|
+
#
|
2
|
+
# Numerical weather forecast period.
|
3
|
+
#
|
4
|
+
class WeatherSage::Weather::Period
|
5
|
+
attr :data,
|
6
|
+
:name,
|
7
|
+
:start_time,
|
8
|
+
:end_time,
|
9
|
+
:is_daytime,
|
10
|
+
:temperature,
|
11
|
+
:temperature_unit,
|
12
|
+
:temperature_trend,
|
13
|
+
:wind_speed,
|
14
|
+
:wind_direction,
|
15
|
+
:icon,
|
16
|
+
:short_forecast,
|
17
|
+
:detailed_forecast
|
18
|
+
|
19
|
+
#
|
20
|
+
# Create new forecast period from given data.
|
21
|
+
#
|
22
|
+
def initialize(ctx, data)
|
23
|
+
@ctx = ctx
|
24
|
+
@data = data.freeze
|
25
|
+
|
26
|
+
# log data
|
27
|
+
@ctx.log.debug('Period#initialize') do
|
28
|
+
'data = %p' % [data]
|
29
|
+
end
|
30
|
+
|
31
|
+
@name = data['name']
|
32
|
+
@start_time = Time.parse(data['startTime'])
|
33
|
+
@end_time = Time.parse(data['endTime'])
|
34
|
+
@is_daytime = data['isDaytime']
|
35
|
+
@temperature = data['temperature']
|
36
|
+
@temperature_unit = data['temperatureUnit']
|
37
|
+
@temperature_trend = data['temperatureTrend']
|
38
|
+
@wind_speed = data['windSpeed']
|
39
|
+
@wind_direction = data['windDirection']
|
40
|
+
@icon = data['icon']
|
41
|
+
@short_forecast = data['shortForecast']
|
42
|
+
@detailed_forecast = data['detailedForecast']
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Thin wrapper around lat/long point in weather API.
|
3
|
+
#
|
4
|
+
class WeatherSage::Weather::Point < WeatherSage::Weather::BaseObject
|
5
|
+
attr :x, :y
|
6
|
+
|
7
|
+
#
|
8
|
+
# Create a new Point object at the given longitude +x+ and latitude
|
9
|
+
# +y+.
|
10
|
+
#
|
11
|
+
def initialize(ctx, x, y)
|
12
|
+
super(ctx)
|
13
|
+
@x, @y = x, y
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Returns a list of weather stations near this point.
|
18
|
+
#
|
19
|
+
def stations
|
20
|
+
# build request path
|
21
|
+
path = 'points/%2.4f%%2C%2.4f/stations' % [@y, @x]
|
22
|
+
|
23
|
+
get(path)['features'].map { |row|
|
24
|
+
WeatherSage::Weather::Station.from_json(@ctx, row)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Returns a hash of properties for this point.
|
30
|
+
#
|
31
|
+
def properties
|
32
|
+
# build request path
|
33
|
+
path = 'points/%2.4f%%2C%2.4f' % [@y, @x]
|
34
|
+
|
35
|
+
# execute request, return properties
|
36
|
+
get(path)['properties']
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Returns a weather forecast for this point.
|
41
|
+
#
|
42
|
+
def forecast
|
43
|
+
forecast_by_type('forecast')
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Returns an hourly weather forecast for this point.
|
48
|
+
#
|
49
|
+
def hourly_forecast
|
50
|
+
forecast_by_type('forecastHourly')
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
#
|
56
|
+
# Get forecast type from properties.
|
57
|
+
#
|
58
|
+
# Remove the scheme, host, and leading slash from the URL provided
|
59
|
+
# in the properties.
|
60
|
+
#
|
61
|
+
def forecast_by_type(forecast_type)
|
62
|
+
# parse URI for given request type
|
63
|
+
uri = URI.parse(properties[forecast_type])
|
64
|
+
|
65
|
+
# strip scheme, host, and leading slash from URI to build path
|
66
|
+
path = uri.path.gsub(/^\//, '')
|
67
|
+
|
68
|
+
# request forecast and build a Forecast object from it
|
69
|
+
::WeatherSage::Weather::Forecast.new(@ctx, get(path))
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Thin wrapper around weather station.
|
3
|
+
#
|
4
|
+
class WeatherSage::Weather::Station < ::WeatherSage::Weather::BaseObject
|
5
|
+
attr :id, :name, :x, :y, :elevation, :time_zone
|
6
|
+
|
7
|
+
#
|
8
|
+
# Create a new Station from the given Context +ctx+ and the JSON
|
9
|
+
# data +row+.
|
10
|
+
#
|
11
|
+
def self.from_json(ctx, row)
|
12
|
+
new(
|
13
|
+
ctx,
|
14
|
+
row['properties']['stationIdentifier'],
|
15
|
+
row['properties']['name'],
|
16
|
+
row['geometry']['coordinates'][0],
|
17
|
+
row['geometry']['coordinates'][1],
|
18
|
+
row['properties']['elevation']['value'],
|
19
|
+
row['properties']['timeZone']
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# Create a new station instance.
|
25
|
+
#
|
26
|
+
def initialize(ctx, id, name, x, y, elevation, time_zone)
|
27
|
+
@ctx = ctx
|
28
|
+
@id = id
|
29
|
+
@name = name
|
30
|
+
@x = x
|
31
|
+
@y = y
|
32
|
+
@elevation = elevation
|
33
|
+
@time_zone = time_zone
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Return a hash of the latest observations from this station.
|
38
|
+
#
|
39
|
+
def latest_observations
|
40
|
+
path = 'stations/%s/observations/latest' % [@id]
|
41
|
+
get(path)['properties']
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#
|
2
|
+
# Thin wrapper around weather.gov API.
|
3
|
+
#
|
4
|
+
module WeatherSage::Weather
|
5
|
+
autoload :BaseObject, File.join(__dir__, 'weather', 'base-object.rb')
|
6
|
+
autoload :Observation, File.join(__dir__, 'weather', 'observation.rb')
|
7
|
+
autoload :Point, File.join(__dir__, 'weather', 'point.rb')
|
8
|
+
autoload :Station, File.join(__dir__, 'weather', 'station.rb')
|
9
|
+
autoload :Forecast, File.join(__dir__, 'weather', 'forecast.rb')
|
10
|
+
autoload :Period, File.join(__dir__, 'weather', 'period.rb')
|
11
|
+
end
|
data/lib/weather-sage.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather-sage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Duncan
|
@@ -15,7 +15,8 @@ description: "\n Ruby library and command-line tool to get the weather foreca
|
|
15
15
|
Geocoding API to geocode street addresses,\n and the National Weather Service
|
16
16
|
Weather API to get weather\n forecasts and current weather observations.\n "
|
17
17
|
email: pabs@pablotron.org
|
18
|
-
executables:
|
18
|
+
executables:
|
19
|
+
- weather-sage
|
19
20
|
extensions: []
|
20
21
|
extra_rdoc_files: []
|
21
22
|
files:
|
@@ -23,8 +24,43 @@ files:
|
|
23
24
|
- Rakefile
|
24
25
|
- bin/weather-sage
|
25
26
|
- lib/weather-sage.rb
|
27
|
+
- lib/weather-sage/cache-entry.rb
|
28
|
+
- lib/weather-sage/cache.rb
|
29
|
+
- lib/weather-sage/census.rb
|
30
|
+
- lib/weather-sage/census/geocoder.rb
|
31
|
+
- lib/weather-sage/census/match.rb
|
32
|
+
- lib/weather-sage/cli.rb
|
33
|
+
- lib/weather-sage/cli/commands.rb
|
34
|
+
- lib/weather-sage/cli/commands/base-forecast.rb
|
35
|
+
- lib/weather-sage/cli/commands/command.rb
|
36
|
+
- lib/weather-sage/cli/commands/forecast.rb
|
37
|
+
- lib/weather-sage/cli/commands/geocode.rb
|
38
|
+
- lib/weather-sage/cli/commands/help.rb
|
39
|
+
- lib/weather-sage/cli/commands/hourly.rb
|
40
|
+
- lib/weather-sage/cli/commands/now.rb
|
41
|
+
- lib/weather-sage/cli/commands/stations.rb
|
42
|
+
- lib/weather-sage/cli/env.rb
|
43
|
+
- lib/weather-sage/cli/env/cache.rb
|
44
|
+
- lib/weather-sage/cli/env/context.rb
|
45
|
+
- lib/weather-sage/cli/env/env.rb
|
46
|
+
- lib/weather-sage/cli/env/log.rb
|
47
|
+
- lib/weather-sage/cli/env/vars.rb
|
48
|
+
- lib/weather-sage/cli/forecast.rb
|
49
|
+
- lib/weather-sage/cli/help.rb
|
50
|
+
- lib/weather-sage/context.rb
|
51
|
+
- lib/weather-sage/http.rb
|
52
|
+
- lib/weather-sage/http/cache.rb
|
53
|
+
- lib/weather-sage/http/error.rb
|
54
|
+
- lib/weather-sage/http/fetcher.rb
|
55
|
+
- lib/weather-sage/http/parser.rb
|
56
|
+
- lib/weather-sage/weather.rb
|
57
|
+
- lib/weather-sage/weather/base-object.rb
|
58
|
+
- lib/weather-sage/weather/forecast.rb
|
59
|
+
- lib/weather-sage/weather/observation.rb
|
60
|
+
- lib/weather-sage/weather/period.rb
|
61
|
+
- lib/weather-sage/weather/point.rb
|
62
|
+
- lib/weather-sage/weather/station.rb
|
26
63
|
- license.txt
|
27
|
-
- test/make-csvs.sh
|
28
64
|
- test/test-cache.rb
|
29
65
|
- test/test-census-geocoder.rb
|
30
66
|
- test/test-helpers.rb
|
data/test/make-csvs.sh
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
# TODO: move to rake task
|
4
|
-
ADDR='7309 carol ln falls church va 22042'
|
5
|
-
|
6
|
-
bin/weather-sage hourly -f "$ADDR" > hourly-full.csv
|
7
|
-
bin/weather-sage hourly -b "$ADDR" > hourly-brief.csv
|
8
|
-
bin/weather-sage forecast -b "$ADDR" > forecast-brief.csv
|
9
|
-
bin/weather-sage forecast -f "$ADDR" > forecast-full.csv
|
10
|
-
bin/weather-sage now "$ADDR" > now.csv
|