visioner 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ad07e8c2e46392159f5c62a4a956d4e646ab4f3
4
- data.tar.gz: fcc1116040567630a84f1c96c4f94d6c899d5bee
3
+ metadata.gz: dfb460875ffcf77f13a494ce40b05e1dc089fc9c
4
+ data.tar.gz: ba23dfdae48c61b58fc88e8bda5c3d0e15c9de1c
5
5
  SHA512:
6
- metadata.gz: 91018c0cd1ef95db035ee992d996c75f6a7dcf17df4b51a4127ec90e5d421d5c5f1b7b52a27eca92c625f8a3718c7c5162c3ff2ed4243c48d9eddf8596c711b7
7
- data.tar.gz: a5482df04d15ddba0fa81fca3dfec6700377b6b8f0594dd15290a52c25e3681ae46b8b795fe81399de55e19ad8437da2e2f89daf08503eb83c28a11a8f6f67aa
6
+ metadata.gz: 72d6f000b32cbbb60675d483b452d35cec3b176cfbcab02eee5b99d94c1c3b331f5a9da8100491813410f53786f9a1517d0b084e5ffc13bbb1b94fce887ef072
7
+ data.tar.gz: 050e98a0ef8f60b2d4dd8512fd6388b4db22d5c5c08f3505a996687be1adef043cb0d51f26bec33c0fb86d76384885c5cdfdaaccb8c2876b275dd63ca8b0101e
data/README.md CHANGED
@@ -16,6 +16,8 @@ Automatically rename your pictures using Google Vision API and metadata.
16
16
 
17
17
  -c, --country Adds country to the new filename (ex: south-korea)
18
18
 
19
+ -i, --city Adds city to the new filename (ex: seoul)
20
+
19
21
  -d, --date Adds date to the new filename (ex: 29/07/2016)
20
22
 
21
23
  -h, --help Displays help
@@ -23,19 +25,19 @@ Automatically rename your pictures using Google Vision API and metadata.
23
25
  **Examples:**
24
26
 
25
27
  $ export GOOGLE_VISION_API_KEY=BI34SyB5DhqV5ReVnkmIM79812yux9UFazNdynD
26
-
28
+
27
29
  $ bin/visioner /Desktop/travel-south-korea-2016-2/*.jpg
28
30
  /Desktop/travel-south-korea-2016-2/IMG_213.jpg -> sea.jpg
29
31
  /Desktop/travel-south-korea-2016-2/IMG_214.jpg -> tower.jpg
30
32
  /Desktop/travel-south-korea-2016-2/IMG_215.jpg -> people.jpg
31
33
  /Desktop/travel-south-korea-2016-2/IMG_216.jpg -> sea2.jpg
32
-
34
+
33
35
  $ bin/visioner --date /Desktop/travel-south-korea-2016-3/*.jpg
34
36
  /Desktop/travel-south-korea-2016-3/IMG_213.jpg -> 02-28-2015_sea.jpg
35
37
  /Desktop/travel-south-korea-2016-3/IMG_214.jpg -> 02-15-2015_tower.jpg
36
38
  /Desktop/travel-south-korea-2016-3/IMG_215.jpg -> 03-28-2015_people.jpg
37
39
  /Desktop/travel-south-korea-2016-3/IMG_216.jpg -> 04-02-2015_sea2.jpg
38
-
40
+
39
41
  $ bin/visioner --country --date /Desktop/travel-south-korea-2016-4/*.jpg
40
42
  /Desktop/travel-south-korea-2016-4/IMG_213.jpg -> south-korea_02-28-2015_sea.jpg
41
43
  /Desktop/travel-south-korea-2016-4/IMG_214.jpg -> south-korea_03-15-2015_tower.jpg
data/bin/visioner CHANGED
@@ -12,6 +12,10 @@ opts.on("-c", "--country", "Adds country to the new filename (ex: south-korea)")
12
12
  options[:country] = c
13
13
  end
14
14
 
15
+ opts.on("-l", "--locality", "Adds locality / city to the new filename (ex: seoul)") do |l|
16
+ options[:locality] = l
17
+ end
18
+
15
19
  opts.on("-d", "--date", "Adds date to the new filename (ex: 29/07/2016)") do |d|
16
20
  options[:date] = d
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module Visioner
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/visioner.rb CHANGED
@@ -7,7 +7,7 @@ require 'optparse'
7
7
 
8
8
  module Visioner
9
9
 
10
- def self.get_country(latitude, longitude)
10
+ def self.get_place(latitude, longitude, type)
11
11
  # Prepare request
12
12
  url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=#{latitude},#{longitude}"
13
13
  url = URI(url)
@@ -15,19 +15,21 @@ module Visioner
15
15
  res = Net::HTTP.new(url.host, url.port)
16
16
  res.use_ssl = true
17
17
 
18
- # Get country
19
- country = 'unknown'
18
+ # Get place
19
+ place = 'unknown'
20
20
  res.start do |http|
21
21
  resp = http.request(req)
22
22
  json = JSON.parse(resp.body)
23
- if json && json['status'] == 'OK' && json['results'][0]['address_components'] && json['results'][0]['address_components'].select {|address_component| address_component['types'][0] == 'country' }
24
- country = json['results'][0]['address_components'].select {|address_component| address_component['types'][0] == 'country' }
25
- country = country[0]['long_name']
26
- country = country.downcase.tr(" ", "-")
23
+ if json && json['status'] == 'OK' && json['results'][0]['address_components'] && json['results'][0]['address_components'].select {|address_component| address_component['types'][0] == type }
24
+ place = json['results'][0]['address_components'].select {|address_component| address_component['types'][0] == type }
25
+ if place[0]
26
+ place = place[0]['long_name']
27
+ place = place.downcase.tr(" ", "-")
28
+ end
27
29
  end
28
30
  end
29
31
 
30
- return country
32
+ return place
31
33
  end
32
34
 
33
35
  def self.rename_all(images, options)
@@ -101,12 +103,18 @@ module Visioner
101
103
  country = ''
102
104
  if options[:country]
103
105
  country = 'unknown' # Fallback
104
- country = self.get_country(exif.gps.latitude, exif.gps.longitude) + '_' if exif.gps_latitude && exif.gps_longitude
106
+ country = self.get_place(exif.gps.latitude, exif.gps.longitude, 'country') + '_' if exif.gps_latitude && exif.gps_longitude
107
+ end
108
+
109
+ locality = ''
110
+ if options[:locality]
111
+ locality = 'unknown' # Fallback
112
+ locality = self.get_place(exif.gps.latitude, exif.gps.longitude, 'locality') + '_' if exif.gps_latitude && exif.gps_longitude
105
113
  end
106
114
 
107
- puts "#{image_name} -> #{country + date + name + counter.to_s + File.extname(image_name)}"
115
+ puts "#{image_name} -> #{country + locality + date + name + counter.to_s + File.extname(image_name)}"
108
116
 
109
- File.rename(image_name, File.dirname(image_name) + "/" + country + date + name + counter.to_s + File.extname(image_name))
117
+ File.rename(image_name, File.dirname(image_name) + "/" + country + locality + date + name + counter.to_s + File.extname(image_name))
110
118
  end
111
119
 
112
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Jean Bergeron