From 3e9464d858342f41a1c90fe51bb9773f5e2917eb Mon Sep 17 00:00:00 2001 From: Martin Puppe Date: Sun, 17 Dec 2017 14:04:51 +0100 Subject: [PATCH] Fix error with newly created Uberspace accounts Newly created Uberspace accounts do not display an account balance on the accounting page. The script has to handle that case. --- Uberspace.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Uberspace.lua b/Uberspace.lua index 099c48d..f1bae9a 100644 --- a/Uberspace.lua +++ b/Uberspace.lua @@ -52,6 +52,11 @@ 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 @@ -90,8 +95,11 @@ function RefreshAccount (account, since) }) end - balanceElement = html:xpath('//*[@id="total"]') - balance = ParseAmount(balanceElement:text()) + local balanceElement = html:xpath('//*[@id="total"]') + local balance = ParseAmount(balanceElement:text()) + if not balance then + balance = 0 + end return {balance=balance, transactions=transactions} end