This repository has been archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Uberspace.lua
108 lines (91 loc) · 3.11 KB
/
Uberspace.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
--[[
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
--]]
WebBanking{version = 1.02,
url = 'https://dashboard.uberspace.de/login',
services = {'Uberspace.de'},
description = string.format(
MM.localizeText("Get balance and transactions for %s"),
"Uberspace.de")
}
function SupportsBank (protocol, bankCode)
return bankCode == 'Uberspace.de' and protocol == ProtocolWebBanking
end
local usConnection = Connection()
local usUsername
function InitializeSession (protocol, bankCode, username, username2,
password, username3)
-- Login.
usUsername = username
html = HTML(usConnection:get('https://dashboard.uberspace.de/login'))
html:xpath('//input[@name="login"]'):attr('value', username)
html:xpath('//input[@name="password"]'):attr('value', password)
html = HTML(
usConnection:request(html:xpath('//input[@name="submit"]'):click()))
if html:xpath('//input[@name="login"]'):length() > 0 then
-- We are still at the login screen.
return "Failed to log in. Please check your user credentials."
end
end
function ListAccounts (knownAccounts)
-- Return array of accounts.
local account = {
name = 'Uberspace ' .. usUsername,
accountNumber = '1',
portfolio = false,
currency = 'EUR',
type = AccountTypeSavings
}
return {account}
end
function RefreshAccount (account, since)
function ParseAmount (amountString)
local pattern = '(%-?%d+),(%d%d)'
local euro, cent = amountString:match(pattern)
if not euro or not cent then
return nil
end
euro = tonumber(euro)
cent = tonumber(cent) / 100
if euro < 0 then
return euro - cent
else
return euro + cent
end
end
html = HTML(usConnection:get(
'https://dashboard.uberspace.de/dashboard/accounting'))
tableRows = html:xpath(
'//*[@id="transactions"]//tr[count(td)=3][position()<last()]')
print('Found ' .. tableRows:length() .. ' rows')
local transactions = {}
for i = 1, tableRows:length() do
local row = tableRows:get(i)
local children = row:children()
local pattern = '(%d%d)%.(%d%d)%.(%d%d%d%d)'
local day, month, year = children:get(1):text():match(pattern)
local bookingDate = os.time{day=day, month=month, year=year}
if bookingDate < since then
print('Stopping parsing because transaction is too old.')
print('Date of transaction: ' .. os.date('%c', bookingDate))
print('since: ' .. os.date('%c', since))
break
end
local amount = ParseAmount(children:get(3):text())
table.insert(transactions, {
bookingDate = bookingDate,
amount = amount
})
end
local balanceElement = html:xpath('//*[@id="total"]')
local balance = ParseAmount(balanceElement:text())
if not balance then
balance = 0
end
return {balance=balance, transactions=transactions}
end
function EndSession ()
usConnection:get('https://dashboard.uberspace.de/logout')
end