Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Use official ynab api
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Schurig committed Feb 21, 2018
1 parent c346abb commit 5e722e8
Show file tree
Hide file tree
Showing 21 changed files with 379 additions and 371 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require spec_helper
--color
14 changes: 10 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source 'https://rubygems.org'

gem 'httparty'

# Dumper: BBVA
gem 'bankscrap'
gem 'bankscrap-bbva', '~> 2.0.2'
Expand All @@ -8,11 +10,15 @@ gem 'bankscrap-bbva', '~> 2.0.2'
gem 'twentysix'

# # Dumper: FinTS
# gem 'ruby_fints', git: 'https://github.com/schurig/ruby_fints.git', branch: 'ing-diba'
gem 'ruby_fints', git: 'https://github.com/schurig/ruby_fints.git', branch: 'ing-diba'
# # original https://github.com/playtestcloud/ruby_fints.git

gem 'base32'

gem 'selenium-webdriver'
gem 'nokogiri', '~> 1.8.1'
# included in selenium but because of a security risk it's set to 1.8.1
group :development do
gem 'pry'
end

group :test do
gem 'rspec'
end
44 changes: 35 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: https://github.com/schurig/ruby_fints.git
revision: bd22a6a6ba5bcd63c0a627f655f2ed4d7669dfa1
branch: ing-diba
specs:
ruby_fints (0.0.1)
cmxl (~> 0.2)
httparty (~> 0.10)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -15,13 +24,14 @@ GEM
bankscrap-bbva (2.0.2)
bankscrap (~> 2.0.3)
base32 (0.3.2)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
cmxl (0.2.0)
rchardet19
coderay (1.1.2)
concurrent-ruby (1.0.5)
deep_merge (1.2.1)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.18)
http-cookie (1.0.3)
domain_name (~> 0.5)
httparty (0.15.6)
Expand All @@ -37,6 +47,7 @@ GEM
nokogiri (~> 1.6)
ntlm-http (~> 0.1, >= 0.1.1)
webrobots (>= 0.0.9, < 0.2)
method_source (0.9.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
Expand All @@ -50,10 +61,23 @@ GEM
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
ntlm-http (0.1.1)
rubyzip (1.2.1)
selenium-webdriver (3.8.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rchardet19 (1.3.7)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
thor (0.20.0)
thread_safe (0.3.6)
twentysix (0.1.1)
Expand All @@ -74,8 +98,10 @@ DEPENDENCIES
bankscrap
bankscrap-bbva (~> 2.0.2)
base32
nokogiri (~> 1.8.1)
selenium-webdriver
httparty
pry
rspec
ruby_fints!
twentysix

BUNDLED WITH
Expand Down
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a ruby script that **pulls your transactions from your banks** and impor

## Supported banks

* Most German and Austrian banks _(all banks that [figo.io](https://figo.io) or that implement the FinTS standard)_
* Most German and Austrian banks _(all banks that implement the FinTS standard)_
* BBVA Spain _(private accounts only)_
* N26

Expand All @@ -27,15 +27,13 @@ _If you're someone from the YNAB-Team: please add a public api-endpoint for an e
```yaml
---
ynab:
username: # email
password: # password
access_token: # ynab access token
budget_id: # budget_id
cash_account_name: # optional
cash_account_id: # optional
accounts:
- dumper: :n26
iban: # iban of your n26
ynab_id: # account id in YNAB
ynab_name: # account name in YNAB
username: # email
password: # password
```
Expand Down Expand Up @@ -84,18 +82,6 @@ The FinTS / HBCI standard is mainly implemented by German banks.

The field `payee` will be `N/A` because we currently don't get the payee name.

### Figo `:figo`

You need to get a [figo.io](https://figo.io) account first.

#### Options

* `force_download` _(default: false)_

> Since there is a high chance that you use the `:figo` dumper more than once, all transactions from figo will be downloaded once and be cached thoughout the run.
>
> _If you want to turn off this behavior add the option `force_download: true`._

# Technical details on how it works

On [app.youneedabudget.com](https://app.youneedabudget.com) you can upload a `.csv` file with your transactions. The structure looks like this:
Expand Down
17 changes: 2 additions & 15 deletions config.sample.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
---
ynab:
username: # YNAB username
password: # YNAB password
access_token: # Your YNAB access token
budget_id: # the first hash in the url when you open your budget
cash_account_name: 'Cash' # if set that it creates transactions
cash_account_id: # if set that it creates transactions
# to your cash account if withdrawal is detected
accounts:
- dumper: :fints
iban: # iban of your account
ynab_id: # last hash in the url when you click on the account in YNAB
ynab_name: # the exact name how you named that account in YNAB
username: # online banking username / alias
password: # online banking PIN (NOT! the pin of your bank card!)
fints_blz: # Your bank's code / Bankleitzahl
fints_endpoint: # can be found here: https://www.hbci-zka.de/institute/institut_auswahl.htm
# Use the PIN/TAN URL from the link above
- dumper: :figo
iban: # iban of your account
ynab_id: # last hash in the url when you click on the account in YNAB
ynab_name: # the exact name how you named that account in YNAB
username: # figo username
password: # figo password
force_download: # default: false
# // if you have multiple figo entries it
# only fetches all transactions once.
# To turn this off set this to true.
- dumper: :n26
iban: # n26 iban
ynab_id: # last hash in the url when you click on the account in YNAB
ynab_name: # the exact name how you named that account in YNAB
username: # n26 username
password: # n26 password
set_category: false # default: false, sets the N26 category name as category
19 changes: 1 addition & 18 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
version: "2"
services:
selenium-chrome:
image: selenium/standalone-chrome
shm_size: 2g
ports:
- "4444:4444"
volumes:
- /dev/shm:/dev/shm # something for shared memory so chrome has enough
- ./.cache:/home/seluser/Downloads # for figo
- ./export:/usr/app/export
ruby:
container_name: ruby
importer:
build:
context: .
volumes:
- ./config.yml:/usr/app/config.yml
- ./export:/usr/app/export
- ./.cache:/root/Downloads # for figo
- ./.cache:/usr/app/.cache # for figo
environment:
- WEBDRIVER_URL=http://selenium-chrome:4444/wd/hub
depends_on:
- selenium-chrome
command: "ruby /usr/app/run.rb"
20 changes: 1 addition & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
version: "2"
services:
selenium-chrome:
image: selenium/standalone-chrome
shm_size: 2g
ports:
- "4444:4444"
volumes:
- /dev/shm:/dev/shm # something for shared memory so chrome has enough
- ./.cache:/home/seluser/Downloads # for figo
- ./export:/usr/app/export
ruby:
container_name: ruby
importer:
image: schurig/ynab-bank-importer:latest
volumes:
- ./config.yml:/usr/app/config.yml
- ./export:/usr/app/export
- ./last_imported:/usr/app/last_imported
- ./.cache:/root/Downloads # for figo
- ./.cache:/usr/app/.cache # for figo
environment:
- WEBDRIVER_URL=http://selenium-chrome:4444/wd/hub
depends_on:
- selenium-chrome
command: "ruby /usr/app/run.rb"
17 changes: 1 addition & 16 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Account
attr_accessor :dumper, :iban, :ynab_id, :csv_file
attr_accessor :dumper, :iban, :ynab_id, :transactions

def initialize(params = {})
@dumper = Dumper.get_dumper(params.fetch('dumper'))
Expand All @@ -16,21 +16,6 @@ def fetch_transactions
@transactions = dumper.fetch_transactions
end

def export_transactions
raise 'You need to call `fetch_transactions` first' if @transactions.nil?
return if @transactions.empty?

FileUtils.mkdir_p YNAB::EXPORT_DIR
CSV.open(export_file, 'wb') do |csv|
csv << %w(Date Payee Category Memo Outflow Inflow)
@transactions.each { |transaction| csv << transaction.to_a }
end
end

def export_file
"#{YNAB::EXPORT_DIR}/#{@iban}.csv"
end

private

def normalize_iban(iban)
Expand Down
29 changes: 27 additions & 2 deletions lib/dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,37 @@ def self.get_dumper(name)
Dumper::Bbva
when :n26
Dumper::N26
when :figo
Dumper::Figo
when :fints
Dumper::Fints
else
raise "Dumper \"#{name}\" not supported."
end
end

def to_ynab_transaction(transaction)
TransactionCreator.call(
account_id: account_id,
date: date(transaction),
payee_name: payee_name(transaction),
payee_iban: payee_iban(transaction),
category_name: category_name(transaction),
category_id: category_id(transaction),
memo: memo(transaction),
amount: amount(transaction),
is_withdrawal: withdrawal?(transaction),
import_id: import_id(transaction)
)
end

def category_name(_transaction)
nil
end

def category_id(_transaction)
nil
end

def normalize_iban(iban)
iban.delete(' ')
end
end
1 change: 1 addition & 0 deletions lib/dumper/bbva.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Bbva < Dumper
require 'bankscrap-bbva'

def initialize(params = {})
@ynab_id = params.fetch('ynab_id')
@username = params.fetch('username')
@password = params.fetch('password')
@iban = params.fetch('iban')
Expand Down
Loading

0 comments on commit 5e722e8

Please sign in to comment.