kimi_balance_monitor.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. @author: luojunhui
  3. """
  4. import requests
  5. from applications import bot
  6. from applications.decoratorApi import retryOnTimeout
  7. BALANCE_LIMIT_THRESHOLD = 200
  8. @retryOnTimeout(retries=5, delay=5)
  9. def check_kimi_balance():
  10. """
  11. 校验kimi余额
  12. :return:
  13. """
  14. url = "https://api.moonshot.cn/v1/users/me/balance"
  15. payload = {}
  16. headers = {
  17. 'Authorization': 'Bearer sk-5DqYCa88kche6nwIWjLE1p4oMm8nXrR9kQMKbBolNAWERu7q'
  18. }
  19. response = requests.request("GET", url, headers=headers, data=payload, timeout=10)
  20. if response.status_code == 200:
  21. response_json = response.json()
  22. balance = response_json['data']['available_balance']
  23. if balance < BALANCE_LIMIT_THRESHOLD:
  24. bot(
  25. title="kimi余额小于 {} 块".format(BALANCE_LIMIT_THRESHOLD),
  26. detail={
  27. "balance": balance
  28. }
  29. )
  30. else:
  31. bot(
  32. title="kimi余额校验失败",
  33. detail={
  34. "response": response.text
  35. }
  36. )
  37. if __name__ == '__main__':
  38. check_kimi_balance()