message_maizi_gas.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. '''
  3. 获取麦子钱包实时 gas
  4. '''
  5. import os
  6. import sys
  7. sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
  8. import httpx
  9. from utils.utils_send_gotify import *
  10. from utils.utils_send_serverchan import *
  11. url = "https://a5.maiziqianbao.net/api/v1/chains/EVM/1/gas_price"
  12. headers = {
  13. "Host": "a5.maiziqianbao.net",
  14. "Connection": "keep-alive",
  15. "x-req-token": "MDbO4FsaSUPdjCdvTUs2zY4V3rnvvYatvYyjz7SfY+aCJ8r+RFm06X2dGR8eEDK7Gc5g1TLEQySEhGerRXbDT/NS+e5QAWRU68yD8m4y/aKK+TBkIv90VwvxmvYId2BVoDPDHQCGG4o3EqRWkS93eV0twYQ7w7qvNUj2e3tpDcUZYuplPyLozgYVTegFPnDk",
  16. "Accept": "*/*",
  17. "x-app-type": "iOS-5",
  18. "x-app-ver": "1.0.1",
  19. "x-app-udid": "419815AD-3015-4B5A-92CA-3BCBED24ACEC",
  20. "x-app-locale": "en",
  21. "Accept-Language": "zh-Hans-CN;q=1.0, en-CN;q=0.9",
  22. "Accept-Encoding": "br;q=1.0, gzip;q=0.9, deflate;q=0.8",
  23. "User-Agent": "MathGas/1.0.1 (MathWallet.MathGas; build:3; macOS 13.5.0) Alamofire/5.4.4"
  24. }
  25. response = httpx.get(url, headers=headers)
  26. if response.status_code != 200:
  27. print("Error:", response.status_code)
  28. exit(0)
  29. if not response.json():
  30. print("Error: No response")
  31. exit(0)
  32. remove_last_n_chars = lambda n, n_chars=9: int(str(n)[:-n_chars]) if len(str(n)) > n_chars else n
  33. try:
  34. data = response.json()['data']
  35. fastest = remove_last_n_chars(data['fastest']['price'])
  36. fast = remove_last_n_chars(data['fast']['price'])
  37. standard = remove_last_n_chars(data['standard']['price'])
  38. low = remove_last_n_chars(data['low']['price'])
  39. base = remove_last_n_chars(data['base']['price'])
  40. result = f'fastest: {fastest}\nfast: {fast}\nstandard: {standard}\nlow: {low}\nbase: {base}'
  41. print(result)
  42. if int(fastest) > 20 or int(fast) > 20 or int(standard) > 20 or int(low) > 20 or int(base) > 20:
  43. # 推送到 message
  44. GotifyNotifier('gas 费大于 20', result).send_message()
  45. # 推送到 serverchan
  46. ServerChanNotifier('gas 费大于 20', result.replace('\n', '\n\n')).send_message()
  47. elif int(fastest) < 5 or int(fast) < 5 or int(standard) < 5 or int(low) < 5 or int(base) < 5:
  48. # 推送到 message
  49. GotifyNotifier('gas 费小于 5', result).send_message()
  50. # 推送到 serverchan
  51. ServerChanNotifier('gas 费小于 5', result.replace('\n', '\n\n')).send_message()
  52. except Exception as e:
  53. print(e)
  54. exit(0)