yuripeyamashita commited on
Commit
553c037
1 Parent(s): 5b2b88d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -80,12 +80,16 @@ def api():
80
  "quoted_msg_id": payload.get("quoted_msg_id")}
81
  else:
82
  message_list[payload.get("msg_id")] = {"user_id": payload.get("user_id"),
83
- "amount": get_amount(payload.get("msg_text"))}
 
84
 
85
  for msg_id, data in message_list.items():
86
  quoted_msg_id = data.get("quoted_msg_id")
87
  quoted_msg_list = {key: value for key, value in message_list.items() if value.get("quoted_msg_id") == msg_id}
88
 
 
 
 
89
  if not quoted_msg_id and len(quoted_msg_list) != 0:
90
  amount: float = data.get("amount")
91
  paid: float = 0.0
@@ -93,7 +97,7 @@ def api():
93
  paid += value.get("amount")
94
  print(amount, paid)
95
  if (amount-paid > 1):
96
- send_text(payload.get("token"), "未付清", data.get("quote_token"))
97
  break
98
 
99
  # if quoted_msg_id:
@@ -161,16 +165,16 @@ def get_users_number() -> int:
161
 
162
 
163
  def get_amount(text: str) -> float | None:
164
- # try:
165
- after_dollar = text.split("$")[1]
166
- rows = after_dollar.split("\n")
167
- number_string = rows[0]
168
- divisor = 1
169
- if len(rows) > 1 and "/" in rows[1]:
170
- divisor = int(rows[1].replace("/", ""))
171
- return round(float(simple_eval(number_string))/divisor, 2)
172
- # except:
173
- # return None
174
 
175
 
176
  if __name__ == "__main__":
 
80
  "quoted_msg_id": payload.get("quoted_msg_id")}
81
  else:
82
  message_list[payload.get("msg_id")] = {"user_id": payload.get("user_id"),
83
+ "amount": get_amount(payload.get("msg_text")),
84
+ "quote_token": get_amount(payload.get("quote_token"))}
85
 
86
  for msg_id, data in message_list.items():
87
  quoted_msg_id = data.get("quoted_msg_id")
88
  quoted_msg_list = {key: value for key, value in message_list.items() if value.get("quoted_msg_id") == msg_id}
89
 
90
+ if msg_id == payload.get("quoted_msg_id") or quoted_msg_id == payload.get("quoted_msg_id"):
91
+ break
92
+
93
  if not quoted_msg_id and len(quoted_msg_list) != 0:
94
  amount: float = data.get("amount")
95
  paid: float = 0.0
 
97
  paid += value.get("amount")
98
  print(amount, paid)
99
  if (amount-paid > 1):
100
+ send_text(payload.get("token"), f"$ {amount-paid} 未付清", data.get("quote_token"))
101
  break
102
 
103
  # if quoted_msg_id:
 
165
 
166
 
167
  def get_amount(text: str) -> float | None:
168
+ try:
169
+ after_dollar = text.split("$")[1]
170
+ rows = after_dollar.split("\n")
171
+ number_string = rows[0]
172
+ divisor = 1
173
+ if len(rows) > 1 and "/" in rows[1]:
174
+ divisor = int(rows[1].replace("/", ""))
175
+ return round(float(simple_eval(number_string))/divisor, 2)
176
+ except:
177
+ return None
178
 
179
 
180
  if __name__ == "__main__":