lbweather 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 079b5402d0410ac2fedc03140e7e7bbc7ca7fe2a
4
+ data.tar.gz: 23fda8b93f0164d686ba07c19c63bbf4b190db34
5
+ SHA512:
6
+ metadata.gz: f4586598a9108e35c2a8edfcea80b90c1acd5e590d0b8aa5bd3092540a3d5333ecd560d7293eb3c31de5966f4b4690524ad462352b906509fe0b116daf996d06
7
+ data.tar.gz: 97a3c9aae4225119c5744fa3d142ead266d60fa4625e86c1b4747c420fd54384fdcfdf22a01cce5d02cb9ec6e430bae56775a797bbe25b8ca13a14833434cf4a
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'weather'
4
+
5
+ option_parser = Weather::CLI.new
6
+ forecaster = Weather::Forecaster.new
7
+ geoencoder = Weather::GeoEncoder.new
8
+
9
+ options = option_parser.parse(ARGV)
10
+
11
+ if options[:address] # We have specificed an address. Fetch for that address.
12
+ geolocation_attempt = geoencoder.geoencode_address(options[:address])
13
+
14
+ location_coordinates = geolocation_attempt[0].data["geometry"]["location"]
15
+
16
+ forecaster.forecast({"latitude" => location_coordinates["lat"], "longitude" => location_coordinates["lng"]})
17
+ else
18
+ forecaster.forecast
19
+ end
20
+
@@ -0,0 +1,15 @@
1
+ require "weather/version"
2
+ require "weather/forecast"
3
+ require "weather/geocode"
4
+ require "weather/cli"
5
+
6
+ require "forecast_io"
7
+ require "geocoder"
8
+ require "yaml"
9
+ require "optparse"
10
+ require "unirest"
11
+ require "json"
12
+
13
+ module Weather
14
+
15
+ end
@@ -0,0 +1,21 @@
1
+ module Weather
2
+ class CLI
3
+ def parse(args)
4
+ options = {}
5
+
6
+ OptionParser.new do |opts|
7
+ opts.banner = "Usage: weather [options]"
8
+
9
+ opts.separator ""
10
+ opts.separator "Specific options:"
11
+
12
+ opts.on("-a", "--address [STRING", "Send a string address for which to find weather.") do |ext|
13
+ options[:address] = ext
14
+ end
15
+
16
+ end.parse!
17
+
18
+ options
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ module Weather
2
+ class Forecaster
3
+ include Weather
4
+
5
+ def forecast(coordinates=nil)
6
+ config = YAML::load_file(ENV['HOME']+'/.weather/config.yaml')
7
+
8
+ ForecastIO.configure do |configuration|
9
+ configuration.api_key = config["forecastio"]["API_KEY"]
10
+ end
11
+
12
+ begin
13
+ if coordinates
14
+ forecast = ForecastIO.forecast(coordinates["latitude"], coordinates["longitude"])
15
+ else # Use coordinates in configuration file.
16
+ if config["personal"]
17
+ latitude = config["personal"]["latitude"]
18
+ longitude = config["personal"]["longitude"]
19
+ end
20
+ if latitude.nil? or longitude.nil?
21
+ r = JSON.parse((Unirest.get "http://ipinfo.io/json").raw_body)
22
+ latitude, longitude = r["loc"].split(',')
23
+ end
24
+ forecast = ForecastIO.forecast(latitude, longitude)
25
+ end
26
+
27
+ puts "It's currently #{forecast.currently.summary.downcase} and feels like #{forecast.currently.apparentTemperature}°."
28
+ puts "Short-term, it's going to be #{forecast.minutely.summary.downcase} #{forecast.hourly.summary} #{forecast.daily.summary}"
29
+ rescue Faraday::ConnectionFailed
30
+ puts "You don't seem to be connected to the Internet. Loser."
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ module Weather
2
+ class GeoEncoder
3
+
4
+ def geoencode_address(address)
5
+ Geocoder.search(address)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Weather
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lbweather
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Linell Bonnette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: forecast_io
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: geocoder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: unirest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Displays the current weather.
98
+ email:
99
+ - tlbonnette@gmail.com
100
+ executables:
101
+ - weather
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - bin/weather
106
+ - lib/weather.rb
107
+ - lib/weather/cli.rb
108
+ - lib/weather/forecast.rb
109
+ - lib/weather/geocode.rb
110
+ - lib/weather/version.rb
111
+ homepage: https://github.com/Linell/Weather
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.1
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Displays the current weather forecast.
135
+ test_files: []
136
+ has_rdoc: