aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-10-27 19:00:46 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-11-09 16:50:57 +0100
commitd464a20370520238aa75b3455d5ff035f150aa94 (patch)
tree3093edcac44f761d2fbc4295caa8b6a3146ab046
parentf7ba7dea0eff46cc9b7b3c3dfd8c5720a63dd7f4 (diff)
downloadgeldschieberbot-d464a20370520238aa75b3455d5ff035f150aa94.tar.gz
geldschieberbot-d464a20370520238aa75b3455d5ff035f150aa94.zip
fix tanken hopfully the last time
-rw-r--r--geldschieberbot.py19
-rw-r--r--tanken.py1
2 files changed, 13 insertions, 7 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index 8723ff5..58a6cb8 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -203,12 +203,17 @@ def handle_input(inp):
if len(w) < 3:
send('ERROR: !tanken not in form "!tanken amount person [info]"')
continue
- amount = w[1]
+ try:
+ amount = float(w[1])
+ except:
+ send("ERROR: amount musst be a number")
+ continue
if w[2] in name2num:
recipient = w[2]
else:
recipient = num2name[sender_number]
- parts, err = tanken(body[1:], amount)
+
+ parts, err = tanken.tanken(body[1:], amount)
if err != None:
send("ERROR: " + err)
@@ -216,11 +221,11 @@ def handle_input(inp):
msg = ""
for p in parts.items():
- msg += p[0] + ": " + str(p[1])
- if p != recipient:
- if p in name2num:
- balance[recipient][p[0]] -= p[1]
- balance[p[0]][recipient] += p[1]
+ msg += p[0] + ": {}km = {:g}\n".format(p[1][0], p[1][1])
+ if p[0] != recipient:
+ if p[0] in name2num:
+ balance[recipient][p[0]] -= p[1][1]
+ balance[p[0]][recipient] += p[1][1]
else:
msg += p[0] + " not known. Please take care manually\n"
diff --git a/tanken.py b/tanken.py
index 4685fee..501978b 100644
--- a/tanken.py
+++ b/tanken.py
@@ -3,6 +3,7 @@
def tanken(drives, cost):
passagers = {}
distance = 0.
+ drives = [d.split(' ') for d in drives]
for d in drives:
try: