flickrage 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.rubocop.yml +50 -0
- data/.ruby-version +1 -0
- data/.travis.yml +14 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +188 -0
- data/Rakefile +16 -0
- data/bin/console +15 -0
- data/bin/flickrage +13 -0
- data/bin/setup +8 -0
- data/flickrage.gemspec +43 -0
- data/lib/flickrage.rb +183 -0
- data/lib/flickrage/cli.rb +228 -0
- data/lib/flickrage/entity.rb +7 -0
- data/lib/flickrage/entity/image.rb +42 -0
- data/lib/flickrage/entity/image_list.rb +66 -0
- data/lib/flickrage/helpers.rb +80 -0
- data/lib/flickrage/log.rb +88 -0
- data/lib/flickrage/pipeline.rb +64 -0
- data/lib/flickrage/service.rb +9 -0
- data/lib/flickrage/service/composer.rb +51 -0
- data/lib/flickrage/service/downloader.rb +63 -0
- data/lib/flickrage/service/resizer.rb +59 -0
- data/lib/flickrage/service/search.rb +53 -0
- data/lib/flickrage/types.rb +6 -0
- data/lib/flickrage/version.rb +4 -0
- data/lib/flickrage/worker.rb +10 -0
- data/lib/flickrage/worker/base.rb +73 -0
- data/lib/flickrage/worker/compose.rb +66 -0
- data/lib/flickrage/worker/download.rb +87 -0
- data/lib/flickrage/worker/resize.rb +85 -0
- data/lib/flickrage/worker/search.rb +106 -0
- data/log/.keep +0 -0
- data/tmp/.keep +0 -0
- metadata +322 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf60b6c67ea4268d0d646cdd9b6b475744c49af2
|
4
|
+
data.tar.gz: 9e529fabe4ab52ace9e86add2d03a6b238c85b6f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 161e305af9402fef2d2af2c0dc24349d014b47087db640da2d79511f66a68b624db902b2f5be22010fc3582cb73fc2e171243977b6a724b15d2aed3b3592dbc9
|
7
|
+
data.tar.gz: e5436fba5048ff0ad7ae1c0ea6bdb73f1e0a053930a864557045c2a6a0b7d1b3cc46091f90dd0c8d2156ce4ef303f0e70fb92144d10d12b3fb4af11e851e58bd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
LineLength:
|
2
|
+
Max: 200
|
3
|
+
|
4
|
+
HashSyntax:
|
5
|
+
EnforcedStyle: ruby19
|
6
|
+
|
7
|
+
Style/SpaceBeforeFirstArg:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/TrailingCommaInLiteral:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/TrailingCommaInArguments:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/MultilineBlockChain:
|
20
|
+
Disabled: true
|
21
|
+
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Max: 20
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/MethodLength:
|
29
|
+
Max: 25
|
30
|
+
|
31
|
+
Style/MultilineBlockChain:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/MultilineMethodCallIndentation:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/MethodLength:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/ZeroLengthPredicate:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
AllCops:
|
47
|
+
Exclude:
|
48
|
+
- '*.gemspec'
|
49
|
+
- 'tasks/**/*'
|
50
|
+
- 'Rakefile'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
rvm:
|
4
|
+
- 2.3.1
|
5
|
+
notifications:
|
6
|
+
email:
|
7
|
+
- api@mrcr.ru
|
8
|
+
script:
|
9
|
+
- bundle exec rake
|
10
|
+
before_install:
|
11
|
+
- sudo apt-get update
|
12
|
+
- sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
|
13
|
+
- sudo apt-get install -qq graphicsmagick
|
14
|
+
- gem update bundler
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Alexander Merkulov
|
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,188 @@
|
|
1
|
+
# Flickrage CLI, your Flickr Collage.
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/flickrage.svg)](http://badge.fury.io/rb/flickrage)
|
4
|
+
[![Build Status](https://travis-ci.org/merqlove/flickrage.svg?branch=master)](https://travis-ci.org/merqlove/flickrage)
|
5
|
+
|
6
|
+
Little tool with idea of downloading random top-n pictures from the Flickr, resize it properly & build collage from them!
|
7
|
+
|
8
|
+
Here are some features:
|
9
|
+
|
10
|
+
- Search at Flickr with words from your own dictionary or provide just a few words :).
|
11
|
+
- Multiple threads out of the box, no matter how many images you want.
|
12
|
+
- Auto-cleanup (optional).
|
13
|
+
- Logging into a file (optional).
|
14
|
+
- Predefined timeouts for long requests (unresponding links or similar).
|
15
|
+
- Verbose mode for research (optional).
|
16
|
+
- Quiet mode for silence (optional).
|
17
|
+
|
18
|
+
## Compatibility
|
19
|
+
|
20
|
+
Ruby versions 2.3.0 and higher.
|
21
|
+
|
22
|
+
<a href="https://raw.githubusercontent.com/merqlove/flickrage/prepare/assets/collage.jpg" target="_blank"><img src="https://raw.githubusercontent.com/merqlove/flickrage/prepare/assets/collage.jpg" style="max-width:50%" alt="Flickrage collage example"></a>
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Install it yourself as:
|
27
|
+
|
28
|
+
$ gem install flickrage
|
29
|
+
|
30
|
+
System Wide Install (OSX, *nix):
|
31
|
+
|
32
|
+
$ sudo gem install flickrage
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
It's pretty simple at the start:
|
37
|
+
|
38
|
+
$ flickrage -k some nice grapefruit
|
39
|
+
|
40
|
+
### Setup
|
41
|
+
|
42
|
+
You'll need to get/generate an API keys from your Flickr profile at https://www.flickr.com/account/sharing
|
43
|
+
|
44
|
+
Next you can export Flickr API keys as ENV variables:
|
45
|
+
|
46
|
+
$ export FLICKR_API_KEY="SOMEKEY"
|
47
|
+
$ export FLICKR_SHARED_SECRET="SOMESECRET"
|
48
|
+
|
49
|
+
Or set keys with arguments:
|
50
|
+
|
51
|
+
$ flickrage --flickr-api-key SOMELONGKEY --flickr-shared-secret SOMELONGSECRET
|
52
|
+
|
53
|
+
### How-To
|
54
|
+
|
55
|
+
Select output folder:
|
56
|
+
|
57
|
+
$ flickrage -k some nice grapefruit -o ./tmp
|
58
|
+
|
59
|
+
Enter collage file_name:
|
60
|
+
|
61
|
+
$ flickrage -k some nice grapefruit --file-name some.jpg
|
62
|
+
|
63
|
+
Get collage of top 10 images:
|
64
|
+
|
65
|
+
$ flickrage -k some nice grapefruit --max 10
|
66
|
+
|
67
|
+
Get collage of top 20 images:
|
68
|
+
|
69
|
+
$ flickrage -k some nice grapefruit --max 20
|
70
|
+
|
71
|
+
Get collage of top 10 images custom width & height:
|
72
|
+
|
73
|
+
$ flickrage -k some nice grapefruit --max 10 --width 160 --height 120
|
74
|
+
|
75
|
+
Provide your own words dictionary:
|
76
|
+
|
77
|
+
$ flickrage -k some nice grapefruit --dict-path /usr/share/dict/words
|
78
|
+
|
79
|
+
### All options:
|
80
|
+
|
81
|
+
> $ flickrage help c
|
82
|
+
|
83
|
+
Options:
|
84
|
+
-k, --keywords=some nice grapefruit
|
85
|
+
[--max=10] # Select number of files.
|
86
|
+
# Default: 10
|
87
|
+
# Possible values: 1, ..., 20
|
88
|
+
[--grid=2] # Select grid base number.
|
89
|
+
[--width=120] # Set width for resize downloaded images.
|
90
|
+
[--height=80] # Set height for resize downloaded images.
|
91
|
+
-l, [--log=/Users/someone/.flickrage/main.log] # Log file path. By default logging is disabled.
|
92
|
+
-o, [--output=./tmp] # Output directory, where all data will be stored.
|
93
|
+
[--file-name=./some.png] # Name for the file with collage.
|
94
|
+
[--dict-path=/usr/share/dict/words] # Path to the file with multiline words (dictionary).
|
95
|
+
-c, [--cleanup], [--no-cleanup] # Cleanup files before collage.
|
96
|
+
-v, [--verbose], [--no-verbose] # Verbose mode.
|
97
|
+
-q, [--quiet], [--no-quiet] # Quiet mode. If don't need any messages and in console.
|
98
|
+
[--flickr-api-key=YOURLONGAPIKEY] # FLICKR_API_KEY. if you can't use environment.
|
99
|
+
[--flickr-shared-secret=YOURLONGSHAREDSECRET] # FLICKR_SHARED_SECRET. if you can't use environment.
|
100
|
+
|
101
|
+
`flickrage` is a tool which loves search on the Flickr & making collages from findings.
|
102
|
+
|
103
|
+
You have to enter name of the output file and a max number of downloading files.
|
104
|
+
|
105
|
+
Parameters helps you specify rectangle size for each image, collage name, it's location, ..., and well the grid base size.
|
106
|
+
|
107
|
+
### Screenshot:
|
108
|
+
|
109
|
+
<img src="https://raw.githubusercontent.com/merqlove/flickrage/prepare/assets/example.png" style="max-width:100%" alt="Flickrage example">
|
110
|
+
|
111
|
+
### Real world example
|
112
|
+
|
113
|
+
$ flickrage c -k one two three --cleanup --flickr-api-key ************ --flickr-shared-secret ***********
|
114
|
+
Thank you for choosing Flickrage, you will find me as your Flickr collage companion :)
|
115
|
+
|
116
|
+
Received keywords: [one, two, three, archencephalic, trub, soiree, barring, Cestodaria, readorn, Thurnia]
|
117
|
+
[+] Searching (found image ID#15415535811)
|
118
|
+
|
119
|
+
Found 10 images:
|
120
|
+
keyword id url title width height
|
121
|
+
one 16214454241 https://farm9.staticflickr.com/8618/16214454241_3ab4ae73c7_b.jpg First Snowfall 1024 687
|
122
|
+
...
|
123
|
+
tightfisted 8757535743 https://farm4.staticflickr.com/3786/8757535743_1c8c6b57d9_b.jpg Teasels at the Sixteen Foot 1024 696
|
124
|
+
achete 15415535811 https://farm3.staticflickr.com/2949/15415535811_4eedddc4b4_b.jpg Une nouvelle, page 12 on 17 1024 1024
|
125
|
+
|
126
|
+
Scheduled to download 10 images
|
127
|
+
Please enter the path of the output directory: ./tmp
|
128
|
+
[+] Downloaded image ID#8757535743
|
129
|
+
|
130
|
+
Downloaded 10 images:
|
131
|
+
keyword id path downloaded?
|
132
|
+
one 16214454241 /Users/some/path/tmp/16214454241_3ab4ae73c7_b.jpg true
|
133
|
+
...
|
134
|
+
achete 15415535811 /Users/some/path/tmp/15415535811_4eedddc4b4_b.jpg true
|
135
|
+
|
136
|
+
Please enter image resize width: 200
|
137
|
+
Please enter image resize height: 100
|
138
|
+
[+] Resized image 15415535811
|
139
|
+
|
140
|
+
Resized 10 images:
|
141
|
+
keyword id path resized?
|
142
|
+
one 16214454241 /Users/some/path/tmp/resized.16214454241_3ab4ae73c7_b.jpg true
|
143
|
+
...
|
144
|
+
tightfisted 8757535743 /Users/some/path/tmp/resized.8757535743_1c8c6b57d9_b.jpg true
|
145
|
+
achete 15415535811 /Users/some/path/tmp/resized.15415535811_4eedddc4b4_b.jpg true
|
146
|
+
|
147
|
+
Please enter the collage file name: some.png
|
148
|
+
[+] Collage making
|
149
|
+
10 images composed
|
150
|
+
|
151
|
+
Congrats! You can find composed collage at /Users/some/path/tmp/some.png
|
152
|
+
|
153
|
+
### Dict
|
154
|
+
|
155
|
+
**Ubuntu**:
|
156
|
+
|
157
|
+
If not installed, install or provide your own:
|
158
|
+
|
159
|
+
$ apt-get install --reinstall wamerican
|
160
|
+
|
161
|
+
**OSX**:
|
162
|
+
|
163
|
+
By default: `/usr/share/dict/words`
|
164
|
+
|
165
|
+
## Dependencies:
|
166
|
+
|
167
|
+
- [Concurrent Ruby](https://github.com/ruby-concurrency/concurrent-ruby) lots of awesome tools.
|
168
|
+
- [Thor](https://github.com/erikhuda/thor) for CLI base.
|
169
|
+
- [Tty Spinner](https://github.com/piotrmurach/tty-spinner) wonderful Spinner.
|
170
|
+
- [Flickraw](https://github.com/hanklords/flickraw) for Flickr API access.
|
171
|
+
- [MiniMagick](https://github.com/minimagick/minimagick) as well as ImageMagick on your machine.
|
172
|
+
- ...
|
173
|
+
|
174
|
+
## Contributing
|
175
|
+
|
176
|
+
1. Fork it ( https://github.com/merqlove/flickrage/fork )
|
177
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
178
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
179
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
180
|
+
5. Create a new Pull Request
|
181
|
+
|
182
|
+
### Testing
|
183
|
+
|
184
|
+
$ rake spec
|
185
|
+
|
186
|
+
Copyright (c) 2016 Alexander Merkulov
|
187
|
+
|
188
|
+
MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
PROJECT_ROOT = File.expand_path('..', __FILE__)
|
5
|
+
$:.unshift "#{PROJECT_ROOT}/lib"
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'rspec/core/rake_task'
|
9
|
+
|
10
|
+
desc 'Run all specs'
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
rescue LoadError
|
13
|
+
# The test gem group fails to install on the platform for some reason
|
14
|
+
end
|
15
|
+
|
16
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'flickrage'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start
|
data/bin/flickrage
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
Signal.trap('INT') { exit 1 }
|
5
|
+
|
6
|
+
require 'pathname'
|
7
|
+
bin_file = Pathname.new(__FILE__).realpath
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', bin_file)
|
10
|
+
|
11
|
+
require 'flickrage/cli'
|
12
|
+
|
13
|
+
Flickrage::CLI.start(ARGV)
|
data/bin/setup
ADDED
data/flickrage.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flickrage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'flickrage'
|
8
|
+
spec.version = Flickrage::VERSION
|
9
|
+
spec.authors = ['Alexander Merkulov']
|
10
|
+
spec.email = ['sasha@merqlove.ru']
|
11
|
+
|
12
|
+
spec.summary = %q{Another one Flickr collage maker.}
|
13
|
+
spec.description = %q{Little tool with idea of downloading random top-n pictures from the Flickr, resize it properly & build collage from them!}
|
14
|
+
spec.homepage = 'https://github.com/merqlove/flickrage'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|assets|spec|features)/}) }
|
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
|
+
spec.licenses = ['MIT']
|
21
|
+
|
22
|
+
spec.required_ruby_version = '>= 2.3.0'
|
23
|
+
|
24
|
+
spec.add_dependency 'thor', '~> 0.19'
|
25
|
+
spec.add_dependency 'flickraw', '~> 0.9.9'
|
26
|
+
spec.add_dependency 'mini_magick', '~> 4.5.1'
|
27
|
+
spec.add_dependency 'dry-configurable', '~> 0.1.7'
|
28
|
+
spec.add_dependency 'dry-types', '~> 0.8.1'
|
29
|
+
spec.add_dependency 'concurrent-ruby-edge'
|
30
|
+
spec.add_dependency 'tty-spinner', '~> 0.3.0'
|
31
|
+
spec.add_dependency 'pastel', '~> 0.6.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
|
36
|
+
spec.add_development_dependency 'json', '~> 1.8.1'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.5.0'
|
38
|
+
spec.add_development_dependency 'rspec-core', '~> 3.5.0'
|
39
|
+
spec.add_development_dependency 'rspec-expectations', '~> 3.5.0'
|
40
|
+
spec.add_development_dependency 'rspec-mocks', '~> 3.5.0'
|
41
|
+
spec.add_development_dependency 'webmock', '~> 2.1.0'
|
42
|
+
spec.add_development_dependency 'coveralls', '~> 0.8.15'
|
43
|
+
end
|
data/lib/flickrage.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'flickrage/version'
|
3
|
+
require 'dry-configurable'
|
4
|
+
require 'dry-types'
|
5
|
+
|
6
|
+
module Flickrage
|
7
|
+
autoload :Log, 'flickrage/log'
|
8
|
+
autoload :Helpers, 'flickrage/helpers'
|
9
|
+
autoload :Types, 'flickrage/types'
|
10
|
+
autoload :Entity, 'flickrage/entity'
|
11
|
+
autoload :Service, 'flickrage/service'
|
12
|
+
autoload :Worker, 'flickrage/worker'
|
13
|
+
autoload :Pipeline, 'flickrage/pipeline'
|
14
|
+
|
15
|
+
extend Dry::Configurable
|
16
|
+
|
17
|
+
MAX_DICT_LINES = 1_000_000
|
18
|
+
|
19
|
+
setting :logger
|
20
|
+
setting :logger_level, Logger::INFO
|
21
|
+
|
22
|
+
setting :verbose, false
|
23
|
+
setting :quiet, false
|
24
|
+
setting :cleanup, false
|
25
|
+
|
26
|
+
setting :resize_file_prefix, 'resized.'
|
27
|
+
|
28
|
+
setting :width
|
29
|
+
setting :height
|
30
|
+
|
31
|
+
setting :pool_size, 5
|
32
|
+
setting :pool
|
33
|
+
|
34
|
+
setting :grid, 5
|
35
|
+
setting :max, 10
|
36
|
+
setting :output
|
37
|
+
|
38
|
+
setting :dict_path, '/usr/share/dict/words'
|
39
|
+
setting :dict
|
40
|
+
|
41
|
+
setting :flickr_api_key
|
42
|
+
setting :flickr_shared_secret
|
43
|
+
|
44
|
+
class << self
|
45
|
+
attr_accessor :logger
|
46
|
+
|
47
|
+
def cleanup
|
48
|
+
logger.close if logger
|
49
|
+
end
|
50
|
+
|
51
|
+
def api_keys?
|
52
|
+
config.flickr_api_key && config.flickr_shared_secret
|
53
|
+
end
|
54
|
+
|
55
|
+
def pool=(value)
|
56
|
+
config.pool = value
|
57
|
+
end
|
58
|
+
|
59
|
+
def dict
|
60
|
+
return config.dict if config.dict
|
61
|
+
_read_dict
|
62
|
+
end
|
63
|
+
|
64
|
+
def _read_dict
|
65
|
+
logger.debug('Caching lines from the Dict')
|
66
|
+
|
67
|
+
raise DictError, "Not found #{config.dict_path}" unless File.exist?(config.dict_path)
|
68
|
+
@dict_file = File.open(config.dict_path, 'r')
|
69
|
+
|
70
|
+
configure do |c|
|
71
|
+
c.dict = @dict_file.each_line.first(MAX_DICT_LINES)
|
72
|
+
end
|
73
|
+
config.dict
|
74
|
+
rescue => e
|
75
|
+
raise DictError, e.message
|
76
|
+
ensure
|
77
|
+
@dict_file.close if @dict_file.respond_to?(:close)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Standard Request Exception. When we don't need droplet instance id.
|
82
|
+
#
|
83
|
+
class BaseError < StandardError; end
|
84
|
+
|
85
|
+
# Time is going over...
|
86
|
+
#
|
87
|
+
class SystemTimeout < BaseError
|
88
|
+
def initialize(*args)
|
89
|
+
Flickrage.logger.error 'Timeout, something going wrong...'
|
90
|
+
super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# User did few mistakes with output path...
|
95
|
+
#
|
96
|
+
class PathError < BaseError
|
97
|
+
def initialize(*args)
|
98
|
+
Flickrage.logger.error 'Please provide existing output path...'
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# User did few mistakes with file_name...
|
104
|
+
#
|
105
|
+
class FileNameError < BaseError
|
106
|
+
def initialize(*args)
|
107
|
+
Flickrage.logger.error 'Please provide right file_name...'
|
108
|
+
super
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# User system has no/wrong default words dict...
|
113
|
+
#
|
114
|
+
class DictError < BaseError
|
115
|
+
def initialize(*args)
|
116
|
+
Flickrage.logger.error 'Please provide existing path to the dict...'
|
117
|
+
super
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# User did few mistakes with size input...
|
122
|
+
#
|
123
|
+
class NumberError < BaseError
|
124
|
+
def initialize(*args)
|
125
|
+
Flickrage.logger.error "Flickrage support for dimensions only numbers in range: #{args[0]}..."
|
126
|
+
super
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Download error rises when Flickr down...
|
131
|
+
#
|
132
|
+
class SearchError < BaseError
|
133
|
+
def initialize(*args)
|
134
|
+
Flickrage.logger.error "Cannot find something...: #{args[0]}"
|
135
|
+
super
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Download error rises when Flickr down...
|
140
|
+
#
|
141
|
+
class DownloadError < BaseError
|
142
|
+
def initialize(*args)
|
143
|
+
Flickrage.logger.error "Connection is down or something goes wrong...: #{args[0]}"
|
144
|
+
super
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Every call must have token in environment or via params.
|
149
|
+
#
|
150
|
+
class NoKeysError < BaseError
|
151
|
+
def initialize(*_args)
|
152
|
+
Flickrage.logger.error 'Please enter Flickr keys'
|
153
|
+
super
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
# Can't find output path?
|
158
|
+
#
|
159
|
+
class SaveError < BaseError
|
160
|
+
def initialize(*args)
|
161
|
+
Flickrage.logger.error "Something wrong with output path: #{args[0]}"
|
162
|
+
super
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Here is something with imagemagick?
|
167
|
+
#
|
168
|
+
class ResizeError < BaseError
|
169
|
+
def initialize(*args)
|
170
|
+
Flickrage.logger.error "Something wrong with resize tools: #{args[0]}"
|
171
|
+
super
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Here is something with imagemagick?
|
176
|
+
#
|
177
|
+
class CollageError < BaseError
|
178
|
+
def initialize(*args)
|
179
|
+
Flickrage.logger.error "Something wrong with collage tools: #{args[0]}"
|
180
|
+
super
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|