message_airdrop_tasks.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from datetime import datetime
  2. import json
  3. import httpx
  4. url = "https://api.chainalert.me/"
  5. headers = {
  6. "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
  7. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
  8. }
  9. text = ''
  10. with httpx.Client() as client:
  11. for page in range(1, 5):
  12. payload = {
  13. "method": "listData",
  14. "params": ['', "CRYPTO_RANK_AIRDROP", page, 0, 0, '']
  15. }
  16. for retry in range(10):
  17. try:
  18. response = client.post(url, headers=headers, data=payload, timeout=3)
  19. except Exception as e:
  20. print(str(e))
  21. continue
  22. if response.status_code != 200:
  23. print(response.status_code)
  24. continue
  25. else:
  26. data = response.json()
  27. if not data:
  28. client.close()
  29. continue
  30. try:
  31. data_list = data['result']
  32. airdrop_list = data_list[0]['data']
  33. airdrop_list = json.loads(airdrop_list)
  34. except Exception as e:
  35. print(str(e))
  36. continue
  37. for airdrop in airdrop_list:
  38. name = airdrop['name']
  39. rank = airdrop['rank']
  40. task = airdrop['item1']
  41. update_date = airdrop['item2']['updateDate']
  42. financing = airdrop['item4']
  43. logoUrl = airdrop['logoUrl']
  44. if task != '无任务':
  45. task = '成本: {}, 耗时: {}, 任务类型: {}'.format(task['cost'], task['time'], task['task'])
  46. text += '任务名称: {}\n排名: {}\n任务详细: {}\n更新时间: {}\n融资: {}\nlogo: {}\n'.format(name, rank, task, update_date, financing, logoUrl)
  47. text += '=' * 50 + '\n'
  48. break
  49. if text:
  50. httpx.post('https://gotify.erhe.top/message?token=Aoe0VKt-kkZnm8d', headers={'Content-Type': 'application/json'}, json={'title': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'message': text})