strava-route-images 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b7e412212ecd6deaa61dadfb8e0766d5f62eecbd680fba5865e609ffb9fd964f
4
+ data.tar.gz: d88f520e201a3b4b3de07b6eda77da60ffb41e85caa68be96c42bd842c1f7d51
5
+ SHA512:
6
+ metadata.gz: b64814eea31ebe93f3a873131a6ea9e10e97253d10b95b40c58637e1e58a76a6e456da657eaaf103dcf5d696b8a798bb67bdb03f9c9f5be00e780f635c659891
7
+ data.tar.gz: efff1c07da5e9e942a84677ef17ad8569d4e16f3ba3a7fb57c531373d644c426dfee5ac7c34a867490d60feca5b2f059d6ea60864ef83c6dfa39af72361208db
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in strava-route-images.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Strava::Route::Images
2
+
3
+ Extract route and altimetry images from a Strava URL.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'strava-route-images'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install strava-route-images
20
+
21
+ ## Usage
22
+
23
+ Like
24
+
25
+ ```ruby
26
+ extractor = Strava::Route::Images.new('https://www.strava.com/routes/16026750')
27
+ extractor.extract
28
+ ```
29
+
30
+ will return a hash with the images:
31
+
32
+ ```ruby
33
+ {
34
+ :base => "/tmp/strava-base20181210-27554-1lsiexj.png",
35
+ :route => "/tmp/strava-route20181210-27554-tjeu61.png",
36
+ :altimetry => "/tmp/strava-altimetry20181210-27554-1lqirce.png"
37
+ }
38
+ ```
39
+
40
+ or specifying the file names:
41
+
42
+ ```ruby
43
+ extractor = Strava::Route::Images.new('https://www.strava.com/routes/16026750',
44
+ base: '/tmp/base.png',
45
+ route: '/tmp/route.png',
46
+ altimetry: '/tmp/altimetry.png'
47
+ )
48
+ ```
49
+ will return
50
+
51
+ ```ruby
52
+ {
53
+ :base => "/tmp/base.png",
54
+ :route => "/tmp/route.png",
55
+ :altimetry => "/tmp/altimetry.png"
56
+ }
57
+ ```
58
+
59
+ It's advised to run this on a background job, because extrating the screenshot
60
+ may be a slow and expensive job.
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
65
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
66
+ prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To
69
+ release a new version, update the version number in `version.rb`, and then run
70
+ `bundle exec rake release`, which will create a git tag for the version, push
71
+ git commits and tags, and push the `.gem` file to
72
+ [rubygems.org](https://rubygems.org).
73
+
74
+ ## Contributing
75
+
76
+ Bug reports and pull requests are welcome on GitHub at
77
+ https://github.com/[USERNAME]/strava-route-images.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "strava/route/images"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ module Strava
2
+ module Route
3
+ class Images
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require 'strava/route/images/version'
2
+ require 'tempfile'
3
+ require_relative './invalid_url.rb'
4
+
5
+ require 'selenium-webdriver'
6
+ require 'mini_magick'
7
+
8
+ module Strava
9
+ module Route
10
+ class Images
11
+ attr_reader :url, :base, :route, :altimetry
12
+
13
+ def initialize(url, options = {})
14
+ raise ::Strava::Route::InvalidUrl unless url.match?(/strava.com/)
15
+
16
+ @url = url
17
+ @base = options[:base] ||= "#{Tempfile.new('strava-base').path}.png"
18
+ @route = options[:route] ||= "#{Tempfile.new('strava-route').path}.png"
19
+ @altimetry = options[:altimetry] ||= "#{Tempfile.new('strava-altimetry').path}.png"
20
+ end
21
+
22
+ def extract
23
+ {
24
+ base: extract_screenshot,
25
+ route: extract_route,
26
+ altimetry: extract_altimetry
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def extract_screenshot
33
+ options = ::Selenium::WebDriver::Chrome::Options.new
34
+ options.add_argument('--headless')
35
+ driver = ::Selenium::WebDriver.for :chrome, options: options
36
+
37
+ driver.navigate.to @url
38
+ driver.manage.window.resize_to(1500, 900)
39
+ driver.save_screenshot @base
40
+ @base
41
+ end
42
+
43
+ def extract_route
44
+ image = MiniMagick::Image.open(@base)
45
+ image.crop '800x360+132+185'
46
+ image.write @route
47
+ @route
48
+ end
49
+
50
+ def extract_altimetry
51
+ image = MiniMagick::Image.open(@base)
52
+ image.crop '800x170+132+550'
53
+ image.write @altimetry
54
+ @altimetry
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module Strava
2
+ module Route
3
+ class InvalidUrl < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "strava/route/images/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "strava-route-images"
8
+ spec.version = Strava::Route::Images::VERSION
9
+ spec.authors = ["Eustaquio Rangel"]
10
+ spec.email = ["taq@eustaquiorangel.com"]
11
+
12
+ spec.summary = %q{Extract route images from a Strava URL}
13
+ spec.description = %q{With this gem we can extract images from the route and altimetry, from a Strava route URL}
14
+ spec.homepage = 'https://github.com/taq/strava-route-images'
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "selenium-webdriver"
27
+ spec.add_development_dependency "mini_magick"
28
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strava-route-images
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eustaquio Rangel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-10 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: mini_magick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: With this gem we can extract images from the route and altimetry, from
84
+ a Strava route URL
85
+ email:
86
+ - taq@eustaquiorangel.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/strava/route/images.rb
99
+ - lib/strava/route/images/version.rb
100
+ - lib/strava/route/invalid_url.rb
101
+ - strava-route-images.gemspec
102
+ homepage: https://github.com/taq/strava-route-images
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.7.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Extract route images from a Strava URL
125
+ test_files: []