bankscrap 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7567c87bd47ae9505b4abaa485cae8442dd41b40
4
- data.tar.gz: 9e5a1bdc25a930b5e8340bd65be5f1302d0a7da0
3
+ metadata.gz: e2142881eec4c8dcc412763eb07d3c84cc33d1fe
4
+ data.tar.gz: a23a8c1e02e54605ca8789a601f7774eb5712bca
5
5
  SHA512:
6
- metadata.gz: 63da5ae6218c554d0ce6d745cdf252f18ecd2bfa137bd8a06d24018d108802ba02907d97ae9e986ea89de9274e683a5f15b54fdf9696e4258307746db87edfab
7
- data.tar.gz: 542a627dfcc461df1ad682ffed3af835345e8b85b8c521dede4ce03690fba24f204c97f671057f023b1897a2ad5a0b5b1004c828c07853c5c377b1dfe48ad91a
6
+ metadata.gz: 5c5a268c46975640c1d851fc860d863f6bbcba8450d0992ec6f23a4f62b6973fe8734ac05169593bfa5ef9d7d15bd3787dc4feb5d7ec8f534453052a54ce5684
7
+ data.tar.gz: e8dbc234ed3712d90e6b0bbecbb4fe40373de20b17416a5ba040424e1791a421413f4139d46ae6ccc8cde9e989b0ea9cc2b0d643b37ff1f2b56055ed65ef312c
data/README.md CHANGED
@@ -77,29 +77,37 @@ Replace 01/01/1980 with your actual birthday.
77
77
 
78
78
  #### Transactions with date range
79
79
 
80
- $ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --extra=from:01-01-2015 to:01-02-2015
80
+ $ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --from 01-01-2015 --to 01-02-2015
81
81
 
82
82
  ---
83
83
 
84
84
  By default it will use your first bank account, if you want to fetch transactions for a different account you can use this syntax:
85
85
 
86
- $ bankscrap transactions YourBank your_iban --user YOUR_DNI --password YOUR_PASSWORD
86
+ $ bankscrap transactions YourBank --iban "your_iban" --user YOUR_DNI --password YOUR_PASSWORD
87
87
 
88
88
  If you don't want to pass your user and password everytime you can define them in your .bash_profile by adding:
89
89
 
90
90
  export BANK_SCRAP_USER=YOUR_BANK_USER
91
91
  export BANK_SCRAP_PASSWORD=YOUR_BANK_PASSWORD
92
92
 
93
+ #### Export transactions to CSV
94
+
95
+ $ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --format CSV [--output ./my_transactions.csv]
96
+
97
+ Currently only CSV is supported. The output parameter is optional, by default `transactions.csv` is used.
98
+
93
99
  ### From Ruby code
94
100
 
95
101
  You can also use this gem from your own app as library. To do so first you must initialize a BankScrap::Bank object
96
102
 
97
103
 
98
104
  ```ruby
99
- require 'bankscrap-bbva'
100
105
  # BBVA
106
+ require 'bankscrap-bbva'
101
107
  bbva = Bankscrap::BBVA::Bank.new(YOUR_BBVA_USER, YOUR_BBVA_PASSWORD)
108
+
102
109
  # ING
110
+ require 'bankscrap-ing'
103
111
  ing = Bankscrap::ING::Bank.new(YOUR_DNI, YOUR_ING_PASSWORD, extra_args: {"birthday" => "dd/mm/yyyy"})
104
112
  ```
105
113
 
data/lib/bankscrap/cli.rb CHANGED
@@ -8,6 +8,10 @@ module Bankscrap
8
8
  option :password, default: ENV['BANKSCRAP_PASSWORD']
9
9
  option :log, default: false
10
10
  option :debug, default: false
11
+ option :iban, default: nil
12
+
13
+ option :format
14
+ option :output
11
15
 
12
16
  # Some bank needs more input, like birthday, this would go here
13
17
  # Usage:
@@ -29,21 +33,18 @@ module Bankscrap
29
33
 
30
34
  desc 'transactions BANK', "get account's transactions"
31
35
  shared_options
32
- def transactions(bank, iban = nil)
36
+ options from: :string, to: :string
37
+ def transactions(bank)
33
38
  assign_shared_options
34
39
 
