nokaya 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +11 -17
- data/lib/nokaya/app.rb +8 -5
- data/lib/nokaya/getter.rb +5 -13
- data/lib/nokaya/image.rb +17 -0
- data/lib/nokaya/status.rb +17 -0
- data/lib/nokaya/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a437d53d827e0c39fa5c65dddd1c0920178f82c
|
4
|
+
data.tar.gz: f017ad65a6324f89a17d0629a4061c6a8fe5b10b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2399328cb080b8604ed821b31db036c355b0492a32cb7a9ad0185012a8338d8e5f45b11aaeb59922a1284d6458e1315c07663b7310374319feba6f8bb2c541e
|
7
|
+
data.tar.gz: d9ab1abe1fc57243c56e95b587184a136beb6053ccb00476e3eeac7e7fcecaf972c35b1ce5c5d6e627148c4efe58843e1dfd1818e74fbfbff03cfabd528b3cea
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,29 +1,23 @@
|
|
1
1
|
# Nokaya
|
2
2
|
|
3
|
-
|
3
|
+
CLI to download photos from several online services including Instagram.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
5
|
+
Mac OS X only for the time being.
|
8
6
|
|
9
|
-
|
7
|
+
## Installation
|
10
8
|
|
11
|
-
|
9
|
+
`gem install nokaya`
|
12
10
|
|
13
|
-
|
11
|
+
## Usage
|
14
12
|
|
15
|
-
|
13
|
+
### Instagram
|
16
14
|
|
17
|
-
|
15
|
+
`nokaya -i url`
|
18
16
|
|
19
|
-
|
17
|
+
`nokaya -i url -n file_name`
|
20
18
|
|
21
|
-
|
19
|
+
Example:
|
22
20
|
|
23
|
-
|
21
|
+
`nokaya -i http://instagram.com/p/noANAfjJ7B/`
|
24
22
|
|
25
|
-
|
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 a new Pull Request
|
23
|
+
`nokaya -i http://instagram.com/p/noANAfjJ7B/ -n happydog`
|
data/lib/nokaya/app.rb
CHANGED
@@ -3,18 +3,21 @@ module Nokaya
|
|
3
3
|
class App < Thor
|
4
4
|
package_name "Nokaya"
|
5
5
|
require_relative 'getter'
|
6
|
+
require_relative 'image'
|
7
|
+
require_relative 'status'
|
6
8
|
|
7
9
|
desc "instagram", "Get the main photo from an Instagram page (nokaya -i url)"
|
8
10
|
map "-i" => :instagram
|
9
|
-
option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension
|
11
|
+
option :name, aliases: "-n", type: :string, desc: "Specify a file name without extension"
|
10
12
|
def instagram *args
|
13
|
+
abort Status.no_url if args.empty?
|
11
14
|
nokaya = Getter.new options, :instagram, args
|
12
15
|
page = nokaya.parse_page
|
13
16
|
img_link = nokaya.get_link page
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts
|
17
|
+
puts Status.downloading img_link
|
18
|
+
path = Image.photo_name nokaya
|
19
|
+
Image.save_image(path, nokaya.get_image(img_link))
|
20
|
+
puts Status.saved path
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
data/lib/nokaya/getter.rb
CHANGED
@@ -17,26 +17,18 @@ module Nokaya
|
|
17
17
|
@args.url
|
18
18
|
end
|
19
19
|
def get_image img_link
|
20
|
-
|
20
|
+
begin
|
21
|
+
open(img_link).read
|
22
|
+
rescue
|
23
|
+
abort Status.no_can_do
|
24
|
+
end
|
21
25
|
end
|
22
26
|
def get_link page
|
23
27
|
page.xpath("//meta[@property='og:image']/@content").first
|
24
28
|
end
|
25
|
-
def photo_name
|
26
|
-
unless @args.options[:name]
|
27
|
-
Dir.home + "/Downloads/#{@args.type.to_s}-#{Time.now.to_i}.jpg"
|
28
|
-
else
|
29
|
-
Dir.home + "/Downloads/#{@args.type.to_s}-#{@args.options[:name]}.jpg"
|
30
|
-
end
|
31
|
-
end
|
32
29
|
def parse_page
|
33
30
|
Nokogiri::HTML get_page_content
|
34
31
|
end
|
35
|
-
def save_image path, img_link
|
36
|
-
f = File.new(path, "wb")
|
37
|
-
f.puts(get_image img_link)
|
38
|
-
f.close
|
39
|
-
end
|
40
32
|
private
|
41
33
|
def get_page_content
|
42
34
|
open @args.url
|
data/lib/nokaya/image.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Nokaya
|
3
|
+
class Image
|
4
|
+
def self.photo_name nokaya
|
5
|
+
unless nokaya.options[:name]
|
6
|
+
Dir.home + "/Downloads/#{nokaya.type.to_s}-#{Time.now.to_i}.jpg"
|
7
|
+
else
|
8
|
+
Dir.home + "/Downloads/#{nokaya.type.to_s}-#{nokaya.options[:name]}.jpg"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def self.save_image path, content
|
12
|
+
f = File.new(path, "wb")
|
13
|
+
f.puts(content)
|
14
|
+
f.close
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Nokaya
|
3
|
+
class Status
|
4
|
+
def self.downloading img_link
|
5
|
+
"\nDownloading #{img_link}, please wait...\n\n"
|
6
|
+
end
|
7
|
+
def self.saved path
|
8
|
+
"Image saved in #{path}\n\n"
|
9
|
+
end
|
10
|
+
def self.no_can_do
|
11
|
+
"Canceled: unable to get the page contents.\n\n"
|
12
|
+
end
|
13
|
+
def self.no_url
|
14
|
+
"\nYou have to specify a page URL.\n\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nokaya/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nokaya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Dejonckheere
|
@@ -202,6 +202,7 @@ extensions: []
|
|
202
202
|
extra_rdoc_files: []
|
203
203
|
files:
|
204
204
|
- ".gitignore"
|
205
|
+
- CHANGELOG.md
|
205
206
|
- Gemfile
|
206
207
|
- Guardfile
|
207
208
|
- LICENSE.txt
|
@@ -211,6 +212,8 @@ files:
|
|
211
212
|
- lib/nokaya.rb
|
212
213
|
- lib/nokaya/app.rb
|
213
214
|
- lib/nokaya/getter.rb
|
215
|
+
- lib/nokaya/image.rb
|
216
|
+
- lib/nokaya/status.rb
|
214
217
|
- lib/nokaya/version.rb
|
215
218
|
- nokaya.gemspec
|
216
219
|
- spec/nokaya_spec.rb
|