yuripeyamashita commited on
Commit
a33cbc3
·
verified ·
1 Parent(s): ebe584c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -16
app.py CHANGED
@@ -45,7 +45,7 @@ def api():
45
  users.append("others")
46
  print(users)
47
 
48
- matrix = [[0 for _ in range(len(users))] for _ in range(len(users))]
49
 
50
  should_checkout = True
51
 
@@ -85,9 +85,6 @@ def api():
85
  if i < j:
86
  matrix_copy[i][j] = matrix[i][j] - matrix[j][i]
87
 
88
- for r in matrix_copy:
89
- print(r)
90
-
91
  result = []
92
 
93
  for i in range(len(matrix_copy)):
@@ -100,12 +97,9 @@ def api():
100
 
101
  if result:
102
  sorted_result = sorted(result, key=lambda x: x["from"])
103
-
104
- for r in sorted_result:
105
- print(r)
106
-
107
  bubble = get_checkout_bubble(sorted_result)
108
  send_flex_text(payload.get("token"), bubble)
 
109
 
110
  raise ValueError("Action Success")
111
 
@@ -223,17 +217,21 @@ def get_amount(text: str) -> float | None:
223
  try:
224
  after_dollar = text.split("$")[1]
225
  rows = after_dollar.split("\n")
226
- number_string = rows[0]
227
  divisor = 1
228
  if len(rows) > 1 and "/" in rows[1]:
229
  divisor = int(rows[1].replace("/", ""))
230
- return round(float(simple_eval(number_string))/divisor, 2)
 
 
 
 
231
  except:
232
  return None
233
 
234
 
235
  def get_summary_bubble(title: str, payer: str, borrowers: list):
236
- total = 0
237
  borrower_contents = []
238
 
239
  for borrower in borrowers:
@@ -278,6 +276,7 @@ def get_summary_bubble(title: str, payer: str, borrowers: list):
278
  "text": title,
279
  "weight": "bold",
280
  "size": "xxl",
 
281
  "margin": "md"
282
  },
283
  {
@@ -335,11 +334,106 @@ def get_summary_bubble(title: str, payer: str, borrowers: list):
335
 
336
 
337
  def get_checkout_bubble(checkout_list: list):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
 
339
  current_user = checkout_list[0].get("from")
340
- current_total = 0
341
  current_pay_to_contents = []
342
- carousel_contents = []
343
 
344
  checkout_list.append({"from": None, "to": None, "amount": 0})
345
 
@@ -364,6 +458,7 @@ def get_checkout_bubble(checkout_list: list):
364
  "text": current_user,
365
  "weight": "bold",
366
  "size": "xxl",
 
367
  "margin": "md"
368
  },
369
  {
@@ -416,10 +511,10 @@ def get_checkout_bubble(checkout_list: list):
416
  )
417
 
418
  current_user = item.get("from")
419
- current_total = 0
420
  current_pay_to_contents = []
421
 
422
- amount = float(item.get("amount"))
423
  current_total += amount
424
 
