flickit 0.1.0
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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +6 -0
- data/.idea/misc.xml +14 -0
- data/.idea/modules.xml +8 -0
- data/.idea/untitled.iml +41 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +738 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +20 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/flickit +10 -0
- data/bin/setup +7 -0
- data/flickit.gemspec +24 -0
- data/lib/collage.rb +67 -0
- data/lib/flickit.rb +10 -0
- data/lib/flickit/version.rb +3 -0
- data/lib/flickr_api.rb +47 -0
- data/lib/keywords_controller.rb +51 -0
- metadata +98 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 iferunsewe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Flickit README
|
|
2
|
+
|
|
3
|
+
Assuming you have the latest version of Ruby of your system, use the following steps to create the collage from flickit.
|
|
4
|
+
|
|
5
|
+
1. Install bundler via 'gem install bundler'
|
|
6
|
+
|
|
7
|
+
2. Now at the root of this project, please enter 'bundle install' to install all of the gems needed for flickit
|
|
8
|
+
|
|
9
|
+
3. To install the gem flickit, enter "gem install flickit"
|
|
10
|
+
|
|
11
|
+
4. Now you should be able to enter 'flickit' plus a maximum of ten keywords.
|
|
12
|
+
|
|
13
|
+
If you enter less than ten keywords, a random word will be picked until a photo can be prhoduced.
|
|
14
|
+
|
|
15
|
+
5. Once you see the message 'CREATED COLLAGE', a collage will have been created on your desktop named 'flickr_collage.jpg'.
|
|
16
|
+
|
|
17
|
+
6. Open flickr_collage.jpg and you will see the images.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Thanks you!!!
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "untitled"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/flickit
ADDED
data/bin/setup
ADDED
data/flickit.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'flickit/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "flickit"
|
|
8
|
+
spec.version = FlickIt::VERSION
|
|
9
|
+
spec.authors = ["iferunsewe"]
|
|
10
|
+
spec.email = ["iferunsewe@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Create collage of flickr images"
|
|
13
|
+
spec.description = "Creates collage of flickr images. Includes random words if less than ten arguments are entered."
|
|
14
|
+
spec.homepage = "https://github.com/iferunsewe/flickr-collage"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
19
|
+
spec.executables = ["flickit"]
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
end
|
data/lib/collage.rb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module FlickIt
|
|
2
|
+
class Collage
|
|
3
|
+
def initialize
|
|
4
|
+
@image = Magick::Image
|
|
5
|
+
@image_list = Magick::ImageList.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Collates all of the images and creates collage
|
|
9
|
+
def create(photos)
|
|
10
|
+
added_local_image_files = add_local_image_files(photos)
|
|
11
|
+
add_to_images_list(added_local_image_files)
|
|
12
|
+
montage_it.write(ENV['HOME'] + '/Desktop/flickr_collage.jpg')
|
|
13
|
+
puts "CREATED COLLAGE"
|
|
14
|
+
end
|
|
15
|
+
# Removes images from image folder
|
|
16
|
+
def delete_images
|
|
17
|
+
FileUtils.rm_rf(Dir.glob('./lib/images/*'))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Creates local images from data in api
|
|
24
|
+
def add_local_image_files(photos)
|
|
25
|
+
photos.map do |photo|
|
|
26
|
+
path = "./lib/images/#{photo['id']}.jpg"
|
|
27
|
+
open(path, 'wb') do |file|
|
|
28
|
+
file << open(create_photo_url(photo)).read
|
|
29
|
+
end
|
|
30
|
+
photo.merge!({'local_path' => open(path)})
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Creates image url to get photo from
|
|
35
|
+
def create_photo_url(photo)
|
|
36
|
+
"http://farm#{photo['farm']}.static.flickr.com/#{photo['server']}/#{photo['id']}_#{photo['secret']}.jpg"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Crops photo
|
|
40
|
+
def crop(photo)
|
|
41
|
+
@image.read(photo['local_path']).first.crop!(300, 400, 300, 400)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Adds images to image list to use to create montage
|
|
45
|
+
def add_to_images_list(photos)
|
|
46
|
+
photos.each do |photo|
|
|
47
|
+
img = @image.read(photo['local_path']).first
|
|
48
|
+
img.border!(30, 30, "#ffffff")
|
|
49
|
+
@image_list << img
|
|
50
|
+
end
|
|
51
|
+
@image_list
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Creates montage and forms an image
|
|
55
|
+
def montage_it(image_list = @image_list)
|
|
56
|
+
photo_width = 250
|
|
57
|
+
photo_height = 250
|
|
58
|
+
padding_between_column = 0
|
|
59
|
+
padding_between_row = 0
|
|
60
|
+
montaged_image = image_list.montage do
|
|
61
|
+
self.tile = "2x5"
|
|
62
|
+
self.geometry = "#{photo_width}x#{photo_height}+#{padding_between_column}+#{padding_between_row}"
|
|
63
|
+
end
|
|
64
|
+
montaged_image.flatten_images
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
data/lib/flickit.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require './lib/flickit/version'
|
|
2
|
+
require './lib/flickr_api'
|
|
3
|
+
require './lib/keywords_controller'
|
|
4
|
+
require './lib/collage'
|
|
5
|
+
require 'active_support/all'
|
|
6
|
+
require 'flickraw'
|
|
7
|
+
require 'pry-byebug'
|
|
8
|
+
require 'httparty'
|
|
9
|
+
require 'rmagick'
|
|
10
|
+
require 'open-uri'
|
data/lib/flickr_api.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'rmagick'
|
|
2
|
+
|
|
3
|
+
module FlickIt
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
class FlickrApi
|
|
7
|
+
include Magick
|
|
8
|
+
|
|
9
|
+
def initialize(keywords=nil)
|
|
10
|
+
@keywords = keywords
|
|
11
|
+
@flickr_endpoint = 'https://api.flickr.com/services/rest/'
|
|
12
|
+
@api_key = "920490d1b6ca2176925a316eb1ed4861"
|
|
13
|
+
@default_query = {'api_key' => @api_key}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Default request for flickr api
|
|
17
|
+
def request_flickr_api(method, params={})
|
|
18
|
+
puts "Requesting the flickr api request for the method #{method}"
|
|
19
|
+
query = {"method" => method}.merge! params
|
|
20
|
+
query.merge! @default_query
|
|
21
|
+
response = HTTParty.post(@flickr_endpoint, :query => query)
|
|
22
|
+
raise "The flickr api request for the method #{method} is returning a #{response.code} response code" unless response.code == 200
|
|
23
|
+
response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Api call for the search method in the flickr api, sorted by the most interesting photos
|
|
27
|
+
def get_flickr_search_result(keyword)
|
|
28
|
+
response = request_flickr_api('flickr.photos.search', {"tags" => keyword, "sort" => 'interestingness-desc'})
|
|
29
|
+
photos = response["rsp"]["photos"]["photo"]
|
|
30
|
+
if photos.nil?
|
|
31
|
+
puts "Didn't find any photos for #{keyword}"
|
|
32
|
+
else
|
|
33
|
+
puts "Found some photos for #{keyword}"
|
|
34
|
+
end
|
|
35
|
+
photos
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def sort_results(keyword_results = get_flickr_results)
|
|
40
|
+
keyword_results.map! do |results|
|
|
41
|
+
results.first
|
|
42
|
+
end
|
|
43
|
+
keyword_results
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module FlickIt
|
|
2
|
+
class KeywordsController
|
|
3
|
+
def initialize
|
|
4
|
+
@flickr_api = FlickrApi.new
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
# Gets keywords from command line and creates an array of images for the keywords. Fills the array with random key word if there are less than 10 words entered or replaces the word if a photo is not found
|
|
8
|
+
def get_photos_for_keywords
|
|
9
|
+
keywords = ARGV.map do |keyword|
|
|
10
|
+
puts "Getting photos for #{keyword}"
|
|
11
|
+
photo_results = @flickr_api.get_flickr_search_result(keyword)
|
|
12
|
+
if photo_results.nil?
|
|
13
|
+
puts "No photos found for #{keyword}"
|
|
14
|
+
photo_results = get_random_keyword_photos
|
|
15
|
+
end
|
|
16
|
+
photo_results.first
|
|
17
|
+
end
|
|
18
|
+
fill_keywords_array(keywords)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# Fills keywords array with random word
|
|
24
|
+
def fill_keywords_array(keywords)
|
|
25
|
+
missing_keywords = 10 - keywords.length
|
|
26
|
+
puts "Filling the keywords array with photos for #{missing_keywords} keywords"
|
|
27
|
+
if missing_keywords != 0
|
|
28
|
+
missing_keywords.times do
|
|
29
|
+
keywords << get_random_keyword_photos.first
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
keywords
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Picks random word from system dictionary
|
|
36
|
+
def random_word
|
|
37
|
+
open('/usr/share/dict/words').read.split(/\n/).sample
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Gets photo for random keyword
|
|
41
|
+
def get_random_keyword_photos
|
|
42
|
+
puts "Finding photos for a random word"
|
|
43
|
+
random_photo_result = @flickr_api.get_flickr_search_result(random_word) until random_photo_result.present? &&
|
|
44
|
+
random_photo_result.first.class == Hash &&
|
|
45
|
+
(['farm', 'server', 'secret'].any? do |key|
|
|
46
|
+
random_photo_result.first.key?(key)
|
|
47
|
+
end)
|
|
48
|
+
random_photo_result
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: flickit
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- iferunsewe
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.9'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.9'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: Creates collage of flickr images. Includes random words if less than
|
|
42
|
+
ten arguments are entered.
|
|
43
|
+
email:
|
|
44
|
+
- iferunsewe@gmail.com
|
|
45
|
+
executables:
|
|
46
|
+
- flickit
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files: []
|
|
49
|
+
files:
|
|
50
|
+
- ".DS_Store"
|
|
51
|
+
- ".gitignore"
|
|
52
|
+
- ".idea/.name"
|
|
53
|
+
- ".idea/.rakeTasks"
|
|
54
|
+
- ".idea/encodings.xml"
|
|
55
|
+
- ".idea/misc.xml"
|
|
56
|
+
- ".idea/modules.xml"
|
|
57
|
+
- ".idea/untitled.iml"
|
|
58
|
+
- ".idea/vcs.xml"
|
|
59
|
+
- ".idea/workspace.xml"
|
|
60
|
+
- Gemfile
|
|
61
|
+
- LICENSE.txt
|
|
62
|
+
- README.md
|
|
63
|
+
- Rakefile
|
|
64
|
+
- bin/console
|
|
65
|
+
- bin/flickit
|
|
66
|
+
- bin/setup
|
|
67
|
+
- flickit.gemspec
|
|
68
|
+
- lib/collage.rb
|
|
69
|
+
- lib/flickit.rb
|
|
70
|
+
- lib/flickit/version.rb
|
|
71
|
+
- lib/flickr_api.rb
|
|
72
|
+
- lib/keywords_controller.rb
|
|
73
|
+
homepage: https://github.com/iferunsewe/flickr-collage
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata: {}
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 2.4.6
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Create collage of flickr images
|
|
97
|
+
test_files: []
|
|
98
|
+
has_rdoc:
|