flickrage 0.1.5 → 0.1.6
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/README.md +1 -0
- data/lib/flickrage.rb +2 -0
- data/lib/flickrage/cli.rb +7 -0
- data/lib/flickrage/service/downloader.rb +30 -22
- data/lib/flickrage/service/search.rb +15 -1
- data/lib/flickrage/version.rb +1 -1
- data/lib/flickrage/worker/search.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847af86d9e43d42df3b1b988ac8a0d9bff7aff75
|
4
|
+
data.tar.gz: 590ec13f794cb3a22b1d2182ddf76088e147c8c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de533e78326980bf3e4f91fd0eea9eab3c062c930c5cba58b5e856f7e856a9b0543bdb0f0779b1f1b82c6af5ab9709dbf4a0a3b37c053002be2bd6040d3a432d
|
7
|
+
data.tar.gz: 5fa397e6a465cd2d82ca5c94c9d82f48edead68da0541001b2ee80cf2dce12776fa90b808e39e7496953ec3a6659242407f6df11b4e2e965e5eff023014be948
|
data/README.md
CHANGED
@@ -93,6 +93,7 @@ Provide your own words dictionary:
|
|
93
93
|
[--file-name=./some.png] # Name for the file with collage.
|
94
94
|
[--dict-path=/usr/share/dict/words] # Path to the file with multiline words (dictionary).
|
95
95
|
-c, [--cleanup], [--no-cleanup] # Cleanup files before collage.
|
96
|
+
-t, [--tagged-search], [--no-tagged-search] # Search by tags.
|
96
97
|
-v, [--verbose], [--no-verbose] # Verbose mode.
|
97
98
|
-q, [--quiet], [--no-quiet] # Quiet mode. If don't need any messages and in console.
|
98
99
|
[--flickr-api-key=YOURLONGAPIKEY] # FLICKR_API_KEY. if you can't use environment.
|
data/lib/flickrage.rb
CHANGED
data/lib/flickrage/cli.rb
CHANGED
@@ -111,6 +111,11 @@ module Flickrage
|
|
111
111
|
type: :boolean,
|
112
112
|
aliases: %w(-c),
|
113
113
|
desc: 'Cleanup files before collage.'
|
114
|
+
method_option :tagged_search,
|
115
|
+
default: false,
|
116
|
+
aliases: %w(-t),
|
117
|
+
type: :boolean,
|
118
|
+
desc: 'Search by tags.'
|
114
119
|
method_option :verbose,
|
115
120
|
type: :boolean,
|
116
121
|
aliases: %w(-v),
|
@@ -200,6 +205,8 @@ module Flickrage
|
|
200
205
|
config.max = options['max'] if options['max']
|
201
206
|
config.grid = options['grid'] if options['grid']
|
202
207
|
config.output = options['output']
|
208
|
+
|
209
|
+
config.tagged_search = options['tagged_search']
|
203
210
|
end
|
204
211
|
end
|
205
212
|
|
@@ -9,7 +9,7 @@ module Flickrage
|
|
9
9
|
|
10
10
|
def run(image)
|
11
11
|
uri = gen_uri(image.url)
|
12
|
-
image.file_name = file_name(uri)
|
12
|
+
image.file_name = file_name(uri) unless image.file_name
|
13
13
|
download_file(uri, image.local_path)
|
14
14
|
check_image(image)
|
15
15
|
rescue StandardError => e
|
@@ -19,45 +19,53 @@ module Flickrage
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
-
def download_file(uri, path,
|
22
|
+
def download_file(uri, path, mode = 'wb')
|
23
|
+
File.open(path, mode) do |file|
|
24
|
+
file.flock(File::LOCK_EX)
|
25
|
+
parse_file(uri, file)
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
FileUtils.rm_f(path) if File.size(path).zero?
|
29
|
+
raise e
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_file(uri, file, limit = Flickrage.config.download_timeout)
|
23
33
|
raise Flickrage::DownloadError, 'Redirect limit arrived' if limit.zero?
|
24
34
|
|
25
35
|
Net::HTTP.start(uri.host, uri.port,
|
26
36
|
use_ssl: uri.scheme == 'https') do |conn|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
conn.request_get(uri.path) do |response|
|
38
|
+
case response
|
39
|
+
when Net::HTTPSuccess
|
40
|
+
response.read_body do |seg|
|
41
|
+
file << seg
|
42
|
+
end
|
43
|
+
when Net::HTTPRedirection
|
44
|
+
download_file(gen_uri(response['location']),
|
45
|
+
path,
|
46
|
+
limit - 1)
|
47
|
+
else
|
48
|
+
response.error!
|
49
|
+
end
|
39
50
|
end
|
40
51
|
end
|
41
52
|
end
|
42
53
|
|
43
|
-
def write_file(path, body, mode = 'wb')
|
44
|
-
File.open(path, mode) do |file|
|
45
|
-
file.flock(File::LOCK_EX)
|
46
|
-
file << body
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
54
|
def gen_uri(url)
|
51
55
|
URI.parse(url)
|
52
56
|
end
|
53
57
|
|
54
58
|
def file_name(uri)
|
55
|
-
|
59
|
+
"#{nsec}_" + File.basename(uri.path)
|
56
60
|
end
|
57
61
|
|
58
62
|
def check_image(image)
|
59
63
|
File.exist?(image.local_path) ? image.finish_download : image
|
60
64
|
end
|
65
|
+
|
66
|
+
def nsec
|
67
|
+
Time.now.nsec
|
68
|
+
end
|
61
69
|
end
|
62
70
|
end
|
63
71
|
end
|
@@ -4,6 +4,12 @@ module Flickrage
|
|
4
4
|
class Search
|
5
5
|
include Flickrage::Helpers::Log
|
6
6
|
|
7
|
+
attr_reader :tagged_search
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@tagged_search = Flickrage.config.tagged_search
|
11
|
+
end
|
12
|
+
|
7
13
|
def run(keyword)
|
8
14
|
result = search(keyword)
|
9
15
|
|
@@ -31,7 +37,7 @@ module Flickrage
|
|
31
37
|
end
|
32
38
|
|
33
39
|
def search(keyword)
|
34
|
-
flickr.photos.search(params(
|
40
|
+
flickr.photos.search(params(search_query(keyword)))
|
35
41
|
end
|
36
42
|
|
37
43
|
def title(text)
|
@@ -48,6 +54,14 @@ module Flickrage
|
|
48
54
|
pages: 1
|
49
55
|
}.merge(opts)
|
50
56
|
end
|
57
|
+
|
58
|
+
def search_query(keyword)
|
59
|
+
if tagged_search
|
60
|
+
{tags: [keyword]}
|
61
|
+
else
|
62
|
+
{text: keyword}
|
63
|
+
end
|
64
|
+
end
|
51
65
|
end
|
52
66
|
end
|
53
67
|
end
|
data/lib/flickrage/version.rb
CHANGED
@@ -5,7 +5,7 @@ module Flickrage
|
|
5
5
|
include Flickrage::Helpers::Dict
|
6
6
|
|
7
7
|
def call
|
8
|
-
keywords = opts['keywords'] || %w()
|
8
|
+
keywords = opts['keywords']&.first(Flickrage.config.max) || %w()
|
9
9
|
|
10
10
|
keywords += sample_words(Flickrage.config.max - keywords.size) if keywords.size < Flickrage.config.max
|
11
11
|
keys = keywords.join(', ')
|