35
- begin
36
- start_date = @extra_args.key?('from') ? Date.strptime(@extra_args['from'], '%d-%m-%Y') : nil
37
- end_date = @extra_args.key?('to') ? Date.strptime(@extra_args['to'], '%d-%m-%Y') : nil
38
- rescue ArgumentError
39
- say 'Invalid date format. Correct format d-m-Y', :red
40
- end
40
+ start_date = parse_date(options[:from]) if options[:from]
41
+ end_date = parse_date(options[:to]) if options[:to]
41
42
 
42
43
  initialize_client_for(bank)
43
44
 
44
- account = iban ? @client.account_with_iban(iban) : @client.accounts.first
45
+ account = @iban ? @client.account_with_iban(@iban) : @client.accounts.first
45
46
 
46
- if !start_date.nil? && !end_date.nil?
47
+ if start_date && end_date
47
48
  if start_date > end_date
48
49
  say 'From date must be lower than to date', :red
49
50
  exit
@@ -54,8 +55,9 @@ module Bankscrap
54
55
  transactions = account.transactions
55
56
  end
56
57
 
57
- say "Transactions for: #{account.description} (#{account.iban})", :cyan
58
+ export_to_file(transactions, options[:format], options[:output]) if options[:format]
58
59
 
60
+ say "Transactions for: #{account.description} (#{account.iban})", :cyan
59
61
  transactions.each do |transaction|
60
62
  say transaction.to_s, (transaction.amount > Money.new(0) ? :green : :red)
61
63
  end
@@ -66,6 +68,7 @@ module Bankscrap
66
68
  def assign_shared_options
67
69
  @user = options[:user]
68
70
  @password = options[:password]
71
+ @iban = options[:iban]
69
72
  @log = options[:log]
70
73
  @debug = options[:debug]
71
74
  @extra_args = options[:extra]
@@ -84,5 +87,25 @@ module Bankscrap
84
87
  rescue NameError
85
88
  raise ArgumentError.new("Invalid bank name. Did you mean \"#{bank_name.upcase}\"?")
86
89
  end
90
+
91
+ def parse_date(string)
92
+ Date.strptime(string, '%d-%m-%Y')
93
+ rescue ArgumentError
94
+ say 'Invalid date format. Correct format d-m-Y (eg: 31-12-2016)', :red
95
+ exit
96
+ end
97
+
98
+ def export_to_file(data, format, path)
99
+ exporter(format, path).write_to_file(data)
100
+ end
101
+
102
+ def exporter(format, path)
103
+ case format.downcase
104
+ when 'csv' then BankScrap::Exporter::Csv.new(path)
105
+ else
106
+ say 'Sorry, file format not supported.', :red
107
+ exit
108
+ end
109
+ end
87
110
  end
88
111
  end
@@ -0,0 +1,20 @@
1
+ require 'csv'
2
+
3
+ module BankScrap
4
+ module Exporter
5
+ class Csv
6
+ HEADERS = %w(Date Description Amount).freeze
7
+
8
+ def initialize(output = nil)
9
+ @output = output || 'transactions.csv'
10
+ end
11
+
12
+ def write_to_file(data)
13
+ CSV.open(@output, 'wb') do |csv|
14
+ csv << HEADERS
15
+ data.each { |line| csv << line.to_a }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -14,6 +14,10 @@ module Bankscrap
14
14
  "#{effective_date.strftime('%d/%m/%Y')} #{description.ljust(45)} #{amount.format.rjust(20)}"
15
15
  end
16
16
 
17
+ def to_a
18
+ [effective_date.strftime('%d/%m/%Y'), description, amount]
19
+ end
20
+
17
21
  private
18
22
 
19
23
  def inspect_attributes
@@ -1,3 +1,3 @@
1
1
  module Bankscrap
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
data/lib/bankscrap.rb CHANGED
@@ -9,3 +9,4 @@ require_relative 'bankscrap/bank'
9
9
  require_relative 'bankscrap/account'
10
10
  require_relative 'bankscrap/investment'
11
11
  require_relative 'bankscrap/transaction'
12
+ require_relative 'bankscrap/exporters/csv'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankscrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Cuevas
@@ -146,6 +146,7 @@ files:
146
146
  - lib/bankscrap/bank.rb
147
147
  - lib/bankscrap/cli.rb
148
148
  - lib/bankscrap/config.rb
149
+ - lib/bankscrap/exporters/csv.rb
149
150
  - lib/bankscrap/investment.rb
150
151
  - lib/bankscrap/locale/en.yml
151
152
  - lib/bankscrap/transaction.rb