Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test member data #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ rvm:
- 2.3.3
sudo: false
cache: bundler
script:
- bash <(curl -fsSL https://github.com/everypolitician/ensure-regression-tests/raw/v0.1.0/ensure-regression-tests)
- bundle exec rake
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem 'rake'
gem 'rubocop'
gem 'scraped', github: 'everypolitician/scraped'
gem 'scraped_page_archive', github: 'everypolitician/scraped_page_archive'
gem 'scraper_test', github: 'everypolitician/scraper_test'
gem 'scraperwiki', github: 'openaustralia/scraperwiki-ruby',
branch: 'morph_defaults'
gem 'table_unspanner', github: 'everypolitician/table_unspanner'
Expand Down
13 changes: 12 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ GIT
git (~> 1.3.0)
vcr-archive (~> 0.3.0)

GIT
remote: https://github.com/everypolitician/scraper_test.git
revision: a8a6c795ea1544bc95e2f7a1dbb132ba8c80ed98
specs:
scraper_test (0.1.0)
minitest (~> 5.0)
pry
vcr (>= 3.0.3)
webmock (>= 2.0)

GIT
remote: https://github.com/everypolitician/table_unspanner.git
revision: a70a98a104a75b470f4ea339fdd728366a40b4d8
Expand Down Expand Up @@ -105,6 +115,7 @@ DEPENDENCIES
rubocop
scraped!
scraped_page_archive!
scraper_test!
scraperwiki!
table_unspanner!
vcr
Expand All @@ -114,4 +125,4 @@ RUBY VERSION
ruby 2.3.3p222

BUNDLED WITH
1.13.6
1.14.6
8 changes: 6 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true
require 'rubocop/rake_task'

require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: %w(rubocop)
require 'scraper_test'
ScraperTest::RakeTask.new.install_tasks

task test: 'test:data'
task default: %w(rubocop test)
44 changes: 44 additions & 0 deletions lib/member_link.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true
require 'scraped'

class MemberLink < Scraped::HTML
field :id do
noko.attr('data-siege')
end

field :name do
noko.attr('data-nom')
end

field :image do
URI.join(url, URI.escape(noko.attr('data-photo').to_s.sub('.thumb50', ''))).to_s
end

field :partylist do
noko.attr('data-liste')
end

field :faction do
noko.attr('data-bloc')
end

field :faction_id do
noko.attr('data-groupe_id')
end

field :area do
noko.attr('data-region')
end

field :gender do
gender = noko.attr('data-sexe')
return if gender.to_s.empty?
return 'male' if gender == 'Hommes'
return 'female' if gender == 'Femmes'
raise "Unknown gender: #{gender}"
end

field :source do
noko.attr('href')
end
end
44 changes: 2 additions & 42 deletions scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,12 @@
require 'scraped'
require 'scraperwiki'

require_rel 'lib'

# require 'open-uri/cached'
# OpenURI::Cache.cache_path = '.cache'
require 'scraped_page_archive/open-uri'

class MemberLink < Scraped::HTML
field :id do
noko.attr('data-siege')
end

field :name do
noko.attr('data-nom')
end

field :image do
URI.join(url, URI.escape(noko.attr('data-photo').to_s.sub('.thumb50', ''))).to_s
end

field :partylist do
noko.attr('data-liste')
end

field :faction do
noko.attr('data-bloc')
end

field :faction_id do
noko.attr('data-groupe_id')
end

field :area do
noko.attr('data-region')
end

field :gender do
gender = noko.attr('data-sexe')
return if gender.to_s.empty?
return 'male' if gender == 'Hommes'
return 'female' if gender == 'Femmes'
raise "Unknown gender: #{gender}"
end

field :source do
noko.attr('href')
end
end

class MembersPage < Scraped::HTML
decorator Scraped::Response::Decorator::AbsoluteUrls

Expand Down
Loading