@@ -1,19 +1,33 @@ import bunco import xlsxwriter +import creds # local from blessings import Terminal +from twilio.rest import Client t = Terminal() g = bunco.Game("players.csv") +enable_sms = False +last_status = 'Off to a great start!' + def plural(str,n,suffix="s"): return str + suffix if n > 1 else str def print_center(before, string, after): col = int((t.width - len(string)) / 2) - 1 print(f"{t.move_x(col)}{before}{string}{after}") +def status(text): + global last_status + row = 6 + (len(g.tables) * 5) + print(t.move(row, 0), end='') + print(t.clear_eol, end='') + print_center(f"{t.bold_green}",f"[ {text} ]", t.normal) + print(t.clear_eos) + last_status = text + def display_dashboard(): print(t.clear,t.move(0,0)) print_center(t.bold_red,"B U N C O S I M U L A T O R", t.normal) print(f"{t.red}{'-'*t.width}{t.normal}\n") @@ -31,22 +45,32 @@ print(f"{t.move_x(3)}{t.cyan}{player}{t.normal}",end='') for n in range(g.current_round()): print(t.move_x(18+(4*n)),end='') print(str(player.round_scores[n]).rjust(4),end='') print('') - -g.play_one_round() -display_dashboard() + status(last_status) def do1(): - g.prep_next_round() g.play_one_round() + if enable_sms: + status("Sending results by SMS to players…") + for player in g.players: + sms(player.smsnumber, summary_text(player)) + display_dashboard() + status("Prepping for next round…") + g.prep_next_round() + status("Ready for another round!") def summary(n): return summary_text(g.players[n]) +def sms(number, message): + if enable_sms and number: + cli = Client(creds.SID, creds.token) + cli.messages.create(to=number, from_=creds.sender, body=message) + def summary_text(player): for table in g.tables: if player in table.players: curtable = table break @@ -69,10 +93,17 @@ f"You made {player.round_roll_counts[g.current_round()-1]} rolls,", f"adding {player.personal_roll_scores[g.current_round()-1]} pts{buncos}", f"to your team score of {player.round_scores[g.current_round()-1]},", f"{winloss} {foe_names}’s score of {sitch['opponent_score']}."] return " ".join(ts) + +def sms_table_move(player, wonlost, table_from, table_to): + if player.smsnumber: + message = f"Having {wonlost} the last round, you move from {table_from} to {table_to}." + sms(player.smsnumber, message) + +bunco.table_move_callback = sms_table_move def excel_sheet(title): wb = xlsxwriter.Workbook('bunco.xlsx') ws = wb.add_worksheet('Overview') style = {}