nypl-site-scraper 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b51638e35e43cd30bfcd290095e94d2a6b0a9a77
4
+ data.tar.gz: d0f055e818633850850acebdf5762a69cc78d9b8
5
+ SHA512:
6
+ metadata.gz: 151184cbadf8a2e37e6e3db7955e87ce5681218d18ae7467d2427d37610a75bfdad1e1218f74e57312ff15c65e8d070492cc25d18544f26fa573b663031120f6
7
+ data.tar.gz: 8d1b57050ae900ad0e11d8a5cf38d6fa7da8931ee031996c566012dda3307b8aeae9aa67b6190cbc4200db511428e3c0ecdbbbe72323bdf82a05146bc3832cf1
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ nypl-site-scraper
@@ -0,0 +1 @@
1
+ ruby-2.4.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nypl-site-scraper.gemspec
4
+ gemspec
@@ -0,0 +1,51 @@
1
+ # NYPL Site Scraper
2
+
3
+ A (mechanize)[https://github.com/sparklemotion/mechanize] driven library for
4
+ getting information about your NYPL account by web scraping.
5
+
6
+ This library is an abstraction to get info from your account.
7
+ If you really want to concern yourself with markup, you're better off
8
+ using mechanize directly.
9
+
10
+ Examples of what it can get are your:
11
+
12
+ * Current Holds
13
+ * Fines (not implemented yet)
14
+ * Current Checkouts (not implemented yet)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'nypl-site-scraper'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install nypl-site-scraper
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ client = NyplSiteScraper::Client.new(barcode: '11111111111111', pin: '2222')
36
+
37
+ client.login! # This is the network call
38
+
39
+ client.get_holds
40
+ # {"holds"=>[{"title"=>"Persepolis. English", "statusString"=>"READY FOR PICKUP", "status"=>"ready", "pickupLocation"=>"Mid-Manhattan Library at 42nd St"}...
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ 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).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nodanaonlyzuul/nypl-site-scraper.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nypl_site_scraper/scraper"
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
@@ -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,68 @@
1
+ require 'mechanize'
2
+
3
+ module NyplSiteScraper
4
+ class Client
5
+
6
+ attr_reader :pin, :barcode, :homepage
7
+
8
+ def initialize(options = {barcode: nil, })
9
+ @barcode = options[:barcode]
10
+ @pin = options[:pin]
11
+ @agent = Mechanize.new
12
+ end
13
+
14
+ def login!
15
+ login_page = @agent.get('https://catalog.nypl.org/iii/cas/login?service=https%3A%2F%2Fcatalog.nypl.org%3A443%2Fpatroninfo~S1%2FIIITICKET&scope=1')
16
+ form = login_page.form
17
+ form.code = barcode
18
+ form.pin = pin
19
+ @homepage = @agent.submit(form, form.buttons.first)
20
+ true
21
+ end
22
+
23
+ def get_holds
24
+ @holds_page ||= @homepage.link_with(text: "My Holds").click
25
+ holds_rows = @holds_page.css('tr.patFuncEntry')
26
+
27
+ response_holds = []
28
+
29
+ holds_rows.each do |hold_row|
30
+ status_string = hold_row.css('td.patFuncStatus').text.strip
31
+ response_holds << {
32
+ title: hold_row.css('td.patFuncTitle').text.strip,
33
+ statusString: status_string,
34
+ status: map_status_string(status_string),
35
+ pickupLocation: get_pickup_location(hold_row),
36
+ }
37
+ end
38
+ {holds: response_holds}
39
+ end
40
+ private
41
+
42
+ def map_status_string(status_string)
43
+
44
+ if status_string == "READY FOR PICKUP"
45
+ return "ready"
46
+ elsif status_string == "IN TRANSIT"
47
+ return "in transit"
48
+ elsif status_string.include?('of')
49
+ return "pending"
50
+ else
51
+ return status_string
52
+ end
53
+ end
54
+
55
+ # Helper because markup for pending vs ready is different
56
+ def get_pickup_location(row)
57
+ pickUpCell = row.css('td.patFuncPickup')
58
+ if pickUpCell.search('div.patFuncPickupLabel').length > 0
59
+ row.css('td.patFuncPickup option[selected=selected]').first.text.strip
60
+ # pickUpCell.search('div.patFuncPickupLabel').text.strip
61
+ else
62
+ pickUpCell.text.strip
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,3 @@
1
+ module NyplSiteScraper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nypl_site_scraper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nypl-site-scraper"
8
+ spec.version = NyplSiteScraper::VERSION
9
+ spec.authors = ["nodanaonlyzuul"]
10
+ spec.licenses = ['MIT']
11
+ spec.summary = %q{A mechanize-driven client to scrape info about your account from NYPL}
12
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
13
+ spec.homepage = "http://github.com/nodanaonlyzuul/nypl-site-scraper"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against " \
21
+ "public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
25
+ f.match(%r{^(test|spec|features)/})
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.3'
32
+ spec.add_development_dependency "pry", '~> 0.11.3'
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nypl-site-scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nodanaonlyzuul
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.7.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.7.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.11.3
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.11.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.13'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.13'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description:
76
+ email:
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".ruby-gemset"
83
+ - ".ruby-version"
84
+ - Gemfile
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/nypl_site_scraper/scraper.rb
90
+ - lib/nypl_site_scraper/version.rb
91
+ - nypl-site-scraper.gemspec
92
+ homepage: http://github.com/nodanaonlyzuul/nypl-site-scraper
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.14
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: A mechanize-driven client to scrape info about your account from NYPL
117
+ test_files: []