airdrop_tasks.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. n = 0
  11. with httpx.Client() as client:
  12. for page in range(1, 5):
  13. payload = {
  14. "method": "listData",
  15. "params": ['', "CRYPTO_RANK_AIRDROP", page, 0, 0, '']
  16. }
  17. for retry in range(10):
  18. try:
  19. response = client.post(url, headers=headers, data=payload, timeout=3)
  20. except Exception as e:
  21. print(str(e))
  22. continue
  23. if response.status_code != 200:
  24. print(response.status_code)
  25. continue
  26. else:
  27. data = response.json()
  28. if not data:
  29. client.close()
  30. continue
  31. try:
  32. data_list = data['result']
  33. airdrop_list = data_list[0]['data']
  34. airdrop_list = json.loads(airdrop_list)
  35. except Exception as e:
  36. print(str(e))
  37. continue
  38. for airdrop in airdrop_list:
  39. name = airdrop['name']
  40. rank = airdrop['rank']
  41. task = airdrop['item1']
  42. update_date = airdrop['item2']['updateDate']
  43. financing = airdrop['item4']
  44. logoUrl = airdrop['logoUrl']
  45. if task == '无任务':
  46. continue
  47. if task == 'No active tasks':
  48. continue
  49. task = '成本: {}, 耗时: {}, 任务类型: {}'.format(task.get('cost'), task.get('time'), task.get('task'))
  50. text += '任务名称: {}\n排名: {}\n任务详细: {}\n更新时间: {}\n融资: {}\nlogo: {}\n'.format(name, rank, task, update_date, financing, logoUrl)
  51. text += '=' * 50 + '\n'
  52. n += 1
  53. break
  54. if text:
  55. print(f'一共 {n} 条数据')
  56. 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})