barometer 0.8.0 → 0.9.0
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.
- data/.gitignore +2 -0
- data/.pelusa.yml +7 -0
- data/.travis.yml +6 -3
- data/Gemfile +11 -1
- data/README.md +89 -244
- data/Rakefile +1 -1
- data/barometer.gemspec +22 -24
- data/lib/barometer.rb +14 -65
- data/lib/barometer/base.rb +35 -65
- data/lib/barometer/data.rb +15 -20
- data/lib/barometer/data/attribute.rb +19 -0
- data/lib/barometer/data/attributes/distance.rb +11 -0
- data/lib/barometer/data/attributes/float.rb +11 -0
- data/lib/barometer/data/attributes/integer.rb +11 -0
- data/lib/barometer/data/attributes/location.rb +11 -0
- data/lib/barometer/data/attributes/pressure.rb +11 -0
- data/lib/barometer/data/attributes/sun.rb +15 -0
- data/lib/barometer/data/attributes/temperature.rb +11 -0
- data/lib/barometer/data/attributes/time.rb +11 -0
- data/lib/barometer/data/attributes/vector.rb +11 -0
- data/lib/barometer/data/attributes/zone.rb +11 -0
- data/lib/barometer/data/convertable_units.rb +145 -0
- data/lib/barometer/data/coordinates.rb +16 -0
- data/lib/barometer/data/distance.rb +14 -133
- data/lib/barometer/data/geo.rb +22 -59
- data/lib/barometer/data/location.rb +14 -20
- data/lib/barometer/data/pressure.rb +14 -135
- data/lib/barometer/data/sun.rb +24 -24
- data/lib/barometer/data/temperature.rb +14 -169
- data/lib/barometer/data/vector.rb +44 -0
- data/lib/barometer/data/zone.rb +109 -112
- data/lib/barometer/query.rb +23 -161
- data/lib/barometer/query/base.rb +88 -0
- data/lib/barometer/query/converter.rb +64 -0
- data/lib/barometer/query/converters/from_coordinates_to_noaa_station_id.rb +30 -0
- data/lib/barometer/query/converters/from_geocode_to_coordinates.rb +28 -0
- data/lib/barometer/query/converters/from_short_zipcode_to_zipcode.rb +28 -0
- data/lib/barometer/query/converters/from_weather_id_to_geocode.rb +30 -0
- data/lib/barometer/query/converters/from_woe_id_or_ipv4_to_geocode.rb +32 -0
- data/lib/barometer/query/converters/to_geocode.rb +30 -0
- data/lib/barometer/query/converters/to_weather_id.rb +30 -0
- data/lib/barometer/query/converters/to_woe_id.rb +30 -0
- data/lib/barometer/query/format.rb +59 -0
- data/lib/barometer/query/formats/base.rb +22 -0
- data/lib/barometer/query/formats/coordinates.rb +14 -0
- data/lib/barometer/query/formats/geocode.rb +15 -0
- data/lib/barometer/query/formats/icao.rb +35 -0
- data/lib/barometer/query/formats/ipv4_address.rb +19 -0
- data/lib/barometer/query/formats/noaa_station_id.rb +15 -0
- data/lib/barometer/query/formats/postalcode.rb +20 -0
- data/lib/barometer/query/formats/short_zipcode.rb +15 -0
- data/lib/barometer/{translations → query/formats/translations}/icao_country_codes.yml +0 -0
- data/lib/barometer/{translations → query/formats/translations}/weather_country_codes.yml +0 -0
- data/lib/barometer/query/formats/unknown.rb +14 -0
- data/lib/barometer/query/formats/weather_id.rb +33 -0
- data/lib/barometer/query/formats/woe_id.rb +28 -0
- data/lib/barometer/query/formats/zipcode.rb +15 -0
- data/lib/barometer/query/service.rb +13 -0
- data/lib/barometer/query/services/apis/geonames_timezone.rb +26 -0
- data/lib/barometer/query/services/apis/google_geocode.rb +35 -0
- data/lib/barometer/query/services/apis/noaa_station.rb +31 -0
- data/lib/barometer/query/services/apis/weather_id.rb +35 -0
- data/lib/barometer/query/services/apis/wunderground_timezone.rb +26 -0
- data/lib/barometer/query/services/apis/yahoo_placefinder.rb +35 -0
- data/lib/barometer/query/services/apis/yahoo_weather.rb +31 -0
- data/lib/barometer/query/services/from_weather_id.rb +64 -0
- data/lib/barometer/query/services/geonames_timezone.rb +18 -0
- data/lib/barometer/query/services/google_geocode.rb +106 -0
- data/lib/barometer/query/services/noaa_station_id.rb +28 -0
- data/lib/barometer/query/services/to_weather_id.rb +25 -0
- data/lib/barometer/query/services/to_woe_id.rb +29 -0
- data/lib/barometer/query/services/wunderground_timezone.rb +18 -0
- data/lib/barometer/query/services/yahoo_geocode.rb +69 -0
- data/lib/barometer/response.rb +12 -0
- data/lib/barometer/response/base.rb +57 -0
- data/lib/barometer/response/current.rb +27 -0
- data/lib/barometer/response/prediction.rb +41 -0
- data/lib/barometer/response/prediction_collection.rb +48 -0
- data/lib/barometer/utils.rb +17 -0
- data/lib/barometer/utils/address.rb +33 -0
- data/lib/barometer/utils/api.rb +30 -0
- data/lib/barometer/utils/config_reader.rb +40 -0
- data/lib/barometer/utils/get.rb +17 -0
- data/lib/barometer/utils/json_reader.rb +22 -0
- data/lib/barometer/utils/payload.rb +100 -0
- data/lib/barometer/utils/payload_request.rb +37 -0
- data/lib/barometer/utils/post.rb +24 -0
- data/lib/barometer/utils/time.rb +78 -0
- data/lib/barometer/{translations → utils/translations}/zone_codes.yml +0 -0
- data/lib/barometer/utils/versioned_registration.rb +70 -0
- data/lib/barometer/utils/xml_reader.rb +27 -0
- data/lib/barometer/utils/zone_code_lookup.rb +30 -0
- data/lib/barometer/version.rb +1 -1
- data/lib/barometer/weather.rb +44 -173
- data/lib/barometer/weather_service.rb +41 -0
- data/lib/barometer/weather_services/base.rb +50 -0
- data/lib/barometer/weather_services/forecast_io.rb +36 -0
- data/lib/barometer/weather_services/forecast_io/api.rb +22 -0
- data/lib/barometer/weather_services/forecast_io/query.rb +38 -0
- data/lib/barometer/weather_services/forecast_io/response.rb +31 -0
- data/lib/barometer/weather_services/forecast_io/response/current_weather.rb +78 -0
- data/lib/barometer/weather_services/forecast_io/response/forecasted_weather.rb +74 -0
- data/lib/barometer/weather_services/forecast_io/response/location.rb +19 -0
- data/lib/barometer/weather_services/forecast_io/response/timezone.rb +25 -0
- data/lib/barometer/weather_services/noaa.rb +21 -305
- data/lib/barometer/weather_services/noaa/current_api.rb +25 -0
- data/lib/barometer/weather_services/noaa/current_query.rb +30 -0
- data/lib/barometer/weather_services/noaa/current_response.rb +29 -0
- data/lib/barometer/weather_services/noaa/forecast_api.rb +25 -0
- data/lib/barometer/weather_services/noaa/forecast_query.rb +39 -0
- data/lib/barometer/weather_services/noaa/forecast_response.rb +28 -0
- data/lib/barometer/weather_services/noaa/response/current_location.rb +42 -0
- data/lib/barometer/weather_services/noaa/response/current_station.rb +46 -0
- data/lib/barometer/weather_services/noaa/response/current_weather.rb +82 -0
- data/lib/barometer/weather_services/noaa/response/forecasted_weather.rb +90 -0
- data/lib/barometer/weather_services/noaa/response/location.rb +19 -0
- data/lib/barometer/weather_services/noaa/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/response.rb +9 -0
- data/lib/barometer/weather_services/response/location.rb +42 -0
- data/lib/barometer/weather_services/response/time_zone.rb +19 -0
- data/lib/barometer/weather_services/weather_bug.rb +24 -280
- data/lib/barometer/weather_services/weather_bug/current_api.rb +26 -0
- data/lib/barometer/weather_services/weather_bug/current_response.rb +33 -0
- data/lib/barometer/weather_services/weather_bug/forecast_api.rb +26 -0
- data/lib/barometer/weather_services/weather_bug/forecast_response.rb +29 -0
- data/lib/barometer/weather_services/weather_bug/query.rb +42 -0
- data/lib/barometer/weather_services/weather_bug/response/current_weather.rb +82 -0
- data/lib/barometer/weather_services/weather_bug/response/forecasted_weather.rb +67 -0
- data/lib/barometer/weather_services/weather_bug/response/location.rb +23 -0
- data/lib/barometer/weather_services/weather_bug/response/station.rb +43 -0
- data/lib/barometer/weather_services/weather_bug/response/sun.rb +32 -0
- data/lib/barometer/weather_services/weather_bug/response/time_helper.rb +52 -0
- data/lib/barometer/weather_services/weather_bug/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/wunderground_v1.rb +32 -0
- data/lib/barometer/weather_services/wunderground_v1/current_api.rb +21 -0
- data/lib/barometer/weather_services/wunderground_v1/current_response.rb +31 -0
- data/lib/barometer/weather_services/wunderground_v1/forecast_api.rb +21 -0
- data/lib/barometer/weather_services/wunderground_v1/forecast_response.rb +33 -0
- data/lib/barometer/weather_services/wunderground_v1/query.rb +30 -0
- data/lib/barometer/weather_services/wunderground_v1/response/current_weather.rb +92 -0
- data/lib/barometer/weather_services/wunderground_v1/response/forecasted_weather.rb +87 -0
- data/lib/barometer/weather_services/wunderground_v1/response/full_timezone.rb +22 -0
- data/lib/barometer/weather_services/wunderground_v1/response/location.rb +43 -0
- data/lib/barometer/weather_services/wunderground_v1/response/station.rb +39 -0
- data/lib/barometer/weather_services/wunderground_v1/response/sun.rb +53 -0
- data/lib/barometer/weather_services/wunderground_v1/response/timezone.rb +15 -0
- data/lib/barometer/weather_services/yahoo.rb +16 -198
- data/lib/barometer/weather_services/yahoo/api.rb +21 -0
- data/lib/barometer/weather_services/yahoo/query.rb +42 -0
- data/lib/barometer/weather_services/yahoo/response.rb +39 -0
- data/lib/barometer/weather_services/yahoo/response/current_weather.rb +86 -0
- data/lib/barometer/weather_services/yahoo/response/forecasted_weather.rb +71 -0
- data/lib/barometer/weather_services/yahoo/response/location.rb +47 -0
- data/lib/barometer/weather_services/yahoo/response/sun.rb +43 -0
- data/lib/barometer/weather_services/yahoo/response/timezone.rb +15 -0
- data/spec/barometer_spec.rb +18 -120
- data/spec/base_spec.rb +114 -0
- data/spec/cassettes/Converter_FromCoordinatesToNoaaStationId.json +1 -0
- data/spec/cassettes/Converter_FromWeatherIdToGeocode.json +1 -0
- data/spec/cassettes/Converter_FromWoeIdOrIpv4ToGeocode.json +1 -0
- data/spec/cassettes/Converter_ToGeocode.json +1 -0
- data/spec/cassettes/Converter_ToWeatherId.json +1 -0
- data/spec/cassettes/Converter_ToWoeId.json +1 -0
- data/spec/cassettes/Service_FromWeatherId.json +1 -0
- data/spec/cassettes/Service_GoogleGeocode.json +1 -0
- data/spec/cassettes/Service_NoaaStation.json +1 -0
- data/spec/cassettes/Service_ToWeatherId.json +1 -0
- data/spec/cassettes/Service_ToWoeId.json +1 -0
- data/spec/cassettes/Service_YahooGeocode.json +1 -0
- data/spec/cassettes/WeatherService_ForecastIo.json +1 -0
- data/spec/cassettes/WeatherService_Noaa.json +1 -1
- data/spec/cassettes/WeatherService_WeatherBug.json +1 -1
- data/spec/cassettes/WeatherService_WundergroundV1.json +1 -0
- data/spec/cassettes/WeatherService_Yahoo.json +1 -1
- data/spec/data/attributes/distance_spec.rb +60 -0
- data/spec/data/attributes/location_spec.rb +41 -0
- data/spec/data/attributes/pressure_spec.rb +60 -0
- data/spec/data/attributes/sun_spec.rb +33 -0
- data/spec/data/attributes/temperature_spec.rb +60 -0
- data/spec/data/attributes/time_spec.rb +58 -0
- data/spec/data/attributes/vector_spec.rb +43 -0
- data/spec/data/attributes/zone_spec.rb +34 -0
- data/spec/data/convertable_units_spec.rb +299 -0
- data/spec/data/coordinates_spec.rb +15 -0
- data/spec/data/distance_spec.rb +49 -333
- data/spec/data/geo_spec.rb +72 -71
- data/spec/data/location_spec.rb +70 -65
- data/spec/data/pressure_spec.rb +49 -333
- data/spec/data/sun_spec.rb +57 -81
- data/spec/data/temperature_spec.rb +49 -393
- data/spec/data/vector_spec.rb +100 -0
- data/spec/data/zone_spec.rb +199 -266
- data/spec/query/base_spec.rb +296 -0
- data/spec/query/converter_spec.rb +98 -0
- data/spec/query/converters/from_coordinates_to_noaa_station_id_spec.rb +35 -0
- data/spec/query/converters/from_geocode_to_coordinates_spec.rb +25 -0
- data/spec/query/converters/from_short_zipcode_to_zipcode_spec.rb +31 -0
- data/spec/query/converters/from_weather_id_to_geocode_spec.rb +40 -0
- data/spec/query/converters/from_woe_id_or_ipv4_to_geocode_spec.rb +51 -0
- data/spec/query/converters/to_geocode_spec.rb +99 -0
- data/spec/query/converters/to_weather_id_spec.rb +35 -0
- data/spec/query/converters/to_woe_id_spec.rb +74 -0
- data/spec/query/formats/base_spec.rb +15 -0
- data/spec/query/formats/coordinates_spec.rb +13 -0
- data/spec/query/formats/geocode_spec.rb +9 -0
- data/spec/query/formats/icao_spec.rb +20 -0
- data/spec/query/formats/ipv4_address_spec.rb +33 -0
- data/spec/query/formats/noaa_station_id_spec.rb +9 -0
- data/spec/query/formats/postalcode_spec.rb +18 -0
- data/spec/query/formats/short_zipcode_spec.rb +18 -0
- data/spec/query/formats/unknown_spec.rb +9 -0
- data/spec/query/formats/weather_id_spec.rb +31 -0
- data/spec/query/formats/woe_id_spec.rb +45 -0
- data/spec/query/formats/zipcode_spec.rb +18 -0
- data/spec/query/formats_spec.rb +55 -0
- data/spec/query/services/from_weather_id_spec.rb +54 -0
- data/spec/query/services/google_geocode_spec.rb +60 -0
- data/spec/query/services/noaa_station_id_spec.rb +23 -0
- data/spec/query/services/to_weather_id_spec.rb +23 -0
- data/spec/query/services/to_woe_id_spec.rb +51 -0
- data/spec/query/services/yahoo_geocode_spec.rb +72 -0
- data/spec/response/base_spec.rb +103 -0
- data/spec/response/current_spec.rb +33 -0
- data/spec/response/predicition_spec.rb +65 -0
- data/spec/response/prediction_collection_spec.rb +97 -0
- data/spec/spec_helper.rb +14 -12
- data/spec/support/key_file_parser.rb +22 -0
- data/spec/support/matchers/formats.rb +36 -0
- data/spec/support/matchers/have_data.rb +46 -0
- data/spec/support/matchers/have_field.rb +128 -0
- data/spec/support/matchers/have_forecast.rb +46 -0
- data/spec/support/matchers/path.rb +23 -0
- data/spec/support/query_factory.rb +20 -0
- data/spec/utils/address_spec.rb +67 -0
- data/spec/utils/config_reader_spec.rb +157 -0
- data/spec/utils/get_spec.rb +22 -0
- data/spec/utils/payload_request_spec.rb +69 -0
- data/spec/utils/payload_spec.rb +168 -0
- data/spec/utils/post_spec.rb +20 -0
- data/spec/utils/time_spec.rb +93 -0
- data/spec/utils/versioned_registration_spec.rb +105 -0
- data/spec/weather_services/base_spec.rb +116 -0
- data/spec/weather_services/forecast_io_spec.rb +71 -0
- data/spec/weather_services/noaa/current_response_spec.rb +22 -0
- data/spec/weather_services/noaa/forecast_response_spec.rb +33 -0
- data/spec/weather_services/noaa_spec.rb +68 -166
- data/spec/weather_services/weather_bug/current_response_spec.rb +64 -0
- data/spec/weather_services/weather_bug/forecast_response_spec.rb +23 -0
- data/spec/weather_services/weather_bug_spec.rb +62 -202
- data/spec/weather_services/wunderground_v1/current_response_spec.rb +19 -0
- data/spec/weather_services/wunderground_v1/forecast_response_spec.rb +62 -0
- data/spec/weather_services/wunderground_v1_spec.rb +78 -0
- data/spec/weather_services/yahoo/response_spec.rb +73 -0
- data/spec/weather_services/yahoo_spec.rb +52 -135
- data/spec/weather_services_spec.rb +103 -0
- data/spec/weather_spec.rb +167 -347
- metadata +342 -123
- data/.document +0 -5
- data/TODO +0 -60
- data/bin/barometer +0 -441
- data/lib/barometer/data/local_datetime.rb +0 -145
- data/lib/barometer/data/local_time.rb +0 -134
- data/lib/barometer/data/speed.rb +0 -158
- data/lib/barometer/data/units.rb +0 -49
- data/lib/barometer/formats.rb +0 -13
- data/lib/barometer/formats/coordinates.rb +0 -57
- data/lib/barometer/formats/format.rb +0 -64
- data/lib/barometer/formats/geocode.rb +0 -60
- data/lib/barometer/formats/icao.rb +0 -37
- data/lib/barometer/formats/postalcode.rb +0 -22
- data/lib/barometer/formats/short_zipcode.rb +0 -17
- data/lib/barometer/formats/weather_id.rb +0 -92
- data/lib/barometer/formats/woe_id.rb +0 -150
- data/lib/barometer/formats/zipcode.rb +0 -31
- data/lib/barometer/key_file_parser.rb +0 -20
- data/lib/barometer/measurements/measurement.rb +0 -202
- data/lib/barometer/measurements/result.rb +0 -207
- data/lib/barometer/measurements/result_array.rb +0 -75
- data/lib/barometer/services.rb +0 -19
- data/lib/barometer/weather_services/service.rb +0 -189
- data/lib/barometer/weather_services/wunderground.rb +0 -264
- data/lib/barometer/web_services/geocode.rb +0 -34
- data/lib/barometer/web_services/noaa_station_id.rb +0 -53
- data/lib/barometer/web_services/placemaker.rb +0 -95
- data/lib/barometer/web_services/timezone.rb +0 -38
- data/lib/barometer/web_services/weather_id.rb +0 -50
- data/lib/barometer/web_services/web_service.rb +0 -29
- data/spec/cassettes/Barometer.json +0 -1
- data/spec/cassettes/Query.json +0 -1
- data/spec/cassettes/Query_Format_Coordinates.json +0 -1
- data/spec/cassettes/Query_Format_Geocode.json +0 -1
- data/spec/cassettes/Query_Format_WeatherID.json +0 -1
- data/spec/cassettes/Query_Format_WoeID.json +0 -1
- data/spec/cassettes/WeatherService.json +0 -1
- data/spec/cassettes/WeatherService_Wunderground.json +0 -1
- data/spec/cassettes/WebService_Geocode.json +0 -1
- data/spec/cassettes/WebService_NoaaStation.json +0 -1
- data/spec/data/local_datetime_spec.rb +0 -274
- data/spec/data/local_time_spec.rb +0 -239
- data/spec/data/speed_spec.rb +0 -374
- data/spec/data/units_spec.rb +0 -101
- data/spec/formats/coordinates_spec.rb +0 -166
- data/spec/formats/format_spec.rb +0 -74
- data/spec/formats/geocode_spec.rb +0 -163
- data/spec/formats/icao_spec.rb +0 -55
- data/spec/formats/postalcode_spec.rb +0 -53
- data/spec/formats/short_zipcode_spec.rb +0 -47
- data/spec/formats/weather_id_spec.rb +0 -182
- data/spec/formats/woe_id_spec.rb +0 -211
- data/spec/formats/zipcode_spec.rb +0 -103
- data/spec/key_file_parser_spec.rb +0 -28
- data/spec/measurements/measurement_spec.rb +0 -381
- data/spec/measurements/result_array_spec.rb +0 -150
- data/spec/measurements/result_spec.rb +0 -632
- data/spec/query_spec.rb +0 -498
- data/spec/weather_services/services_spec.rb +0 -135
- data/spec/weather_services/wunderground_spec.rb +0 -179
- data/spec/web_services/geocode_spec.rb +0 -31
- data/spec/web_services/noaa_station_id_spec.rb +0 -33
- data/spec/web_services/placemaker_spec.rb +0 -41
- data/spec/web_services/web_services_spec.rb +0 -20
data/.document
DELETED
data/TODO
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
== now
|
2
|
-
- use Yahoo placemaker for geocoding (as exclusive, or as priority for supported conversions)
|
3
|
-
|
4
|
-
== very soon
|
5
|
-
|
6
|
-
- google geocoding terms of service indicate that "a map must be shown" ... what to do?
|
7
|
-
- driver: hamweather
|
8
|
-
- driver: metar
|
9
|
-
- improve code based on metrics
|
10
|
-
- use Geomojo to convert coords to woe_id (when no yahoo key)
|
11
|
-
- remove use of HTTParty, use Net:HTTP and Nokogiri instead
|
12
|
-
|
13
|
-
== soon
|
14
|
-
|
15
|
-
- refactor: data-zone
|
16
|
-
- methods to use service_specific icons/images
|
17
|
-
|
18
|
-
== future
|
19
|
-
|
20
|
-
- Rdoc compatible documentation
|
21
|
-
- add uv, moon, elevation info to current
|
22
|
-
- driver: intellicast
|
23
|
-
- weather.com simple_questions improve answers (use extra data)
|
24
|
-
- make sure you can compare LocalTime to LocalDateTime in LocalTime class
|
25
|
-
|
26
|
-
- be smart, never make duplicate queries
|
27
|
-
- ie. if you are including wunderground, do it first and use the timezone info
|
28
|
-
|
29
|
-
- conversion and weather fetching queries should have hooks to allow
|
30
|
-
for configurable caching via memcache, then web service calls can
|
31
|
-
be cached across multiple measurement instances.
|
32
|
-
|
33
|
-
== bugs
|
34
|
-
|
35
|
-
== refactoring
|
36
|
-
|
37
|
-
- Parsing dates is slow (ie Time.parse)
|
38
|
-
for data parsing with known date/time formats, parse the
|
39
|
-
needed information explicitly
|
40
|
-
|
41
|
-
example:
|
42
|
-
|
43
|
-
_parse_date(text)
|
44
|
-
text =~ /^(\d\d\d\d)-(\d\d)-(\d\d)/
|
45
|
-
Time.new($3,$2,$1)
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
== other weather info
|
50
|
-
|
51
|
-
=== intellicast
|
52
|
-
http://www.intellicast.com/IcastRSS/Signup.aspx
|
53
|
-
http://www.intellicast.com/content/
|
54
|
-
http://www.nws.noaa.gov/mdl/synop/nam.php
|
55
|
-
http://www.hamweather.net/hw3/hw3php/democss/hw3.php?config=&forecast=zandh&icao=PADQ
|
56
|
-
http://www.arl.noaa.gov/READYcmet.php
|
57
|
-
http://www.windguru.cz/int/index.php
|
58
|
-
http://www.nco.ncep.noaa.gov/pmb/products/gfs/
|
59
|
-
http://www.weatherdeveloper.com/2008/01/31/grib2-migration/
|
60
|
-
http://www.cpc.noaa.gov/products/wesley/wgrib2/
|
data/bin/barometer
DELETED
@@ -1,441 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# == Barometer
|
4
|
-
# This is the command line interface to the barometer gem.
|
5
|
-
#
|
6
|
-
# == Examples
|
7
|
-
# This command will measure the weather for the given query.
|
8
|
-
# barometer berlin
|
9
|
-
#
|
10
|
-
# Other examples:
|
11
|
-
# barometer --yahoo 90210
|
12
|
-
# barometer --verbose 'new york'
|
13
|
-
#
|
14
|
-
# == Usage
|
15
|
-
# barometer [options] query
|
16
|
-
#
|
17
|
-
# For help use: barometer -h
|
18
|
-
#
|
19
|
-
# Options:
|
20
|
-
# -v, --version Display the version, then exit
|
21
|
-
# -V, --verbose Verbose output
|
22
|
-
# -t, --timeout seconds until service queries will timeout
|
23
|
-
# -g, --geocode Force Geocoding of query
|
24
|
-
# -z, --timezone Enhance Timezone
|
25
|
-
# -m, --metric measure in metric
|
26
|
-
# -i, --imperial measure in imperial
|
27
|
-
# --wunderground add wunderground as a source
|
28
|
-
# --yahoo add yahoo as a source
|
29
|
-
# --bug add weather_bug as a source
|
30
|
-
# --noaa add NOAA as a source
|
31
|
-
# -p, --pop pop threshold used to determine wet?
|
32
|
-
# -s, --wind wind speed threshold used to determine windy?
|
33
|
-
# -a, --at time/date used to determine when to calculate summary
|
34
|
-
#
|
35
|
-
# == Author
|
36
|
-
# Mark G
|
37
|
-
# http://github.com/attack/barometer
|
38
|
-
#
|
39
|
-
# == Copyright
|
40
|
-
# Copyright (c) 2009-2013 Mark G. Licensed under the MIT License:
|
41
|
-
# http://www.opensource.org/licenses/mit-license.php
|
42
|
-
|
43
|
-
require 'rubygems'
|
44
|
-
require 'barometer'
|
45
|
-
#require '/Users/mark/code/gems/barometer/lib/barometer'
|
46
|
-
|
47
|
-
require 'optparse'
|
48
|
-
require 'ostruct'
|
49
|
-
require 'time'
|
50
|
-
require 'date'
|
51
|
-
require 'yaml'
|
52
|
-
|
53
|
-
# file where API keys are stored
|
54
|
-
KEY_FILE = File.expand_path(File.join('~', '.barometer'))
|
55
|
-
|
56
|
-
class App
|
57
|
-
attr_reader :options
|
58
|
-
|
59
|
-
def initialize(arguments, stdin)
|
60
|
-
@arguments = arguments.dup
|
61
|
-
|
62
|
-
# Set defaults
|
63
|
-
@options = OpenStruct.new
|
64
|
-
@options.timeout = 15
|
65
|
-
@options.geocode = false
|
66
|
-
@options.timezone = false
|
67
|
-
@options.metric = true
|
68
|
-
@options.sources = []
|
69
|
-
@options.verbose = false
|
70
|
-
@options.at = nil
|
71
|
-
@options.default = true
|
72
|
-
|
73
|
-
# thresholds
|
74
|
-
@options.windy_m = 10
|
75
|
-
@options.windy_i = 7
|
76
|
-
@options.pop = 50
|
77
|
-
end
|
78
|
-
|
79
|
-
# Parse options, check arguments, then process the command
|
80
|
-
def run
|
81
|
-
if parsed_options? && arguments_valid?
|
82
|
-
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
83
|
-
output_options if @options.verbose # [Optional]
|
84
|
-
|
85
|
-
process_command
|
86
|
-
|
87
|
-
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
88
|
-
else
|
89
|
-
output_usage
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
protected
|
94
|
-
|
95
|
-
# future options
|
96
|
-
#
|
97
|
-
# time: -a --at
|
98
|
-
#
|
99
|
-
def parsed_options?
|
100
|
-
# Specify options
|
101
|
-
opt = OptionParser.new
|
102
|
-
opt.on('-v', '--version') { output_version ; exit 0 }
|
103
|
-
opt.on('-h', '--help') { output_help }
|
104
|
-
opt.on('-V', '--verbose') { @options.verbose = true }
|
105
|
-
opt.on('-a n', '--at n') {|n| @options.at = Time.parse(n.to_s) }
|
106
|
-
opt.on('-t n', '--timeout n') {|n| @options.timeout = n }
|
107
|
-
opt.on('-g', '--geocode') { @options.geocode = true }
|
108
|
-
opt.on('-z', '--timezone') { @options.timezone = true }
|
109
|
-
opt.on('-m', '--metric') { @options.metric = true }
|
110
|
-
opt.on('-i', '--imperial') { @options.metric = false }
|
111
|
-
opt.on('--wunderground') { @options.sources << :wunderground; @options.default = false }
|
112
|
-
opt.on('--yahoo') { @options.sources << :yahoo; @options.default = false }
|
113
|
-
opt.on('--bug') { @options.sources << :weather_bug; @options.default = false }
|
114
|
-
opt.on('--noaa') { @options.sources << :noaa; @options.default = false }
|
115
|
-
opt.on('-p n', '--pop n') {|n| @options.pop = n.to_i || 50 }
|
116
|
-
opt.on('-s n', '--wind n') {|n| @options.metric ? @options.windy_m = n.to_f || 10 : @options.windy_i = n.to_f || 7 }
|
117
|
-
|
118
|
-
opt.parse!(@arguments) rescue return false
|
119
|
-
|
120
|
-
process_options
|
121
|
-
true
|
122
|
-
end
|
123
|
-
|
124
|
-
def config_weather_bug
|
125
|
-
if File.exists?(KEY_FILE)
|
126
|
-
keys = YAML.load_file(KEY_FILE)
|
127
|
-
if keys["weather_bug"] && keys["weather_bug"]["code"]
|
128
|
-
code = keys["weather_bug"]["code"].to_s
|
129
|
-
else
|
130
|
-
bug_key_message
|
131
|
-
exit
|
132
|
-
end
|
133
|
-
else
|
134
|
-
File.open(KEY_FILE, 'w') {|f| f << "\nweather_bug:\n code: API_CODE" }
|
135
|
-
bug_key_message
|
136
|
-
exit
|
137
|
-
end
|
138
|
-
{ :weather_bug => { :keys => { :code => code } } }
|
139
|
-
end
|
140
|
-
|
141
|
-
# Performs post-parse processing on options
|
142
|
-
def process_options
|
143
|
-
@options.sources << :wunderground if @options.default
|
144
|
-
@options.sources = @options.sources.uniq
|
145
|
-
Barometer.force_geocode = @options.geocode
|
146
|
-
Barometer.enhance_timezone = @options.timezone
|
147
|
-
if @options.sources.include?(:weather_bug)
|
148
|
-
@options.sources.delete(:weather_bug)
|
149
|
-
@options.sources << config_weather_bug
|
150
|
-
end
|
151
|
-
Barometer.config = { 1 => @options.sources }
|
152
|
-
Barometer.timeout = @options.timeout
|
153
|
-
end
|
154
|
-
|
155
|
-
def output_options
|
156
|
-
puts "Options:\n"
|
157
|
-
|
158
|
-
@options.marshal_dump.each do |name, val|
|
159
|
-
puts " #{name} = #{val}"
|
160
|
-
end
|
161
|
-
puts
|
162
|
-
end
|
163
|
-
|
164
|
-
# True if required arguments were provided
|
165
|
-
def arguments_valid?
|
166
|
-
true if (@arguments.length >= 1 || @options.web)
|
167
|
-
end
|
168
|
-
|
169
|
-
def output_help
|
170
|
-
output_version
|
171
|
-
end
|
172
|
-
|
173
|
-
def output_usage
|
174
|
-
puts "Usage: "
|
175
|
-
puts "barometer [options] query"
|
176
|
-
puts
|
177
|
-
puts "For help use: barometer -h"
|
178
|
-
puts
|
179
|
-
puts "options:"
|
180
|
-
puts " -v, --version Display the version, then exit"
|
181
|
-
puts " -V, --verbose Verbose output"
|
182
|
-
puts " -t, --timeout seconds until service queries will timeout"
|
183
|
-
puts " -g, --geocode Force Geocoding of query"
|
184
|
-
puts " -z, --timezone Force timezone query"
|
185
|
-
puts " -m, --metric measure in metric"
|
186
|
-
puts " -i, --imperial measure in imperial"
|
187
|
-
puts " --wunderground add wunderground as a source"
|
188
|
-
puts " --yahoo add yahoo as a source"
|
189
|
-
puts " --bug add weather_bug as a source"
|
190
|
-
puts " --noaa add NOAA as a source"
|
191
|
-
puts " -p, --pop pop threshold used to determine wet?"
|
192
|
-
puts " -s, --wind wind speed threshold used to determine windy?"
|
193
|
-
puts " -a, --at time/date used to determine when to calculate summary"
|
194
|
-
end
|
195
|
-
|
196
|
-
def output_version
|
197
|
-
puts "#{File.basename(__FILE__)} version #{Barometer::VERSION}"
|
198
|
-
end
|
199
|
-
|
200
|
-
def process_command
|
201
|
-
barometer = Barometer.new(@arguments.join(" "))
|
202
|
-
begin
|
203
|
-
if @options.verbose
|
204
|
-
Barometer::debug!
|
205
|
-
div(char="*")
|
206
|
-
puts "DEBUG LOG"
|
207
|
-
blank
|
208
|
-
end
|
209
|
-
barometer.measure(@options.metric) if barometer
|
210
|
-
blank if @options.verbose
|
211
|
-
pretty_output(barometer) if barometer.weather
|
212
|
-
rescue Barometer::OutOfSources
|
213
|
-
puts
|
214
|
-
puts " SORRY: your query did not provide any results"
|
215
|
-
puts
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
#
|
221
|
-
# HELPERS
|
222
|
-
#
|
223
|
-
|
224
|
-
@level = 1
|
225
|
-
|
226
|
-
def y(value)
|
227
|
-
value ? "yes" : "no"
|
228
|
-
end
|
229
|
-
|
230
|
-
def div(char="#")
|
231
|
-
puts char*50
|
232
|
-
end
|
233
|
-
|
234
|
-
def title(title, level=1)
|
235
|
-
@level = level
|
236
|
-
puts "#{" " * @level}-- #{title} --"
|
237
|
-
end
|
238
|
-
|
239
|
-
def value(title, value)
|
240
|
-
puts "#{" " * @level}#{title}: #{value}" unless value.nil?
|
241
|
-
end
|
242
|
-
|
243
|
-
def blank
|
244
|
-
puts
|
245
|
-
end
|
246
|
-
|
247
|
-
def section(title, level=1, show_blank=true)
|
248
|
-
@level = level
|
249
|
-
title(title, level); yield; blank if show_blank
|
250
|
-
end
|
251
|
-
|
252
|
-
def pretty_hash(hash)
|
253
|
-
return unless hash.is_a?(Hash)
|
254
|
-
hash.each { |k,v| value(k,v) }
|
255
|
-
end
|
256
|
-
|
257
|
-
def pretty_summary(s)
|
258
|
-
return unless s
|
259
|
-
section("AVERAGES") do
|
260
|
-
pretty_hash({
|
261
|
-
"humidity" => s.humidity.to_i, "temperature" => s.temperature,
|
262
|
-
"wind" => s.wind, "pressure" => s.pressure,
|
263
|
-
"dew_point" => s.dew_point, "heat_index" => s.heat_index,
|
264
|
-
"wind_chill" => s.wind_chill, "visibility" => s.visibility })
|
265
|
-
end
|
266
|
-
section("SUMMARY#{ " (@ #{@options.at})" if @options.at }") do
|
267
|
-
pretty_hash({
|
268
|
-
"day?" => s.day?(@options.at), "sunny?" => s.sunny?(@options.at),
|
269
|
-
"windy?" => s.windy?(@options.at, @options.metric ? @options.windy_m : @options.windy_i),
|
270
|
-
"wet?" => s.wet?(@options.at, @options.pop) })
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
def pretty_query(q)
|
275
|
-
return unless q
|
276
|
-
section("ORIGINAL QUERY", 1) do
|
277
|
-
pretty_hash({
|
278
|
-
"Query" => q.q, "Format" => q.format,
|
279
|
-
"Country Code" => q.country_code })
|
280
|
-
end
|
281
|
-
if q.geo
|
282
|
-
section("GEO", 2) do
|
283
|
-
pretty_hash({
|
284
|
-
"Address" => q.geo.address, "Query" => q.geo.query,
|
285
|
-
"Locality" => q.geo.locality, "Region" => q.geo.region,
|
286
|
-
"Country" => q.geo.country, "Country Code" => q.geo.country_code,
|
287
|
-
"Latitude" => q.geo.latitude, "Longitude" => q.geo.longitude })
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
def pretty_location(l)
|
293
|
-
return unless l
|
294
|
-
section("LOCATION", 2) do
|
295
|
-
pretty_hash({
|
296
|
-
"ID" => l.id, "Name" => l.name,
|
297
|
-
"City" => l.city, "State Name" => l.state_name,
|
298
|
-
"State Code" => l.state_code, "Country" => l.country,
|
299
|
-
"Country Code" => l.country_code, "Zip Code" => l.zip_code,
|
300
|
-
"Latitude" => l.latitude, "Longitude" => l.longitude })
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
def pretty_station(s)
|
305
|
-
return unless s
|
306
|
-
section("STATION", 2) do
|
307
|
-
pretty_hash({
|
308
|
-
"ID" => s.id, "Name" => s.name,
|
309
|
-
"City" => s.city, "State Name" => s.state_name,
|
310
|
-
"State Code" => s.state_code, "Country" => s.country,
|
311
|
-
"Country Code" => s.country_code, "Zip Code" => s.zip_code,
|
312
|
-
"Latitude" => s.latitude, "Longitude" => s.longitude })
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
def pretty_timezone(t)
|
317
|
-
return unless t
|
318
|
-
section("TIMEZONE", 2) do
|
319
|
-
pretty_hash({ "Long" => t.full, "Code" => t.code, "DST?" => t.dst?,
|
320
|
-
"Now" => t.now(true), "Today" => t.today })
|
321
|
-
end
|
322
|
-
end
|
323
|
-
|
324
|
-
def pretty_current(c)
|
325
|
-
return unless c
|
326
|
-
section("CURRENT", 2) do
|
327
|
-
pretty_hash({
|
328
|
-
"Measured at" => c.current_at, "Updated at" => c.updated_at.to_s(true),
|
329
|
-
"Humidity" => c.humidity, "Icon" => c.icon,
|
330
|
-
"Condition" => c.condition, "Temperature" => c.temperature,
|
331
|
-
"Dew Point" => c.dew_point, "Heat Index" => c.heat_index,
|
332
|
-
"Pressure" => c.pressure, "Visibility" => c.visibility,
|
333
|
-
"Wind Chill" => c.wind_chill })
|
334
|
-
pretty_hash({ "Wind" => c.wind, "Wind Direction" => c.wind.direction,
|
335
|
-
"Wind Degrees" => c.wind.degrees }) if c.wind
|
336
|
-
pretty_hash({ "Sun Rise" => c.sun.rise, "Sun Set" => c.sun.set }) if c.sun
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
def pretty_forecast(f)
|
341
|
-
return unless f
|
342
|
-
section("FOR: #{f.date}", 3) do
|
343
|
-
pretty_hash({
|
344
|
-
"Valid From" => f.valid_start_date.to_s(true),
|
345
|
-
"Valid Until" => f.valid_end_date.to_s(true),
|
346
|
-
"Icon" => f.icon, "Description" => f.description,
|
347
|
-
"Condition" => f.condition, "High" => f.high,
|
348
|
-
"Low" => f.low, "POP" => f.pop, "Humidity" => f.humidity })
|
349
|
-
pretty_hash({ "Wind" => f.wind, "Wind Direction" => f.wind.direction,
|
350
|
-
"Wind Degrees" => f.wind.degrees }) if f.wind
|
351
|
-
pretty_hash({ "Sun Rise" => f.sun.rise, "Sun Set" => f.sun.set }) if f.sun
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
def pretty_forecasts(forecasts)
|
356
|
-
return unless forecasts
|
357
|
-
section("FORECAST(s)", 3, false) do
|
358
|
-
blank
|
359
|
-
forecasts.each do |forecast|
|
360
|
-
pretty_forecast(forecast)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
def pretty_measurement(m)
|
366
|
-
return unless m
|
367
|
-
section(m.source.to_s, 1) do
|
368
|
-
pretty_hash({
|
369
|
-
"Measured At" => m.measured_at,
|
370
|
-
"Source" => m.source, "Time Stamp" => m.utc_time_stamp,
|
371
|
-
"Metric" => m.metric?, "Success" => m.success?,
|
372
|
-
"Service Time" => "#{(m.end_at - m.start_at)} s" })
|
373
|
-
end
|
374
|
-
section("MODIFIED QUERY", 2) do
|
375
|
-
pretty_hash({ "Query" => m.query, "Format" => m.format })
|
376
|
-
end
|
377
|
-
pretty_location(m.location)
|
378
|
-
pretty_station(m.station)
|
379
|
-
pretty_timezone(m.timezone)
|
380
|
-
pretty_current(m.current)
|
381
|
-
pretty_forecasts(m.forecast)
|
382
|
-
end
|
383
|
-
|
384
|
-
def pretty_measurements(w)
|
385
|
-
return unless w
|
386
|
-
section("MEASUREMENTS", 1) do
|
387
|
-
blank
|
388
|
-
w.measurements.each do |m|
|
389
|
-
pretty_measurement(m)
|
390
|
-
end
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
def pretty_info(w)
|
395
|
-
title("INFO", 1)
|
396
|
-
value("GitHub", "http://github.com/attack/barometer")
|
397
|
-
value("Barometer Version", Barometer::VERSION)
|
398
|
-
value("Total Time", "#{(w.end_at - w.start_at)} s")
|
399
|
-
end
|
400
|
-
|
401
|
-
def pretty_output(barometer)
|
402
|
-
weather = barometer.weather
|
403
|
-
if weather
|
404
|
-
div
|
405
|
-
puts "#"
|
406
|
-
puts "# #{weather.default.location.name || barometer.query.q}"
|
407
|
-
puts "#"
|
408
|
-
div
|
409
|
-
blank
|
410
|
-
pretty_summary(weather)
|
411
|
-
pretty_query(barometer.query)
|
412
|
-
pretty_measurements(weather)
|
413
|
-
pretty_info(weather)
|
414
|
-
div("-")
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
def bug_key_message
|
419
|
-
puts
|
420
|
-
puts "MISSING KEYS !!!"
|
421
|
-
puts "Please update the key_file '#{KEY_FILE}' with your weather_bug api key"
|
422
|
-
puts "Get it here: ???"
|
423
|
-
puts "Then, add these lines to the file:"
|
424
|
-
puts "weather_bug:"
|
425
|
-
puts " code: API_CODE"
|
426
|
-
puts
|
427
|
-
end
|
428
|
-
|
429
|
-
# set API keys
|
430
|
-
if File.exists?(KEY_FILE)
|
431
|
-
keys = YAML.load_file(KEY_FILE)
|
432
|
-
if keys["yahoo"] && keys["yahoo"]["app_id"]
|
433
|
-
Barometer.yahoo_placemaker_app_id = keys["yahoo"]["app_id"]
|
434
|
-
end
|
435
|
-
else
|
436
|
-
File.open(KEY_FILE, 'w') {|f| f << "yahoo:\n app_id: YOUR_KEY_KERE" }
|
437
|
-
end
|
438
|
-
|
439
|
-
# Create and run the application
|
440
|
-
app = App.new(ARGV, STDIN)
|
441
|
-
app.run
|