scrape456 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: 744e74e6c259bd66a1c1c5de1e9bf14ecd9dcdc3ea220ee4ede52722444a6df0
4
+ data.tar.gz: 4ba0ef0d9fc9402b4b7e85eeccccddab3be4379b0488808497f4c926d5021afc
5
+ SHA512:
6
+ metadata.gz: 6fc0541f5347b32c32d8b4ad5c8e68b7977eb0ca2f4853c889cbf273906d358861036a5779e8c999efbf0536826448da9350f51b702e57d0aad08c19c12ad05d
7
+ data.tar.gz: 76fa66b62cfa1ef92482d96b9aec49593df98a49741822cad0bfdae4519fa94f03328ba0670f44e300bc55bfa80837adaa5183ec8867f4da328258e0e7055bb3
data/.envrc ADDED
@@ -0,0 +1,5 @@
1
+ if [ "$(type -t direnv_load)" = 'function' ]; then
2
+ PATH_add bin
3
+ fi
4
+ export LOGIN_USER_1=`pass show 123Signup\ AAC\ oca2 | grep '^login:' | head -n1 | cut -d' ' -f2`
5
+ export LOGIN_PASSWORD_1=`pass show 123Signup\ AAC\ oca2 | head -n1`
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.0
5
+ before_install: gem install bundler -v 1.16.1
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 scrape456.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ scrape456 (0.1.0)
5
+ poltergeist (~> 1.17)
6
+ rspec (~> 3.7.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ capybara (3.0.3)
14
+ addressable
15
+ mini_mime (>= 0.1.3)
16
+ nokogiri (~> 1.8)
17
+ rack (>= 1.6.0)
18
+ rack-test (>= 0.6.3)
19
+ xpath (~> 3.0)
20
+ cliver (0.3.2)
21
+ diff-lcs (1.3)
22
+ mini_mime (1.0.0)
23
+ mini_portile2 (2.3.0)
24
+ minitest (5.11.3)
25
+ nokogiri (1.8.2)
26
+ mini_portile2 (~> 2.3.0)
27
+ poltergeist (1.18.0)
28
+ capybara (>= 2.1, < 4)
29
+ cliver (~> 0.3.1)
30
+ websocket-driver (>= 0.2.0)
31
+ public_suffix (3.0.2)
32
+ rack (2.0.5)
33
+ rack-test (1.0.0)
34
+ rack (>= 1.0, < 3)
35
+ rake (10.5.0)
36
+ rspec (3.7.0)
37
+ rspec-core (~> 3.7.0)
38
+ rspec-expectations (~> 3.7.0)
39
+ rspec-mocks (~> 3.7.0)
40
+ rspec-core (3.7.1)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-expectations (3.7.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-mocks (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-support (3.7.1)
49
+ websocket-driver (0.7.0)
50
+ websocket-extensions (>= 0.1.0)
51
+ websocket-extensions (0.1.3)
52
+ xpath (3.0.0)
53
+ nokogiri (~> 1.8)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler (~> 1.16)
60
+ minitest (~> 5.0)
61
+ rake (~> 10.0)
62
+ scrape456!
63
+
64
+ BUNDLED WITH
65
+ 1.16.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ryan Platte
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ryan Platte
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,39 @@
1
+ # Scrape456
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/scrape456`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'scrape456'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install scrape456
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/scrape456.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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 "scrape456"
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/scrape456 ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'scrape456'
5
+
6
+ csv_result = Scrape456::Download.new(
7
+ username: ENV['LOGIN_USER_1'],
8
+ password: ENV['LOGIN_PASSWORD_1']
9
+ ).call
10
+
11
+ puts csv_result
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,109 @@
1
+ require 'capybara/poltergeist'
2
+ require 'rspec/expectations'
3
+ require 'capybara/rspec'
4
+ require 'open-uri'
5
+
6
+ module Scrape456
7
+
8
+ # Given a username and password, retrieves all event attendee data from 123Signup.
9
+ #
10
+ # Usage:
11
+ #
12
+ # csv_result = Scrape456::Download.new(
13
+ # username: ENV['LOGIN_USER_1'],
14
+ # password: ENV['LOGIN_PASSWORD_1']
15
+ # ).call
16
+ #
17
+ # puts csv_result
18
+ class Download
19
+ include ::RSpec::Matchers
20
+ include ::Capybara::RSpecMatchers
21
+
22
+ LOGIN_URL = 'https://redirect.123signup.com/login'
23
+ ONLOAD_REDIRECT_XPATH = "//body[contains(@onload,'pageLoadRedirect')]"
24
+ THIRTY_SECONDS = 30
25
+
26
+ def initialize(username:, password:)
27
+ @username = username
28
+ @password = password
29
+ set_up_capybara
30
+ end
31
+
32
+ def set_up_capybara
33
+ options = {}
34
+ Capybara.register_driver :poltergeist do |app|
35
+ Capybara::Poltergeist::Driver.new(app, options)
36
+ end
37
+ Capybara.current_driver = :poltergeist
38
+ Capybara.javascript_driver = :poltergeist
39
+ Capybara.run_server = false
40
+ Capybara.default_max_wait_time = THIRTY_SECONDS
41
+ end
42
+
43
+ def log_in
44
+ session.visit LOGIN_URL
45
+ session.fill_in 'username', with: @username
46
+ session.fill_in 'password', with: @password
47
+ session.click_link 'SignInButton'
48
+ end
49
+
50
+ def session
51
+ Capybara.current_session
52
+ end
53
+
54
+ def extract_redirect_url
55
+ onload_value = session.find('body')['onload']
56
+ lines = onload_value.split(';')
57
+ redirect_destination_abs_path = lines.grep(/pageLoadRedirect/).first.sub(/^.*"([^"]*)".*$/, '\1')
58
+ session.current_host + redirect_destination_abs_path
59
+ end
60
+
61
+ def fetch_csv_response_body
62
+ session.assert_selector('body')
63
+ expect(session.find('body')).to (
64
+ have_text(/^SignupMemberID,/)
65
+ ).or(
66
+ match_xpath(ONLOAD_REDIRECT_XPATH)
67
+ )
68
+ if session.find('body').matches_xpath?(ONLOAD_REDIRECT_XPATH)
69
+ csv_url = extract_redirect_url
70
+ session.visit(csv_url)
71
+ STDERR.puts "Report generated by 123Signup. Fetching CSV..."
72
+ csv_response_body = open(csv_url).read
73
+ STDERR.puts "CSV found. First 10 lines:"
74
+ STDERR.puts session.body.split("\n")[0..10].join("\n")
75
+ else
76
+ csv_response_body = session.body
77
+ end
78
+ csv_response_body
79
+ end
80
+
81
+ def extract_csv_from_full_response(full_response)
82
+ strip_regex = /\A<html.*<pre[^>]*>(SignupMemberID,.*)<\/pre><\/body><\/html>\z/m
83
+ full_response.sub(strip_regex, '\1')
84
+ end
85
+
86
+ def call
87
+ csv_result = nil
88
+
89
+ session = Capybara.current_session
90
+ STDERR.puts 'Logging in to 123Signup...'
91
+ log_in
92
+ session.within_frame('FrameApplication') do
93
+ session.within_frame('contents') do
94
+ session.within_frame('MenuList') do
95
+ STDERR.puts 'Navigating to reports...'
96
+ session.click_link 'Event Reports'
97
+ end
98
+ session.within_frame('Results') do
99
+ session.click_link('Event Attendee Data')
100
+ session.click_button 'BottomDownloadReport'
101
+ STDERR.puts 'Waiting on report download...'
102
+ csv_result = extract_csv_from_full_response(fetch_csv_response_body)
103
+ end
104
+ end
105
+ end
106
+ csv_result
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,22 @@
1
+ module Scrape456
2
+
3
+ # Returns filenames for successive screenshots. The resulting filenames sort
4
+ # by date and sequence and include descriptive labels.
5
+ #
6
+ # Usage example:
7
+ #
8
+ # shot_filenames = ScreenshotFilenameSequence.new
9
+ # ...
10
+ # session.save_screenshot(shot_filenames.next(:after_click_event_attendee_data))
11
+ #
12
+ class ScreenshotFilenameSequence
13
+ def initialize
14
+ @counter = 0
15
+ end
16
+
17
+ def next(label)
18
+ @counter += 1
19
+ Time.now.utc.iso8601 + '-' + ('%02d' % @counter) + '-' + label.to_s + '.png'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Scrape456
2
+ VERSION = "0.1.0"
3
+ end
data/lib/scrape456.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'scrape456/version'
2
+ require 'scrape456/download'
3
+
4
+ module Scrape456
5
+ end
data/scrape456.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "scrape456/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "scrape456"
7
+ spec.version = Scrape456::VERSION
8
+ spec.authors = ["Ryan Platte"]
9
+ spec.email = ["ryan@burnbush.net"]
10
+
11
+ spec.summary = %q{Export data from 123Signup sites.}
12
+ spec.homepage = "https://github.com/replaid/scrape456"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features|\.envrc)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "poltergeist", "~> 1.17"
23
+ spec.add_dependency "rspec", "~> 3.7"
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrape456
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Platte
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: poltergeist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description:
84
+ email:
85
+ - ryan@burnbush.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".envrc"
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/scrape456
101
+ - bin/setup
102
+ - lib/scrape456.rb
103
+ - lib/scrape456/download.rb
104
+ - lib/scrape456/screenshot_filename_sequence.rb
105
+ - lib/scrape456/version.rb
106
+ - scrape456.gemspec
107
+ homepage: https://github.com/replaid/scrape456
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.7.3
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Export data from 123Signup sites.
131
+ test_files: []