فهرست منبع

自动发送message增加, 空投任务消息

Jack 11 ماه پیش
والد
کامیت
fd4c260e18
2فایلهای تغییر یافته به همراه56 افزوده شده و 40 حذف شده
  1. 0 40
      manual/airdrop_list/main.py
  2. 56 0
      message/message_airdrop_tasks.py

+ 0 - 40
manual/airdrop_list/main.py

@@ -1,40 +0,0 @@
-import time
-from datetime import datetime
-import httpx
-
-url = "https://api.chainalert.me/"
-headers = {
-    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
-    "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"
-}
-
-for page in range(1, 11):
-    payload = {
-        "method": "listData",
-        "params": ['', "CRYPTO_RANK_AIRDROP", page, 0, 0, '']
-    }
-
-    with httpx.Client() as client:
-        time.sleep(3)
-        try:
-            response = client.post(url, headers=headers, data=payload, timeout=3)
-        except Exception as e:
-            client.close()
-            continue
-        if response.status_code != 200:
-            client.close()
-            continue
-        else:
-            text = ''
-            data = response.json()
-            if not data:
-                client.close()
-                continue
-
-            data_list = data['result']
-            airdrop_list = data_list[0]['data']
-            print(airdrop_list)
-            # target_data = eval(data['result'][0]['data'])
-            # target_data = target_data[0]
-            #
-            # print(target_data)

+ 56 - 0
message/message_airdrop_tasks.py

@@ -0,0 +1,56 @@
+from datetime import datetime
+import json
+import httpx
+
+url = "https://api.chainalert.me/"
+headers = {
+    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
+    "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"
+}
+text = ''
+with httpx.Client() as client:
+    for page in range(1, 5):
+        payload = {
+            "method": "listData",
+            "params": ['', "CRYPTO_RANK_AIRDROP", page, 0, 0, '']
+        }
+        for retry in range(10):
+            try:
+                response = client.post(url, headers=headers, data=payload, timeout=3)
+            except Exception as e:
+                print(str(e))
+                continue
+            if response.status_code != 200:
+                print(response.status_code)
+                continue
+            else:
+                data = response.json()
+                if not data:
+                    client.close()
+                    continue
+
+                try:
+                    data_list = data['result']
+                    airdrop_list = data_list[0]['data']
+                    airdrop_list = json.loads(airdrop_list)
+                except Exception as e:
+                    print(str(e))
+                    continue
+                for airdrop in airdrop_list:
+                    name = airdrop['name']
+                    rank = airdrop['rank']
+                    task = airdrop['item1']
+                    update_date = airdrop['item2']['updateDate']
+                    financing = airdrop['item4']
+                    logoUrl = airdrop['logoUrl']
+
+                    if task != '无任务':
+                        task = '成本: {}, 耗时: {}, 任务类型: {}'.format(task['cost'], task['time'], task['task'])
+
+                    text += '任务名称: {}\n排名: {}\n任务详细: {}\n更新时间: {}\n融资: {}\nlogo: {}\n'.format(name, rank, task, update_date, financing, logoUrl)
+                    text += '=' * 50 + '\n'
+
+                break
+
+if text:
+    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})