aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2017-08-12 12:51:08 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2017-08-12 12:51:08 +0200
commit576d21cb573715cd97b6d24123efebda584f3a20 (patch)
treec6735ae6ccd7e6d0ed05534add8ab528970ab2f5
parent69b131cc77012ad924096bef7a9c1542903e94cf (diff)
downloadgeldschieberbot-576d21cb573715cd97b6d24123efebda584f3a20.tar.gz
geldschieberbot-576d21cb573715cd97b6d24123efebda584f3a20.zip
improve summary add single user summary
-rw-r--r--geldschieberbot.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/geldschieberbot.py b/geldschieberbot.py
index a1209dd..0b6a1c6 100644
--- a/geldschieberbot.py
+++ b/geldschieberbot.py
@@ -21,19 +21,27 @@ send_cmd = "signal-cli -u irgendwer send -g irgendwem"
def send(msg):
subprocess.run(send_cmd.split(' '), input=msg.encode())
-def create_summary():
- summary = "Summary:\n"
+def create_summary(user):
+ summary = ""
+ p_balances = balance[user] # failes if user is not in balance
+ for person in p_balances:
+ amount = p_balances[person]
+ if amount == 0:
+ continue
+ summary += "\t" + ("<-" if amount < 0 else "->")
+ summary += " " + person2 + " " + str(abs(amount)) + "\n"
+ if summary == "":
+ summary = "\tAll fine :)\n"
+ summary = user + ":\n" + summary
+ return summary
+
+def create_total_summary():
+ summary = "Summary:"
for person in balance:
- summary += person + ":\n"
-
- p_balance = balance[person]
- for person2 in p_balance:
- amount = p_balance[person2]
- summary += "\t" + ("<-" if amount < 0 else "->")
- summary += " " + person2 + " " + str(abs(amount)) + "\n"
- summary += "\n"
-
+ summary += '\n'
+ summary += "* " + create_summary(person)
+
return summary
def create_members():
@@ -119,10 +127,15 @@ def handle_input(inp):
balance[w[1]] = nm
elif w[0] == "!sum":
- if len(w) > 2:
- send('ERROR: not in form "!sum [name]"')
+ if len(w) == 1:
+ send(create_total_summary())
+ elif len(w) == 2:
+ if w[1] in name2num:
+ send("Summary:\n" + create_summary(w[1]))
+ else:
+ send("ERROR: name not registered")
else:
- send(create_summary())
+ send('ERROR: not in form "!sum [name]"')
elif w[0] == "!schieb" or w[0] == "!zieh":
if len(w) != 3: