flickxtractr 0.3.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4d14c2c74500f2ea0d0d0715ca29c90777697dd2
4
+ data.tar.gz: a0125fb21234e9841c0eb04f8c7adb012dac2ea6
5
+ SHA512:
6
+ metadata.gz: f442e047249610a262bd28cd2852d41508c13a880e6f8d313cb5b01d76d725bd7bde194034d1dee542926eec44e4978b9c125aebc3a1c42097fbe4772cf8ed59
7
+ data.tar.gz: c58b648570ff4718f1e61f6d3f44fabe33cd4320d97c87a6781c7de2ed8edb24a0dda32fb3b31f71a1d54aa506e17ff75200e7d22e732424ef444c215704eb4f
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ .ruby-version
33
+ .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gem.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 RootsRated Inc.
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.
@@ -0,0 +1,37 @@
1
+ # Flickxtractr
2
+
3
+ A quick micro-service for downloading a Flickr image and attaching
4
+ additional meta-data from a web scrape.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'flickxtractr'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install flickxtractr
21
+
22
+ Add dependent libraries:
23
+
24
+ $ brew install phantomjs
25
+ $ brew install exiftool
26
+
27
+ ## Usage
28
+
29
+ TODO: Write usage instructions here
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/RootsRated/flickxtractr/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,2 @@
1
+ require 'flickxtractr'
2
+ require 'flickxtractr/cli'
@@ -0,0 +1,4 @@
1
+ <form action="/extract" method="post">
2
+ <input name="url">
3
+ <input type="submit">
4
+ </form>
@@ -0,0 +1,5 @@
1
+ bitly_access_token:
2
+ ding_on_complete?: true
3
+ output_dir: ./
4
+ screenshot_dir: ./
5
+ screenshot_public_url_prefix:
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'flickxtractr/cli'
5
+ Flickxtractr::CLI.start(ARGV.dup)
6
+ rescue LoadError => e
7
+ abort "#{e.inspect} - perhaps you need to run using `bundle exec`?"
8
+ end
@@ -0,0 +1,2 @@
1
+ require 'flickxtractr/app'
2
+ run Flickxtractr::App
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flickxtractr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flickxtractr"
8
+ spec.version = Flickxtractr::VERSION
9
+ spec.authors = ["RootsRated"]
10
+ spec.email = ["developers@rootsrated.com"]
11
+ spec.summary = %q{An image +meta extraction tool}
12
+ spec.description = %q{An image +meta extraction tool}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 = %w{app lib}
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency "bitly"
25
+ spec.add_dependency "capybara"
26
+ spec.add_dependency "hashie", "~> 3.4"
27
+ spec.add_dependency "mini_exiftool"
28
+ spec.add_dependency "poltergeist"
29
+ spec.add_dependency "sinatra"
30
+ spec.add_dependency "thor"
31
+ end
@@ -0,0 +1,11 @@
1
+ require "flickxtractr/version"
2
+
3
+ module Flickxtractr
4
+ autoload :App, 'flickxtractr/app'
5
+ autoload :Dotfile, 'flickxtractr/dotfile'
6
+ autoload :Extractr, 'flickxtractr/extractr'
7
+
8
+ def self.dotfile
9
+ @_dotfile ||= Dotfile.new
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ require 'sinatra'
2
+
3
+ module Flickxtractr
4
+ class App < Sinatra::Base
5
+ set :erb, :format => :html5
6
+ set :views, ['./app/views']
7
+
8
+ get '/' do
9
+ erb :home
10
+ end
11
+
12
+ post '/extract' do
13
+ "Extract!"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,69 @@
1
+ require 'flickxtractr'
2
+ require 'thor'
3
+
4
+ module Flickxtractr
5
+ class CLI < Thor
6
+ package_name 'Flickxtractr'
7
+
8
+ desc "install", "Install library dependencies"
9
+ def install
10
+ # Install Dependencies
11
+ %w{ exiftool phantomjs }.each do |dependency|
12
+ `brew install #{dependency}`
13
+ end
14
+
15
+ # Generate dotfile
16
+ Dotfile.install unless Dotfile.exists?
17
+ end
18
+
19
+ desc "extract URL", "Extract and enrich flickr image"
20
+ def extract(flickr_url)
21
+ print_extract_output("Loading", "Loading","Loading","Loading","Loading")
22
+
23
+ extractr = Flickxtractr::Extractr.new(flickr_url)
24
+ clear_output! && print_extract_output(
25
+ extractr.page_image_title,
26
+ extractr.page_image_description,
27
+ extractr.page_owner_name,
28
+ "Generating . . .",
29
+ "Generating . . .",
30
+ )
31
+
32
+ extractr.generate_image!
33
+
34
+ clear_output! && print_extract_output(
35
+ extractr.page_image_title,
36
+ extractr.page_image_description,
37
+ extractr.page_owner_name,
38
+ extractr.generated_image_file_name_with_extension,
39
+ extractr.generated_screenshot_file_name,
40
+ )
41
+
42
+ ding! if Flickxtractr.dotfile.ding_on_complete?
43
+ end
44
+
45
+ private
46
+
47
+ def print_extract_output(title, description, author, download, screenshot)
48
+ print <<-EOF
49
+ ---------------------------------------------------
50
+ Name #{title}
51
+ Description #{description}
52
+ Author #{author}
53
+ - - - - - - - - - - - - - - - - - - - - - - - - - -
54
+ Download #{download}
55
+ Screenshot #{screenshot}
56
+ ---------------------------------------------------
57
+ EOF
58
+ STDOUT.flush
59
+ end
60
+
61
+ def clear_output!
62
+ 8.times { print "\033[A", "\033[K" }
63
+ end
64
+
65
+ def ding!
66
+ print "\a"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ require 'delegate'
2
+ require 'hashie/mash'
3
+ require 'yaml'
4
+
5
+ module Flickxtractr
6
+ class Dotfile < SimpleDelegator
7
+
8
+ TEMPLATE_PATH = File.join(File.dirname(__FILE__), '..', '..', 'assets', 'dotfile.yml')
9
+ DOTFILE_FILENAME = ".flickxtractr"
10
+
11
+ class << self
12
+ def install
13
+ FileUtils.copy TEMPLATE_PATH, path
14
+ end
15
+
16
+ def path
17
+ File.join(user_path, DOTFILE_FILENAME)
18
+ end
19
+
20
+ def exists?
21
+ File.exist? path
22
+ end
23
+
24
+ private
25
+
26
+ def user_path
27
+ Dir.home rescue ENV.fetch('HOME', "/")
28
+ end
29
+ end
30
+
31
+ def initialize
32
+ dotfile_path = File.exist?(self.class.path) ? self.class.path : TEMPLATE_PATH
33
+ super Hashie::Mash.new YAML.load_file(dotfile_path)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,140 @@
1
+ require 'bitly'
2
+ require 'capybara'
3
+ require 'capybara/dsl'
4
+ require 'capybara/poltergeist'
5
+ require 'mini_exiftool'
6
+
7
+ module Flickxtractr
8
+ class Extractr
9
+ include Capybara::DSL
10
+
11
+ attr_reader :url
12
+
13
+ def initialize(url)
14
+ @url = url
15
+
16
+ initialize_capybara!
17
+ end
18
+
19
+ def generate_image!
20
+ generate_page_screenshot!
21
+
22
+ image_file = generate_image_file!
23
+ apply_meta_from_extract!(image_file)
24
+ end
25
+
26
+ def page_image_uri
27
+ @_page_image_uri ||= begin
28
+ find(:css, "div.download a").click
29
+ within("div.download-dialog-tooltip ul.sizes") do
30
+ URI(find(:xpath, "./li[@class='Original']/a")[:href])
31
+ end
32
+ end
33
+ end
34
+
35
+ def generated_image_file_name
36
+ "#{Date.today.strftime("%Y%m%d")}_#{generated_image_slug}"
37
+ end
38
+
39
+ def generated_image_file_name_with_extension
40
+ "#{generated_image_file_name}.#{page_image_uri.path.match(/\.(.+?)\z/)[1]}"
41
+ end
42
+
43
+ def generated_screenshot_file_name
44
+ "#{generated_image_file_name}_screenshot.png"
45
+ end
46
+
47
+ def generated_image_slug
48
+ page_image_title.gsub(/\W+/, '-').downcase.gsub(/\A-|-\Z/, '')
49
+ end
50
+
51
+ def page_image_title
52
+ find(:css, "h1.photo-title").text
53
+ end
54
+
55
+ def page_image_description
56
+ all(:css, "h2.photo-desc p").collect(&:text).join("\n")
57
+ end
58
+
59
+ def page_image_keywords
60
+ tag_links = all(:css, "ul.tags-list li a")
61
+ tag_links.collect { |a| a[:title] unless a.has_selector?(".remove-tag") }.compact.join("; ")
62
+ end
63
+
64
+ def page_owner_name
65
+ find(:css, "div.attribution-info a.owner-name.truncate").text
66
+ end
67
+
68
+ def page_owner_profile
69
+ "https://www.flickr.com#{find(:css, "div.attribution-info a.owner-name.truncate")[:href]}"
70
+ end
71
+
72
+ private
73
+
74
+ def initialize_capybara!
75
+ Capybara.current_driver = :poltergeist
76
+ Capybara.javascript_driver = :poltergeist
77
+ visit(url)
78
+ end
79
+
80
+ def generate_image_file!
81
+ File.open(File.join(Flickxtractr.dotfile.output_dir, generated_image_file_name_with_extension), "wb").tap do |f|
82
+ Net::HTTP.start(page_image_uri.host) do |http|
83
+ begin
84
+ http.request_get(page_image_uri.path) do |resp|
85
+ resp.read_body do |segment|
86
+ f.write(segment)
87
+ end
88
+ end
89
+ ensure
90
+ f.close
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ def generate_page_screenshot!
97
+ page.save_screenshot(File.join(Flickxtractr.dotfile.screenshot_dir, generated_screenshot_file_name), full: true)
98
+ end
99
+
100
+ def apply_meta_from_extract!(image_file)
101
+ MiniExiftool.new(image_file.path).tap do |rmi|
102
+ image_meta.each { |k, v| rmi[k] = v }
103
+ rmi.save!
104
+ end
105
+ end
106
+
107
+ def image_meta
108
+ {
109
+ "Headline" => page_image_title,
110
+ "Description" => page_image_description,
111
+ "Keywords" => page_image_keywords,
112
+ "Credit" => page_owner_name,
113
+ "Credit Line" => page_owner_name,
114
+ "Source" => shortened_url_for(url).short_url,
115
+ "Instructions" => shortened_url_for(public_screenshot_url).short_url,
116
+ }
117
+ end
118
+
119
+ def public_screenshot_url
120
+ "#{Flickxtractr.dotfile.screenshot_public_url_prefix}/#{generated_screenshot_file_name}"
121
+ end
122
+
123
+ def shortened_url_for(url_to_shorten)
124
+ self.class.bitly_client.shorten(url_to_shorten)
125
+ end
126
+
127
+ def self.bitly_client
128
+ @_bitly_client ||= begin
129
+ Bitly.use_api_version_3
130
+
131
+ Bitly.configure do |config|
132
+ config.api_version = 3
133
+ config.access_token = Flickxtractr.dotfile.bitly_access_token
134
+ end
135
+
136
+ Bitly.client
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ module Flickxtractr
2
+ VERSION = "0.3.0"
3
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickxtractr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - RootsRated
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-26 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ - !ruby/object:Gem::Dependency
42
+ name: bitly
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mini_exiftool
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: poltergeist
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sinatra
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: An image +meta extraction tool
140
+ email:
141
+ - developers@rootsrated.com
142
+ executables:
143
+ - flickxtractr
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - Thorfile
153
+ - app/views/home.erb
154
+ - assets/dotfile.yml
155
+ - bin/flickxtractr
156
+ - config.ru
157
+ - flickxtractr.gemspec
158
+ - lib/flickxtractr.rb
159
+ - lib/flickxtractr/app.rb
160
+ - lib/flickxtractr/cli.rb
161
+ - lib/flickxtractr/dotfile.rb
162
+ - lib/flickxtractr/extractr.rb
163
+ - lib/flickxtractr/version.rb
164
+ homepage: ''
165
+ licenses:
166
+ - MIT
167
+ metadata: {}
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - app
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.4.8
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: An image +meta extraction tool
189
+ test_files: []