exif_weather 0.0.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.
- data/.gitignore +18 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +1 -0
- data/exif_weather.gemspec +25 -0
- data/lib/exif_weather.rb +20 -0
- data/lib/exif_weather/version.rb +3 -0
- data/spec/exif_weather_spec.rb +23 -0
- data/spec/gps.jpg +0 -0
- data/spec/no_gps.jpg +0 -0
- data/spec/no_lat.jpg +0 -0
- data/spec/no_lon.jpg +0 -0
- metadata +136 -0
data/.gitignore
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lib/*
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Toshiyuki Suzumura
|
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,50 @@
|
|
1
|
+
# ExifWeather
|
2
|
+
|
3
|
+
Get weather information via http://openweathermap.org/ based on GPS information of JPEG.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'exif_weather'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install exif_weather
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
ExifWeather.weather( image_file_name )
|
23
|
+
#=> Hash
|
24
|
+
|
25
|
+
### Example
|
26
|
+
|
27
|
+
ExifWeather.weather('gps.jpg')
|
28
|
+
#=>
|
29
|
+
{"coord"=>{"lon"=>134.41, "lat"=>35.49},
|
30
|
+
"sys"=>{"country"=>"JP", "sunrise"=>1372189731, "sunset"=>1372242103},
|
31
|
+
"weather"=>[{"id"=>500, "main"=>"Rain", "description"=>"light rain", "icon"=>"10n"}],
|
32
|
+
"base"=>"global stations",
|
33
|
+
"main"=>{"temp"=>291.985, "temp_min"=>291.985, "temp_max"=>291.985,
|
34
|
+
"pressure"=>973.1, "sea_level"=>1013.31, "grnd_level"=>973.1, "humidity"=>98},
|
35
|
+
"wind"=>{"speed"=>1.85, "deg"=>356.503},
|
36
|
+
"rain"=>{"3h"=>0.75},
|
37
|
+
"clouds"=>{"all"=>92},
|
38
|
+
"dt"=>1372255333,
|
39
|
+
"id"=>1849892,
|
40
|
+
"name"=>"Tottori",
|
41
|
+
"cod"=>200
|
42
|
+
}
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exif_weather/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "exif_weather"
|
8
|
+
spec.version = ExifWeather::VERSION
|
9
|
+
spec.authors = ["Toshiyuki Suzumura"]
|
10
|
+
spec.email = ["suz.labo@amail.plala.or.jp"]
|
11
|
+
spec.description = %q{Get weather information based on GPS information of JPEG.}
|
12
|
+
spec.summary = %q{Get weather information via http://openweathermap.org/ based on GPS information of JPEG.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "exifr"
|
24
|
+
spec.add_development_dependency "json"
|
25
|
+
end
|
data/lib/exif_weather.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "exif_weather/version"
|
2
|
+
require 'exifr'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module ExifWeather
|
7
|
+
##
|
8
|
+
# Get weather information via http://openweathermap.org/
|
9
|
+
# @param [String] file the JPEG image file with GPS information.
|
10
|
+
# @return [Hash] weather information.
|
11
|
+
def self.weather( file )
|
12
|
+
e = EXIFR::JPEG.new(file)
|
13
|
+
return nil unless e.gps
|
14
|
+
lat = e.gps.latitude
|
15
|
+
lon = e.gps.longitude
|
16
|
+
return nil if lat.nil? or lon.nil?
|
17
|
+
res = open("http://api.openweathermap.org/data/2.5/weather?lat=#{lat}&lon=#{lon}").read
|
18
|
+
return JSON.parse(res)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'exif_weather'
|
2
|
+
|
3
|
+
describe ExifWeather do
|
4
|
+
before do
|
5
|
+
@no_gps = File.expand_path('../no_gps.jpg', __FILE__)
|
6
|
+
@no_lat = File.expand_path('../no_lat.jpg', __FILE__)
|
7
|
+
@no_lon = File.expand_path('../no_lon.jpg', __FILE__)
|
8
|
+
@gps = File.expand_path('../gps.jpg', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "shoud be nil when JPEG have no GPS info." do
|
12
|
+
expect(ExifWeather.weather(@no_gps)).to be_nil
|
13
|
+
end
|
14
|
+
it "shoud be nil when JPEG have no latitude info." do
|
15
|
+
expect(ExifWeather.weather(@no_lat)).to be_nil
|
16
|
+
end
|
17
|
+
it "shoud be nil when JPEG have no longitude info." do
|
18
|
+
expect(ExifWeather.weather(@no_lon)).to be_nil
|
19
|
+
end
|
20
|
+
it "shoud be return hash when JPEG have GPS info." do
|
21
|
+
expect(ExifWeather.weather(@gps)).to be_an_instance_of(Hash)
|
22
|
+
end
|
23
|
+
end
|
data/spec/gps.jpg
ADDED
Binary file
|
data/spec/no_gps.jpg
ADDED
Binary file
|
data/spec/no_lat.jpg
ADDED
Binary file
|
data/spec/no_lon.jpg
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exif_weather
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Toshiyuki Suzumura
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: exifr
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: json
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Get weather information based on GPS information of JPEG.
|
79
|
+
email:
|
80
|
+
- suz.labo@amail.plala.or.jp
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .yardopts
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- exif_weather.gemspec
|
92
|
+
- lib/exif_weather.rb
|
93
|
+
- lib/exif_weather/version.rb
|
94
|
+
- spec/exif_weather_spec.rb
|
95
|
+
- spec/gps.jpg
|
96
|
+
- spec/no_gps.jpg
|
97
|
+
- spec/no_lat.jpg
|
98
|
+
- spec/no_lon.jpg
|
99
|
+
homepage: ''
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: 2407113792254567503
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: 2407113792254567503
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 1.8.25
|
127
|
+
signing_key:
|
128
|
+
specification_version: 3
|
129
|
+
summary: Get weather information via http://openweathermap.org/ based on GPS information
|
130
|
+
of JPEG.
|
131
|
+
test_files:
|
132
|
+
- spec/exif_weather_spec.rb
|
133
|
+
- spec/gps.jpg
|
134
|
+
- spec/no_gps.jpg
|
135
|
+
- spec/no_lat.jpg
|
136
|
+
- spec/no_lon.jpg
|