aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-11-03 17:40:42 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-11-09 16:51:03 +0100
commit1e70503c405029e610fad115ab233a2e27bfd0a7 (patch)
tree2608429cc16060979bb1ce036c439eb1c6fb3ec9
parent1652389543b5bb762327c344ae11ba94b936c898 (diff)
downloadgeldschieberbot-1e70503c405029e610fad115ab233a2e27bfd0a7.tar.gz
geldschieberbot-1e70503c405029e610fad115ab233a2e27bfd0a7.zip
don't use floats
THIS BREAKS THE OLD BALANCES!!!
-rw-r--r--geldschieberbot.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index ee73877..33115e9 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -17,6 +17,23 @@ group_id = "GELD!!!"
send_cmd = "signal-cli -u irgendwer send -g irgendwem"
+def to_cent(euro):
+ euro = euro.split('.')
+ if len(euro) > 2:
+ raise TypeError
+ euro[0] = int(euro[0])
+ if len(euro) < 2:
+ euro.append(0)
+ else:
+ if len(euro[1]) == 1:
+ euro[1] = int(euro[1]) * 10
+ else:
+ euro[1] = int(euro[1])
+ return euro[0] * 100 + euro[1]
+
+def to_euro(cents):
+ return str(cents/100)
+
def send(msg):
subprocess.run(send_cmd.split(' '), input=msg.encode())
@@ -29,11 +46,11 @@ def create_summary(user):
if amount == 0:
continue
total -= amount
- summary += "\t{} {} {:.2}\n".format("<-" if amount < 0 else "->", person, abs(amount))
+ summary += "\t{} {} {}\n".format("<-" if amount < 0 else "->", person, abs(to_euro(amount)))
if summary == "":
summary = "\tAll fine :)\n"
else:
- summary += "\tBalance: {:.2}".format(total)
+ summary += "\tBalance: {}".format(to_euro(total))
summary = user + ":\n" + summary
return summary
@@ -177,7 +194,7 @@ def handle_input(inp):
sender = num2name[sender_number]
try:
- amount = float(amount)
+ amount = to_cents(amount)
except:
send("ERROR: amount musst be a number")
continue
@@ -196,7 +213,7 @@ def handle_input(inp):
send("New Balance: {0} {1} {2:.2} {3}\n".format(sender,
("->" if p_balance > 0 else "<-"),
- abs(p_balance),
+ abs(to_euro(p_balance)),
recipient))
elif cmd == "!tanken":
@@ -204,7 +221,7 @@ def handle_input(inp):
send('ERROR: !tanken not in form "!tanken amount person [info]"')
continue
try:
- amount = float(w[1])
+ amount = to_cents(w[1])
except:
send("ERROR: amount musst be a number")
continue