425
  current_pay_to_contents.append({
@@ -435,7 +530,7 @@ def get_checkout_bubble(checkout_list: list):
435
  },
436
  {
437
  "type": "text",
438
- "text": f"${round(amount,2)}",
439
  "size": "sm",
440
  "color": "#111111",
441
  "align": "end"
 
45
  users.append("others")
46
  print(users)
47
 
48
+ matrix = [[0.0 for _ in range(len(users))] for _ in range(len(users))]
49
 
50
  should_checkout = True
51
 
 
85
  if i < j:
86
  matrix_copy[i][j] = matrix[i][j] - matrix[j][i]
87
 
 
 
 
88
  result = []
89
 
90
  for i in range(len(matrix_copy)):
 
97
 
98
  if result:
99
  sorted_result = sorted(result, key=lambda x: x["from"])
 
 
 
 
100
  bubble = get_checkout_bubble(sorted_result)
101
  send_flex_text(payload.get("token"), bubble)
102
+ message_list = {}
103
 
104
  raise ValueError("Action Success")
105
 
 
217
  try:
218
  after_dollar = text.split("$")[1]
219
  rows = after_dollar.split("\n")
220
+ number = float(simple_eval(rows[0]))
221
  divisor = 1
222
  if len(rows) > 1 and "/" in rows[1]:
223
  divisor = int(rows[1].replace("/", ""))
224
+ if divisor % 3 == 0:
225
+ number += 1
226
+ if divisor == 0:
227
+ raise ValueError("divisor = 0")
228
+ return round(number/divisor, 2)
229
  except:
230
  return None
231
 
232
 
233
  def get_summary_bubble(title: str, payer: str, borrowers: list):
234
+ total = 0.0
235
  borrower_contents = []
236
 
237
  for borrower in borrowers:
 
276
  "text": title,
277
  "weight": "bold",
278
  "size": "xxl",
279
+ "wrap": True,
280
  "margin": "md"
281
  },
282
  {
 
334
 
335
 
336
  def get_checkout_bubble(checkout_list: list):
337
+ carousel_contents = []
338
+
339
+ checkout_total = 0.0
340
+ checkout_contents = []
341
+ checkout_items = {key: value for key, value in message_list.items() if not value.get("quoted_msg_id")}
342
+ for _, value in checkout_items.items:
343
+ msg_text = value.get("msg_text")
344
+ amount = round(float(value.get("amount")), 2)
345
+ checkout_total += amount
346
+
347
+ if msg_text:
348
+ msg_text = msg_text.split("$")[0]
349
+
350
+ checkout_contents.append({
351
+ "type": "box",
352
+ "layout": "vertical",
353
+ "contents": [
354
+ {
355
+ "type": "text",
356
+ "text": msg_text,
357
+ "size": "sm",
358
+ "color": "#555555",
359
+ "flex": 0
360
+ },
361
+ {
362
+ "type": "text",
363
+ "text": f"${amount}",
364
+ "size": "sm",
365
+ "color": "#111111",
366
+ "align": "end"
367
+ }
368
+ ],
369
+ "margin": "sm"
370
+ })
371
+
372
+ carousel_contents.append({
373
+ "type": "bubble",
374
+ "body": {
375
+ "type": "box",
376
+ "layout": "vertical",
377
+ "contents": [
378
+ {
379
+ "type": "text",
380
+ "text": "結算明細",
381
+ "weight": "bold",
382
+ "color": "#1DB446",
383
+ "size": "sm"
384
+ },
385
+ {
386
+ "type": "text",
387
+ "text": "此次結算包含:",
388
+ "size": "sm",
389
+ "color": "#aaaaaa",
390
+ "wrap": True,
391
+ "margin": "lg"
392
+ },
393
+ {
394
+ "type": "box",
395
+ "layout": "vertical",
396
+ "margin": "md",
397
+ "spacing": "sm",
398
+ "contents": checkout_contents},
399
+ {
400
+ "type": "separator",
401
+ "margin": "lg"
402
+ },
403
+ {
404
+ "type": "box",
405
+ "layout": "horizontal",
406
+ "contents": [
407
+ {
408
+ "type": "text",
409
+ "text": "合計",
410
+ "size": "sm",
411
+ "color": "#555555"
412
+ },
413
+ {
414
+ "type": "text",
415
+ "text": f"${round(checkout_total,2)}",
416
+ "size": "sm",
417
+ "color": "#111111",
418
+ "align": "end",
419
+ "weight": "bold"
420
+ }
421
+ ],
422
+ "margin": "lg"
423
+ }
424
+ ]
425
+ },
426
+ "styles": {
427
+ "footer": {
428
+ "separator": True
429
+ }
430
+ }
431
+ }
432
+ )
433
 
434
  current_user = checkout_list[0].get("from")
435
+ current_total = 0.0
436
  current_pay_to_contents = []
 
437
 
438
  checkout_list.append({"from": None, "to": None, "amount": 0})
439
 
 
458
  "text": current_user,
459
  "weight": "bold",
460
  "size": "xxl",
461
+ "wrap": True,
462
  "margin": "md"
463
  },
464
  {
 
511
  )
512
 
513
  current_user = item.get("from")
514
+ current_total = 0.0
515
  current_pay_to_contents = []
516
 
517
+ amount = round(float(item.get("amount")), 2)
518
  current_total += amount
519
 
520
  current_pay_to_contents.append({
 
530
  },
531
  {
532
  "type": "text",
533
+ "text": f"${amount}",
534
  "size": "sm",
535
  "color": "#111111",
536
  "align": "end"