bankjob 0.5.0 → 0.5.1
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.
- data/History.txt +4 -1
- data/lib/bankjob.rb +1 -1
- data/lib/bankjob/scraper.rb +1 -1
- data/lib/bankjob/support.rb +54 -0
- data/scrapers/bpi_scraper.rb +16 -1
- metadata +2 -2
data/History.txt
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
== 0.
|
|
1
|
+
== 0.5.1 2009-04-20
|
|
2
|
+
* 1 minor enhancement:
|
|
3
|
+
* bpi_scraper.rb now accepts an optional third argument for the account number. Entering a number will cause the scraper to scrape that account rather than the default account.
|
|
2
4
|
|
|
5
|
+
== 0.5.0 2009-04-14
|
|
3
6
|
* 1 major enhancement:
|
|
4
7
|
* Initial release
|
data/lib/bankjob.rb
CHANGED
data/lib/bankjob/scraper.rb
CHANGED
data/lib/bankjob/support.rb
CHANGED
|
@@ -79,7 +79,54 @@ module Bankjob
|
|
|
79
79
|
return amt.to_f
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
##
|
|
83
|
+
# Finds a selector field in a named +form+ in the given Mechanize +page+, selects
|
|
84
|
+
# the suggested +label+
|
|
85
|
+
def select_and_submit(page, form_name, select_name, selection)
|
|
86
|
+
option = nil
|
|
87
|
+
form = page.form(form_name)
|
|
88
|
+
unless form.nil?
|
|
89
|
+
selector = form.field(select_name)
|
|
90
|
+
unless selector.nil?
|
|
91
|
+
option = select_option(selector, selection)
|
|
92
|
+
form.submit
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
return option
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
##
|
|
99
|
+
# Given a Mechanize::Form:SelectList +selector+ will attempt to select the option
|
|
100
|
+
# specified by +selection+.
|
|
101
|
+
# This algorithm is used:
|
|
102
|
+
# The first option with a label equal to the +selection+ is selected.
|
|
103
|
+
# - if none is found then -
|
|
104
|
+
# The first option with a value equal to the +selection+ is selected.
|
|
105
|
+
# - if none is found then -
|
|
106
|
+
# The first option with a label or value that equal to the +selection+ is selected
|
|
107
|
+
# after removing non-alphanumeric characters from the label or value
|
|
108
|
+
# - if none is found then -
|
|
109
|
+
# The first option with a lable or value that _contains_ the +selection+
|
|
110
|
+
#
|
|
111
|
+
# If matching option is found, the #select is called on it.
|
|
112
|
+
# If no option is found, nil is returned - otherwise the option is returned
|
|
113
|
+
#
|
|
114
|
+
def select_option(selector, selection)
|
|
115
|
+
options = selector.options.select { |o| o.text == selection }
|
|
116
|
+
options = selector.options.select { |o| o.value == selection } if options.empty?
|
|
117
|
+
options = selector.options.select { |o| o.text.gsub(/[^a-zA-Z0-9]/,"") == selection } if options.empty?
|
|
118
|
+
options = selector.options.select { |o| o.value.gsub(/[^a-zA-Z0-9]/,"") == selection } if options.empty?
|
|
119
|
+
options = selector.options.select { |o| o.text.include?(selection) } if options.empty?
|
|
120
|
+
options = selector.options.select { |o| o.value.include?(selection) } if options.empty?
|
|
121
|
+
|
|
122
|
+
option = options.first
|
|
123
|
+
option.select() unless option.nil?
|
|
124
|
+
return option
|
|
125
|
+
end
|
|
82
126
|
|
|
127
|
+
##
|
|
128
|
+
# Uploads the given OFX document to the Wesabe account specified in the +wesabe_args+
|
|
129
|
+
#
|
|
83
130
|
def self.wesabe_upload(wesabe_args, ofx_doc, logger)
|
|
84
131
|
if (wesabe_args.nil? or (wesabe_args.length < 2 and wesabe_args.length > 3))
|
|
85
132
|
raise "Incorrect number of args for Wesabe (#{wesabe_args}), should be 2 or 3."
|
|
@@ -113,6 +160,13 @@ module Bankjob
|
|
|
113
160
|
end
|
|
114
161
|
end
|
|
115
162
|
|
|
163
|
+
##
|
|
164
|
+
# Helps the user determine how to upload to their Wesabe account.
|
|
165
|
+
#
|
|
166
|
+
# When used with no args, will give generic help information.
|
|
167
|
+
# When used with Wesabe account and password, will log into Wesabe and list
|
|
168
|
+
# the users accounts, and suggest command line args to upload to each account.
|
|
169
|
+
#
|
|
116
170
|
def self.wesabe_help(wesabe_args)
|
|
117
171
|
if (wesabe_args.nil? or wesabe_args.length != 2)
|
|
118
172
|
puts <<-EOF
|
data/scrapers/bpi_scraper.rb
CHANGED
|
@@ -15,7 +15,10 @@ include Bankjob # access the namespace of Bankjob
|
|
|
15
15
|
# as an example of how to build your own scraper.
|
|
16
16
|
#
|
|
17
17
|
# BpiScraper expects the user name and password to be passed on the command line
|
|
18
|
-
# using -
|
|
18
|
+
# using --scraper-args "user password" (with a space between them).
|
|
19
|
+
# Optionally, the account number can also be specified with the 3rd argument so:
|
|
20
|
+
# --scraper-args "user password 803030000001" causing that account to be selected
|
|
21
|
+
# before scraping the statement
|
|
19
22
|
#
|
|
20
23
|
class BpiScraper < BaseScraper
|
|
21
24
|
|
|
@@ -75,6 +78,18 @@ class BpiScraper < BaseScraper
|
|
|
75
78
|
if (transactions_page.nil?)
|
|
76
79
|
raise "BPI Scraper failed to load the transactions page at #{TRANSACTIONS_URL}"
|
|
77
80
|
end
|
|
81
|
+
|
|
82
|
+
# If there is a third scraper arg, it is the account number and we use it
|
|
83
|
+
# to select the account on the transactions page
|
|
84
|
+
if (scraper_args and scraper_args.length > 2)
|
|
85
|
+
account = scraper_args[2]
|
|
86
|
+
# the account selector is the field 'contaCorrente' in the form 'form_mov'
|
|
87
|
+
Bankjob.select_and_submit(transactions_page, 'form_mov', 'contaCorrente', account)
|
|
88
|
+
sleep 1
|
|
89
|
+
# refetch the transactions page after selecting the account
|
|
90
|
+
transactions_page = agent.get(TRANSACTIONS_URL)
|
|
91
|
+
end
|
|
92
|
+
|
|
78
93
|
return transactions_page
|
|
79
94
|
end
|
|
80
95
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bankjob
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rhubarb
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-04-
|
|
12
|
+
date: 2009-04-20 00:00:00 +01:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|