jack 7 mesi fa
parent
commit
df5c516d53

+ 1 - 0
.gitignore

@@ -62,3 +62,4 @@ target/
 
 other/split_clash_config/split_config
 ai_news/save_data
+daily/*.txt

+ 28 - 1
manual/3dos_daily.py → daily/daily_3dos.py

@@ -1,7 +1,13 @@
 # -*- coding: utf-8 -*-
+import sys
+import os
 from httpx import Client
 from concurrent.futures import ThreadPoolExecutor, as_completed
 
+sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
+from utils.utils_send_gotify import *
+from utils.utils_daily_task_scheduler import *
+
 
 def daily_claim_3dos(email, password):
     # client = Client(proxy="http://127.0.0.1:7890")
@@ -134,6 +140,8 @@ def main():
         "yujieccyj10@hotmail.com|||aaaAAA111!!!",
     ]
 
+    send_str = ''
+
     with ThreadPoolExecutor(max_workers=len(account_list)) as executor:
         futures = []
         for account in account_list:
@@ -143,8 +151,27 @@ def main():
         for future in as_completed(futures):
             result = future.result()
             if result:
+                send_str += result + '\n'
                 print(result)
 
+    if send_str:
+        gotify_notifier = GotifyNotifier(title='3dos daily', message=send_str, token_name='CheckAndRemind')
+        gotify_notifier.send_message()
+        print(result)
+    else:
+        print("No news found.")
+
 
 if __name__ == "__main__":
-    main()
+    print('开始 3dos 每日签到')
+    T = TaskScheduler(os.path.join(os.getcwd(), "daily_3dos.txt"))
+    # 执行前读取执行时间, 判断是否到执行时间
+    if not T.load_start_time():
+        print('3dos 任务未到执行时间')
+        exit(1)
+
+    # 开始执行
+    # main()
+
+    # 执行完成后, 将执行时间 + 24 小时写入文件
+    T.save_start_time()

+ 1 - 0
message/message_chaincatcher.py

@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 import sys
 import os
 from playwright.sync_api import sync_playwright

+ 64 - 0
utils/utils_daily_task_scheduler.py

@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+import os
+import time
+from datetime import datetime
+"""
+TaskScheduler 类用于管理定时任务的执行时间。
+
+该类通过在指定的文件中存储时间戳来记录任务的上次执行时间和下次执行时间。
+它提供了两个主要方法:load_start_time 和 save_start_time。
+load_start_time 方法用于检查是否到达任务的执行时间,如果未到达则返回 0,否则返回上次执行时间。
+save_start_time 方法用于更新下次执行时间,默认为当前时间加上指定的时间间隔(默认为 24 小时)。
+
+Attributes:
+    file_path (str): 存储时间戳的文件路径。
+    time_span (int): 任务执行的时间间隔,默认为 86400 秒(24 小时)。
+
+Methods:
+    load_start_time(): 检查是否到达任务的执行时间。
+    save_start_time(): 更新下次执行时间。
+
+Example:
+    >>> scheduler = TaskScheduler("task_time.txt")
+    >>> last_start_time = scheduler.load_start_time()
+    >>> if last_start_time != 0:
+    >>>     # 执行任务
+    >>> scheduler.save_start_time()
+
+Note:
+    该类假设文件路径是有效的,并且有足够的权限进行读写操作。
+    如果文件不存在,将自动创建并写入当前时间戳。
+"""
+
+class TaskScheduler:
+    def __init__(self, file_path, time_span=86400):
+        self.file_path = file_path
+        self.time_span = time_span
+
+    def load_start_time(self):
+        timestamp_now = int(time.time())
+
+        start_time = 0
+        if not os.path.exists(self.file_path):
+            with open(self.file_path, "w") as file:
+                file.write(str(timestamp_now))
+            print('创建执行时间文件 {}'.format(datetime.fromtimestamp(timestamp_now).strftime('%Y-%m-%d %H:%M:%S')))
+            return 0
+        else:
+            with open(self.file_path, "r") as file:
+                start_time = int(file.read())
+            if start_time > timestamp_now:
+                print('任务未到执行时间, 下次执行时间: {}'.format(datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S')))
+                return 0
+            print('开始执行定时任务')
+            return start_time
+
+    def save_start_time(self):
+        timestamp_now = int(time.time())
+        date_now = datetime.fromtimestamp(timestamp_now).strftime('%Y-%m-%d %H:%M:%S')
+
+        # 时间戳 +24 小时
+        timestamp_now += self.time_span
+        print('写入下次执行时间: {}'.format(datetime.fromtimestamp(timestamp_now).strftime('%Y-%m-%d %H:%M:%S')))
+        with open(self.file_path, "w") as file:
+            file.write(str(timestamp_now))

+ 10 - 7
utils/utils_ql_create_tasks.py

@@ -78,6 +78,7 @@ def main():
             spider_path = os.path.join(project_path, 'spider')
             message_path = os.path.join(project_path, 'message')
             manual_path = os.path.join(project_path, 'manual')
+            daily_path = os.path.join(project_path, 'daily')
             tasks_template = [{
                 'base_tasks': [
                     {
@@ -199,14 +200,16 @@ def main():
                         "command": "python3 {}/read_news.py".format(manual_path),
                         "schedule": "0 0 1 1 *",
                         "labels": ["manual"]
-                    },
+                    }
+                ],
+                'daily': [
                     {
-                        "name": "3dos每日签到",
-                        "command": "python3 {}/3dos_daily.py".format(manual_path),
-                        "schedule": "0 0 1 1 *",
-                        "labels": ["manual"]
-                    },
-                ]
+                        "name": "3dos自动签到",
+                        "command": "python3 {}/daily_3dos.py".format(daily_path),
+                        "schedule": "*/5 * * * *",
+                        "labels": ["daily"]
+                    }
+                ],
             }]
 
             for task_template in tasks_template:

+ 1 - 0
utils/utils_send_gotify.py

@@ -18,6 +18,7 @@ class GotifyNotifier:
             'AirdropTasksNews': 'Aoe0VKt-kkZnm8d',
             'weather': 'A9KF--mx_12PjSu',
             'news': 'AT2QGp_vyCX4akW',
+            'CheckAndRemind': 'Aw7XKE2Ppk7Dgwk',
             'test': 'A0Xg6ZE5946iBYg',
         }