Skip to content

Commit

Permalink
Figure out how to properly test la caixa
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Dec 15, 2011
1 parent 4be1199 commit 1b4fcf0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 41 deletions.
4 changes: 3 additions & 1 deletion bin/autility
Expand Up @@ -83,7 +83,9 @@ command :lacaixa do |c|
raise "Both --user and --password are required options." unless options.user && options.password

result = Autility::LaCaixa.scrape(options.user, options.password, options.month, options.output_folder)
puts "Path: #{result}"
result.each do |document_path|
puts "Path: #{document_path}"
end
end
end

29 changes: 21 additions & 8 deletions lib/autility/lacaixa.rb
Expand Up @@ -39,17 +39,21 @@ def initialize(user, password, month, folder)
@year = Time.now.year
end

# Public: Scrapes the vodafone website and gets the invoice for the current
# Public: Scrapes the lacaixa website and gets the invoice for the current
# month, saving it to @folder.
#
# Returns the String path of the saved document.
def scrape
def scrape(index=nil)
setup_capybara
log_in

FileUtils.mkdir_p(@folder)
filename = "#{@folder}/lacaixa_#{month}_#{@year}.pdf"
document.save(filename)
if index
filename = "#{@folder}/lacaixa_#{month}_#{@year}__#{index}.pdf"
document(index).save(filename)
else
return document
end
filename
end

Expand All @@ -69,7 +73,7 @@ def log_in
# fetched yet).
#
# Returns the Document to be fetched.
def document
def document(index=nil)
@document ||= begin
params = {}
url = "https://loc6.lacaixa.es"
Expand All @@ -86,15 +90,24 @@ def document

within_frame(all('frame')[1][:name]) do
within_frame('Cos') do
sleep 3
find("#lbl_Varios a").click
p "CLICKED!"
binding.pry
sleep 3
wait_until { find('#enlaceDescr') }
rows = all('.table_generica tr').select do |tr|
tr.find("td").text =~ /#{month}\/#{@year}/
end

rows.first.find("a").click
if index
rows[index].find("a").click
else
docs = []
rows.each_with_index do |row, idx|
scraper = LaCaixa.new(@user, @password, @month, @folder)
docs << scraper.scrape(idx)
end
return docs
end
end
end

Expand Down
32 changes: 0 additions & 32 deletions test/autility/lacaixa_test.rb

This file was deleted.

0 comments on commit 1b4fcf0

Please sign in to comment.