meteo 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGES +5 -0
- data/Gemfile +23 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +43 -0
- data/bin/meteo +7 -0
- data/bin/meteo.bat +6 -0
- data/lib/meteo/meteo.rb +19 -0
- data/lib/meteo/meteo_cli.rb +29 -0
- data/lib/meteo/reporter.rb +94 -0
- data/lib/meteo/version.rb +3 -0
- data/lib/meteo.rb +1 -0
- data/meteo.gemspec.erb +22 -0
- data/spec/meteo_spec.rb +34 -0
- data/spec/spec_helper.rb +1 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Njg2ODIxYjczMjk3ZGZiZjliNTdkZjg5ZjBkYjMwYTkxZGE2ZmU0MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzA1YzczOTg5YjUyNjYxNmQzNzQxODdkMDM3ZGM0YmVlZDI2YjVkZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjJiNDJkNzEzYmJmY2NiM2FhNTU3MDFmNzVlNDJiM2ZiZjA3N2NjMGJiYmEy
|
10
|
+
M2MxYzg3N2I3MGU1OTI2MjQ3NzU0NzA1ZGUxNzcyYmRlOWJhZTUxZjQ5YmI4
|
11
|
+
MzZjYTM1OGZhYTMzNTY3NjQ0MTBjMTcxMzk3YjMyNDVlYTI4ZmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWM0MTNjMGJhYmMyNTA2ZTk0NjNhZTVjMmUzMTc2OTgzNDc1YWEzNWVlMzdj
|
14
|
+
OTBiYWM0NWY2NGJiOWEyYjdjNmE5MDM5OWVhMmI5MmNiNWY0Y2IyNTc0MTMz
|
15
|
+
NTc3MmFlY2MzZDMyNWM5YjIyOWM0Y2VhMmMyZjRjN2VmNDZjNGU=
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
meteo
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3
|
data/CHANGES
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
group :default do
|
4
|
+
gem "thor"
|
5
|
+
end
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "gemspec_deps_gen"
|
9
|
+
gem "gemcutter"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem "mocha", :require => false
|
14
|
+
gem "rspec"
|
15
|
+
gem "awesome_print"
|
16
|
+
end
|
17
|
+
|
18
|
+
#group :debug do
|
19
|
+
# gem "debugger-ruby_core_source"
|
20
|
+
# gem "ruby-debug-base19x", "0.11.30.pre12"
|
21
|
+
# gem "ruby-debug-ide", "0.4.17"
|
22
|
+
#end
|
23
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alexander Shvets
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Meteo
|
2
|
+
|
3
|
+
Provides command line access to OpenWeatherMap service
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'meteo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install meteo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "meteo/version"
|
7
|
+
require "gemspec_deps_gen/gemspec_deps_gen"
|
8
|
+
|
9
|
+
version = Meteo::VERSION
|
10
|
+
project_name = File.basename(Dir.pwd)
|
11
|
+
|
12
|
+
task :gen do
|
13
|
+
generator = GemspecDepsGen.new
|
14
|
+
|
15
|
+
generator.generate_dependencies "spec", "#{project_name}.gemspec.erb", "#{project_name}.gemspec"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :build => :gen do
|
19
|
+
system "gem build #{project_name}.gemspec"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :install do
|
23
|
+
system "gem install #{project_name}-#{version}.gem"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :uninstall do
|
27
|
+
system "gem uninstall #{project_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
task :release => :build do
|
31
|
+
system "gem push #{project_name}-#{version}.gem"
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new do |task|
|
35
|
+
task.pattern = 'spec/**/*_spec.rb'
|
36
|
+
task.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
task :fix_debug do
|
40
|
+
system "mkdir -p $GEM_HOME/gems/debugger-ruby_core_source-1.2.3/lib"
|
41
|
+
system "cp -R ~/debugger-ruby_core_source/lib $GEM_HOME/gems/debugger-ruby_core_source-1.2.3"
|
42
|
+
end
|
43
|
+
|
data/bin/meteo
ADDED
data/bin/meteo.bat
ADDED
data/lib/meteo/meteo.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class Meteo
|
4
|
+
OPEN_WEATHER_MAP_SERVICE_URL = 'http://api.openweathermap.org/data/2.5/weather'
|
5
|
+
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@url = OPEN_WEATHER_MAP_SERVICE_URL
|
10
|
+
end
|
11
|
+
|
12
|
+
def quote location, units
|
13
|
+
quote_url = "#{url}?q=#{location}%20nj&units=#{units}"
|
14
|
+
|
15
|
+
uri = URI.parse(URI.escape(quote_url))
|
16
|
+
|
17
|
+
Net::HTTP.get(uri)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "thor"
|
2
|
+
require 'json'
|
3
|
+
require 'meteo'
|
4
|
+
require 'meteo/reporter'
|
5
|
+
|
6
|
+
class MeteoCLI < Thor
|
7
|
+
include Reporter
|
8
|
+
|
9
|
+
desc "quote location", "quote weather for location"
|
10
|
+
long_desc <<-LONGDESC
|
11
|
+
`meteo` will print weather quote for requested city.
|
12
|
+
|
13
|
+
You can optionally specify a second parameter, which will print
|
14
|
+
out a from message as well.
|
15
|
+
|
16
|
+
> $ meteo quote "plainsboro, nj"
|
17
|
+
LONGDESC
|
18
|
+
option :units
|
19
|
+
def quote(location)
|
20
|
+
units = options[:units] ? options[:units] : "imperial"
|
21
|
+
|
22
|
+
service = Meteo.new
|
23
|
+
|
24
|
+
response = JSON.parse(service.quote(location, units))
|
25
|
+
|
26
|
+
puts report(response, units).join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Reporter
|
4
|
+
def report(response, units)
|
5
|
+
sunrise = response['sys']['sunrise']
|
6
|
+
sunset = response['sys']['sunset']
|
7
|
+
|
8
|
+
pressure = response['main']['pressure']
|
9
|
+
|
10
|
+
city = response['name']
|
11
|
+
temperature = response['main']['temp']
|
12
|
+
humidity = response['main']['humidity']
|
13
|
+
|
14
|
+
sky = response['weather'][0]['main']
|
15
|
+
wind = response['wind']['speed']
|
16
|
+
|
17
|
+
current_time = Time.now.to_i
|
18
|
+
|
19
|
+
if current_time >= sunset or current_time <= sunrise
|
20
|
+
period = 'night'
|
21
|
+
else
|
22
|
+
period = 'day'
|
23
|
+
end
|
24
|
+
|
25
|
+
case units
|
26
|
+
when 'metric'
|
27
|
+
scale = "°C"
|
28
|
+
speed_unit = "m/s"
|
29
|
+
pressure_unit = "hPa"
|
30
|
+
pressure = sprintf('%.0f', pressure)
|
31
|
+
when 'imperial'
|
32
|
+
scale = "°F"
|
33
|
+
speed_unit = "mph"
|
34
|
+
pressure_unit = "inHg"
|
35
|
+
pressure = sprintf('%.2f', pressure*0.0295)
|
36
|
+
else
|
37
|
+
# type code here
|
38
|
+
end
|
39
|
+
|
40
|
+
icon = self.send(weather(sky, period))
|
41
|
+
|
42
|
+
background = "\033[44m"
|
43
|
+
dashes = "\033[34m-"
|
44
|
+
text = "\033[36;1m"
|
45
|
+
delimiter = "\033[35m=>"
|
46
|
+
data = "\033[33;1m"
|
47
|
+
stop = "\033[0m"
|
48
|
+
|
49
|
+
%W(
|
50
|
+
#{background}#{text}#{icon}
|
51
|
+
#{city} #{delimiter}#{data}
|
52
|
+
#{text}Temperature #{data}#{temperature}#{scale}
|
53
|
+
#{text}Humidity #{data}#{humidity}%
|
54
|
+
#{text}Wind #{data}#{wind}#{speed_unit}
|
55
|
+
#{text}Pressure #{data}#{pressure} #{pressure_unit}
|
56
|
+
#{text}Sunrise #{data}#{Time.at(sunrise).strftime('%I:%M:%S%p')}
|
57
|
+
#{text}Sunset #{data}#{Time.at(sunset).strftime('%I:%M:%S%p')}#{stop}
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def weather sky, period
|
62
|
+
case sky
|
63
|
+
when 'Clear'
|
64
|
+
(period == "night") ? 'moon' : 'sun'
|
65
|
+
|
66
|
+
when 'Clouds'
|
67
|
+
"clouds"
|
68
|
+
|
69
|
+
when 'Rain'
|
70
|
+
"rain"
|
71
|
+
|
72
|
+
when 'Fog'
|
73
|
+
"fog"
|
74
|
+
else
|
75
|
+
(period == "night") ? 'moon' : 'sun'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#def colorize(text, color_code)
|
80
|
+
# "\e[#{color_code}#{text}\e[0m"
|
81
|
+
#end
|
82
|
+
|
83
|
+
def sun
|
84
|
+
"\033[33;1m\xe2\x98\x80"
|
85
|
+
end
|
86
|
+
|
87
|
+
def moon
|
88
|
+
"\033[36m\xe2\x98\xbd"
|
89
|
+
end
|
90
|
+
|
91
|
+
def clouds
|
92
|
+
"\033[37;1m\xe2\x98\x81"
|
93
|
+
end
|
94
|
+
end
|
data/lib/meteo.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "meteo/meteo"
|
data/meteo.gemspec.erb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/lib/meteo/version')
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "meteo"
|
7
|
+
spec.summary = %q{Provides command line access to OpenWeatherMap service.}
|
8
|
+
spec.description = %q{Provides command line access to OpenWeatherMap service.}
|
9
|
+
spec.email = "alexander.shvets@gmail.com"
|
10
|
+
spec.authors = ["Alexander Shvets"]
|
11
|
+
spec.homepage = "http://github.com/shvets/meteo"
|
12
|
+
spec.executables = ["meteo"]
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($\)
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
spec.version = Meteo::VERSION
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
<%= project_dependencies %>
|
21
|
+
end
|
22
|
+
|
data/spec/meteo_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# translate_spec.rb
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
|
5
|
+
require 'meteo'
|
6
|
+
require 'json'
|
7
|
+
require 'awesome_print'
|
8
|
+
|
9
|
+
describe Meteo do
|
10
|
+
describe "#quote" do
|
11
|
+
it "gets the quote" do
|
12
|
+
result = JSON.parse(subject.quote("plainsboro, nj", "imperial"))
|
13
|
+
|
14
|
+
ap result
|
15
|
+
|
16
|
+
expect(result['sys']['country']).to eq("United States of America")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#it "should raise an error if one of parameters is missing" do
|
21
|
+
# expect { subject.meteo(nil, :ru) }.to raise_error
|
22
|
+
#
|
23
|
+
# expect { subject.meteo(:en, nil) }.to raise_error
|
24
|
+
#
|
25
|
+
# expect { subject.meteo(:en, :ru, nil) }.to raise_error
|
26
|
+
#end
|
27
|
+
#
|
28
|
+
#it "should meteo test string from one language to another" do
|
29
|
+
# r = subject.meteo(:en, :ru, "hello world!")
|
30
|
+
# puts r
|
31
|
+
# r.size.should be > 0
|
32
|
+
#end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$: << File.expand_path('../lib', File.dirname(__FILE__))
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: meteo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Shvets
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gemspec_deps_gen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: gemcutter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Provides command line access to OpenWeatherMap service.
|
56
|
+
email: alexander.shvets@gmail.com
|
57
|
+
executables:
|
58
|
+
- meteo
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .ruby-gemset
|
64
|
+
- .ruby-version
|
65
|
+
- CHANGES
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/meteo
|
71
|
+
- bin/meteo.bat
|
72
|
+
- lib/meteo.rb
|
73
|
+
- lib/meteo/meteo.rb
|
74
|
+
- lib/meteo/meteo_cli.rb
|
75
|
+
- lib/meteo/reporter.rb
|
76
|
+
- lib/meteo/version.rb
|
77
|
+
- meteo.gemspec.erb
|
78
|
+
- spec/meteo_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: http://github.com/shvets/meteo
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.1.2
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Provides command line access to OpenWeatherMap service.
|
104
|
+
test_files:
|
105
|
+
- spec/meteo_spec.rb
|
106
|
+
- spec/spec_helper.rb
|