jack vor 2 Monaten
Ursprung
Commit
d87bf72183

+ 0 - 236
base/base_news_data_collation.py

@@ -1,236 +0,0 @@
-'''
-每日从 mongo 数据库, 做新闻汇总,发送到邮箱
-'''
-import os
-import sys
-
-sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
-
-from pymongo import MongoClient
-from datetime import datetime, timedelta
-import re
-import smtplib
-from email.mime.text import MIMEText
-from email.header import Header
-from base.base_load_config import load_config, get_base_path
-
-config_json = load_config()
-base_project = get_base_path()
-
-PROJECT_NAME = config_json.get('PROJECT_NAME')
-DB_USER = config_json.get('DB_USER')
-DB_PASSWORD = config_json.get('DB_PASSWORD')
-DB_IP = config_json.get('DB_IP')
-DB_PORT = config_json.get('DB_PORT')
-MAIL_HOST = config_json.get('MAIL_HOST')
-MAIL_USER = config_json.get('MAIL_USER')
-MAIL_PASS = config_json.get('MAIL_PASS')
-MAIL_SENDER = config_json.get('MAIL_SENDER')
-MAIL_RECEIVERS = config_json.get('MAIL_RECEIVERS')
-DB_NAME = config_json.get('DB_NAME')  # 确保配置文件中有这个键
-MONGO_LINK = f'mongodb://{DB_USER}:{DB_PASSWORD}@{DB_IP}:{DB_PORT}/'.format(**config_json)
-now_day = datetime.now().strftime('%Y-%m-%d')  # 获取今天的日期
-filter_days = config_json.get('FILTER_DAYS')
-filter_keys = config_json.get('FILTER_KEYS')
-filter_switch = True
-
-
-class NewsDataCollation(object):
-    def __init__(self):
-        # 第三方 SMTP 服务
-        self.mail_host = MAIL_HOST  # 设置服务器
-        self.mail_user = MAIL_USER  # 用户名
-        self.mail_pass = MAIL_PASS  # 口令
-
-        self.sender = MAIL_SENDER
-        self.receivers = [MAIL_RECEIVERS]
-
-        self.processed_data = []
-
-    def load_data(self):
-        processed_data = []
-        # 读取数据
-        print('程序正在读取数据')
-        client = MongoClient(MONGO_LINK)
-        db = client['NEWS']
-
-        # 根据 self.days 获取日期范围
-        start_date = (datetime.now() - timedelta(days=filter_days - 1)).strftime('%Y-%m-%d')
-        end_date = datetime.now().strftime('%Y-%m-%d')
-
-        # 构造查询条件,匹配日期范围内的日期
-        query = {
-            "create_datetime": {
-                "$regex": f"^{start_date}|{end_date}",
-                "$options": "i"  # 使用不区分大小写的匹配
-            }
-        }
-
-        # 遍历数据库中的所有集合
-        for collection_name in db.list_collection_names():
-            print(collection_name)
-            collection = db[collection_name]
-            cursor = collection.find(query)
-            for document in cursor:
-                if not document.get('title'):
-                    continue
-
-                # 检查 'repush_times' 字段是否存在,如果不存在则默认为 5
-                repush_times = document.get('repush_times', 5)
-
-                # 减少 repush_times 的值
-                new_repush_times = repush_times - 1
-
-                # 更新数据库中的 repush_times 字段
-                collection.update_one(
-                    {"_id": document['_id']},  # 假设文档中有 _id 字段作为唯一标识
-                    {"$set": {"repush_times": new_repush_times}}
-                )
-
-                data = self.process_data(document)
-                if data:
-                    processed_data.append(data)
-
-        # 关闭MongoDB连接
-        client.close()
-        return processed_data
-
-    def process_data(self, document):
-        # 处理数据
-        data = {
-            "title": document.get('title') or '',
-            "context": document.get('context') or '',
-            "source_url": document.get('source_url') or '',
-            'link': document.get('link') or '',
-            "article_type": document.get('article_type') or '',
-            "article_source": document.get('article_source') or '',
-            "img_url": document.get('img_url') or '',
-            'keyword': document.get('keyword') or '',
-            "posted_date": document.get('posted_date') or '',
-            "create_time": document.get('create_time') or '',
-            "create_datetime": document.get('create_datetime') or '',
-            "repush_times": document.get('repush_times', 5) - 1
-        }
-
-        data['title'] = self.clean_string(data['title'], 'title')
-        data['context'] = self.clean_string(data['context'], 'context')
-
-        return data
-
-    def clean_string(self, input_string, text_type):
-        # 清除 title 和 context 中的换行符和制表符
-        if not isinstance(input_string, str):
-            return ''
-
-        # 清除所有空白字符(包括空格、制表符、换行符等)
-        cleaned_string = re.sub(r'\s+', '', input_string)
-
-        if len(cleaned_string) > 100:
-            cleaned_string = cleaned_string[:100] + '...'
-
-        if text_type == 'context':
-            pass
-
-        return cleaned_string
-
-    def send_email(self, processed_data):
-        # 发送邮件
-        print('准备发送邮件')
-        subject = '新闻汇总sub'
-        title = '新闻汇总title'
-        text = '********************************************************\n'
-        for data in processed_data:
-            text += '标题: {}\n'.format(data['title'])
-            text += '正文: {}\n'.format(data['context'])
-            text += '文章地址: {}\n'.format(data['link'])
-            text += '类型: {}\n'.format(data['article_type'])
-            text += '板块: {}\n'.format(data['article_source'])
-            text += '文章时间: {}\n'.format(data['posted_date'])
-            text += '获取时间: {}\n'.format(data['create_datetime'])
-            text += '********************************************************\n\n'
-
-        message = MIMEText(text, 'plain', 'utf-8')
-        message['From'] = Header(title, 'utf-8')
-        message['To'] = Header("auto", 'utf-8')
-        message['Subject'] = Header(subject, 'utf-8')
-
-        try:
-            smtpObj = smtplib.SMTP_SSL(self.mail_host)
-            smtpObj.login(self.mail_user, self.mail_pass)
-            smtpObj.sendmail(self.sender, self.receivers, message.as_string())
-            print("邮件发送成功")
-        except smtplib.SMTPException as e:
-            print("Error: 无法发送邮件", e)
-
-    def send_email_with_keyword(self, series, keys, processed_data):
-        process_send_data = {}
-        keys = keys.split('|')
-        have_data_keys = []
-        for key in keys:
-            # print(f'通过关键字: {key} 过滤')  # 用来调试 key 是否正确
-            for data in processed_data:
-                if key in data['title'] or key in data['context']:
-                    # 如果数据里面无 keyword, 用当前 key 替换一下
-                    if not data.get('keyword'):
-                        data['keyword'] = key
-
-                    if series not in process_send_data:
-                        process_send_data[series] = [data]
-                    else:
-                        process_send_data[series].append(data)
-
-                    # 储存一下有数据的 key, 输出用
-                    have_data_keys.append(key)
-
-        if process_send_data:
-            print('{}系列, 以下关键字有数据\n{}'.format(series, list(set(have_data_keys))))
-            # 发送邮件
-            print('程序正在准备发送邮件的数据')
-            for key in process_send_data:
-                subject = '新闻汇总sub - {}'.format(series)
-                title = '新闻汇总title - {}'.format(series)
-                text = '********************************************************\n'
-                for data in process_send_data[key]:
-                    text += '标题: {}\n'.format(data['title'])
-                    text += '正文: {}\n'.format(data['context'])
-                    text += '文章地址: {}\n'.format(data['link'])
-                    text += '类型: {}\n'.format(data['article_type'])
-                    text += '板块: {}\n'.format(data['article_source'])
-                    text += '关键词: {}\n'.format(key)
-                    text += '文章时间: {}\n'.format(data['posted_date'])
-                    text += '获取时间: {}\n'.format(data['create_datetime'])
-                    text += '********************************************************\n\n'
-
-                message = MIMEText(text, 'plain', 'utf-8')
-                message['From'] = Header(title, 'utf-8')
-                message['To'] = Header("auto", 'utf-8')
-                message['Subject'] = Header(subject, 'utf-8')
-
-                try:
-                    smtpObj = smtplib.SMTP_SSL(self.mail_host)
-                    smtpObj.login(self.mail_user, self.mail_pass)
-                    smtpObj.sendmail(self.sender, self.receivers, message.as_string())
-                    print("关键字: {} 的邮件发送成功".format(series))
-                except smtplib.SMTPException as e:
-                    print("Error: 无法发送邮件", e)
-
-    def main(self):
-        # 加载指定天数的所有数据
-        processed_data = self.load_data()
-
-        # 如果无数据, 则退出
-        if not processed_data:
-            print("没有找到任何数据")
-            exit(0)
-
-        # 发送一次所有数据的邮件
-        # self.send_email(processed_data)
-
-        # # 这里是通过关键词过滤然后再发送邮件
-        if filter_switch and filter_keys:
-            for series, keys in filter_keys.items():
-                self.send_email_with_keyword(series, keys, processed_data)
-
-
-if __name__ == '__main__':
-    NewsDataCollation().main()

+ 236 - 0
base/base_utils_ql_create_tasks.py

@@ -0,0 +1,236 @@
+# -*- coding: utf-8 -*-
+import os
+
+import requests
+
+# 青龙面板的地址
+url = "https://auto.erhe.top"
+
+
+# 登录青龙面板
+def login():
+    response = requests.post(f"{url}/api/user/login", json={"username": "toor", "password": "!QAZ2wsx+0913"})
+    print(response)
+    if response.status_code != 200:
+        print(response.status_code)
+        print(response.text)
+        exit(0)
+    return response.json()['data']['token']
+
+
+# 获取任务列表
+def get_tasks(token):
+    response = requests.get(f"{url}/api/crons", headers={"Authorization": f"Bearer {token}"})
+    return response.json()['data']['data']
+
+
+# 创建任务
+def create_task(task_template, token):
+    payload = {
+        "name": task_template["name"],
+        "command": task_template["command"],
+        "schedule": task_template["schedule"],
+        "labels": task_template["labels"]
+    }
+    headers = {
+        "Authorization": f"Bearer {token}",
+        "Content-Type": "application/json"
+    }
+    response = requests.post(f"{url}/api/crons", headers=headers, json=payload)
+    return response.json()
+
+
+# 创建视图分类
+def create_view_type(token):
+    view_type_list = ['base', 'spider_common']
+    for view_type in view_type_list:
+        payload = {
+            "name": view_type,
+            "filters": {
+                'property': 'labels',
+                'operation': 'Reg',
+                'value': view_type
+            },
+            'filterRelation': 'and'
+        }
+        headers = {
+            "Authorization": f"Bearer {token}",
+            "Content-Type": "application/json"
+        }
+        response = requests.post(f"{url}/api/crons", headers=headers, json=payload)
+
+
+# 主逻辑
+def main():
+    while True:
+        try:
+            token = login()
+            print(f"已连接到 {url}")
+            tasks = get_tasks(token)
+            tasks_names = [task['name'] for task in tasks]
+            if tasks:
+                print("Current tasks name: \n{}, \ntotal: {}".format('\n'.join(tasks_names), str(len(tasks_names))))
+            else:
+                print("Tasks list is empty")
+
+            project_path = '/ql/data/scripts/auto/'
+            base_path = os.path.join(project_path, 'base')
+            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': [
+                    {
+                        "name": "每天开始自动创建日志",
+                        "command": "python3 {}/base_daily_logs_generate.py".format(base_path),
+                        "schedule": "0 0 * * *",
+                        "labels": ["base"]
+                    },
+                    {
+                        "name": "每天结束自动发送日志",
+                        "command": "python3 {}/base_daily_logs_send.py".format(base_path),
+                        "schedule": "58 23 * * *",
+                        "labels": ["base"]
+                    },
+                    {
+                        "name": "每天自动删除旧数据",
+                        "command": "python3 {}/base_timing_remove_data.py".format(base_path),
+                        "schedule": "1 0 * * *",
+                        "labels": ["base"]
+                    },
+                    {
+                        "name": "每天新闻汇总,发送到邮箱",
+                        "command": "python3 {}/base_news_data_collation.py".format(base_path),
+                        "schedule": "0 10 6,12,18 * * *",
+                        "labels": ["base"]
+                    },
+                    {
+                        "name": "定时刷新 freshrss 订阅源",
+                        "command": "python3 {}/update_feed.py".format(base_path),
+                        "schedule": "0 6,22 * * *",
+                        "labels": ["base"]
+                    }
+                ],
+                'spider': [
+                    {
+                        "name": "自动执行反斗限免爬虫",
+                        "command": "python3 {}/news_get_apprcn.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "自动执行chiphell爬虫",
+                        "command": "python3 {}/news_get_chiphell.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "自动执行hello_github爬虫",
+                        "command": "python3 {}/news_get_hello_github.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "自动执行Anyknew爬虫",
+                        "command": "python3 {}/news_get_news.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "自动执行币界网文章爬虫",
+                        "command": "python3 {}/spider_web3_coin_world.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "获取 web3 新闻",
+                        "command": "python3 {}/spider_web3_news.py".format(spider_path),
+                        "schedule": "0 0 3,6,9,12,15,18,21 * * *",
+                        "labels": ["spider"]
+                    },
+                    {
+                        "name": "自动执行dlt爬虫",
+                        "command": "python3 {}/spider_get_and_check_dlt.py".format(spider_path),
+                        "schedule": "30 22 * * 1,3,6",
+                        "labels": ["spider"]
+                    }
+                ],
+                'message_tasks': [
+                    {
+                        "name": "获取coin实时数据",
+                        "command": "python3 {}/message_coin_detail.py".format(message_path),
+                        "schedule": "0 * * * *",
+                        "labels": ["message"]
+                    },
+                    {
+                        "name": "对比大乐透最新一期数据,匹配已购买号码,发送消息",
+                        "command": "python3 {}/message_dlt.py".format(message_path),
+                        "schedule": "30 22 * * 1,3,6",
+                        "labels": ["message"]
+                    },
+                    {
+                        "name": "获取未来 7 天的天气预报",
+                        "command": "python3 {}/message_get_one_week_weather.py".format(message_path),
+                        "schedule": "0 0 6,22 * * *",
+                        "labels": ["message"]
+                    },
+                    {
+                        "name": "从 freshrss-psql 数据库中读取数据并发送",
+                        "command": "python3 {}/message_rss_data_handel.py".format(message_path),
+                        "schedule": "30 6,9,12,18,22 * * *",
+                        "labels": ["message"]
+                    },
+                    {
+                        "name": "空投任务消息",
+                        "command": "python3 {}/message_airdrop_tasks.py".format(message_path),
+                        "schedule": "0 8,20 * * *",
+                        "labels": ["message"]
+                    },
+                    {
+                        "name": "链捕手快讯消息推送",
+                        "command": "python3 {}/message_chaincatcher.py".format(message_path),
+                        "schedule": "0 */2 * * *",
+                        "labels": ["message"]
+                    }
+                ],
+                'manual': [
+                    {
+                        "name": "手动读取rss订阅新闻",
+                        "command": "python3 {}/read_news.py".format(manual_path),
+                        "schedule": "0 0 1 1 *",
+                        "labels": ["manual"]
+                    }
+                ],
+                'daily': [
+                    {
+                        "name": "3dos自动签到",
+                        "command": "python3 {}/daily_3dos.py".format(daily_path),
+                        "schedule": "*/5 * * * *",
+                        "labels": ["daily"]
+                    }
+                ],
+            }]
+
+            for task_template in tasks_template:
+                for task_type, task_list in task_template.items():
+                    for task in task_list:
+                        task_name = task["name"]
+                        if task_name in tasks_names:
+                            print("Task {} already exists.".format(task_name))
+                        else:
+                            result = create_task(task, token)
+                            print("Task creation result:", result)
+
+            # 创建所有任务之后, 创建视图分类
+            # create_view_type(token)
+            break  # 正常执行完成后退出循环
+
+        except Exception as e:
+            print("An error occurred: ", e)
+            print("Retrying...")
+
+
+if __name__ == "__main__":
+    main()
+    print('done!')

+ 1 - 0
gotify_config.json

@@ -1,4 +1,5 @@
 {
+  "logs": "A52cfQ1UZ2e.Z0B",
   "base": "A8EVb0Cmxnb2vfk",
   "coin": "AgfOJESqDKftBTQ",
   "dlt": "A3bqt9Dlbs.fPUb",

+ 0 - 0
message/airdrop_tasks/airdrop_tasks.py → message/message_airdrop_tasks.py


+ 0 - 0
message/chaincatcher/chaincatcher.py → message/message_chaincatcher.py


+ 0 - 0
message/coin_detail/coin_detail.py → message/message_coin_detail.py


+ 0 - 0
message/dlt/dlt.py → message/message_dlt.py


+ 0 - 0
message/weather/get_one_week_weather.py → message/message_get_one_week_weather.py


+ 0 - 0
message/rss_data_handel/rss_data_handel.py → message/message_rss_data_handel.py


+ 0 - 0
remind/auto_remind.py → remind/remind_auto_remind.py


+ 170 - 0
utils/utils.py

@@ -0,0 +1,170 @@
+# -*- coding: utf-8 -*-
+import json
+import time
+from datetime import datetime
+import os
+import sys
+
+import httpx
+import pymongo
+
+sys.path.append(os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo'))
+PROJECT_PATH = os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo')
+
+from utils.utils_mongo_handle import MongoHandle
+from base.base_load_config import load_config, get_base_path
+
+config_json = load_config()
+base_project = get_base_path()
+
+
+DB_USER = config_json.get('DB_USER')
+DB_PASSWORD = config_json.get('DB_PASSWORD')
+DB_IP = config_json.get('DB_IP')
+DB_PORT = config_json.get('DB_PORT')
+MONGO_LINK = f'mongodb://{DB_USER}:{DB_PASSWORD}@{DB_IP}:{DB_PORT}/'
+
+
+class LogsHandle(object):
+    def __init__(self):
+        self.now_day = time.strftime('%Y-%m-%d', time.localtime())
+        db = 'logs'
+        collection = 'logs_' + self.now_day
+        self.mongo = MongoHandle(db=db, collection=collection, del_db=False, del_collection=False, auto_remove=0)
+
+    def logs_generate(self):
+        data_to_insert = {
+            "title": "logs",
+            "context": 'generate logs',
+            "state": "create",
+            "create_time": int(time.time()),
+            "create_datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+        }
+
+        self.mongo.collection.insert_one(data_to_insert)
+
+    def logs_send(self):
+        subject = 'auto collection logs'
+        title = 'auto collection - logs: {}'.format(self.now_day)
+        text = ''
+
+        # TODO
+        # 从 mongodb 读取日志, 拼接 text, 发送邮件
+        # 查询所有文档
+        cursor = self.mongo.collection.find()
+        # 遍历结果集
+        for record in cursor:
+            text += "logs_source: {}, logs_detail: {}, state: {} logs_create_time: {}\n\n".format(
+                record.setdefault('title'),
+                record.setdefault('content'),
+                record.setdefault('state'),
+                record.setdefault('create_datetime'),
+            )
+
+        GotifyNotifier(title=title, message=text, token_name='logs').send_message()
+
+    def logs_write(self, title_source=None, content=None, state=None, send_now=False):
+        data_to_insert = {
+            "title": title_source,
+            "context": content,
+            "state": state,
+            "create_time": int(time.time()),
+            "create_datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+        }
+
+        self.mongo.collection.insert_one(data_to_insert)
+
+        if send_now:
+            title = 'Auto Info - running logs: {}'.format(self.now_day)
+            text = 'logs_source: {}, logs_detail: {}, state: {} logs_create_time: {}'.format(
+                data_to_insert.setdefault('title'),
+                data_to_insert.setdefault('content'),
+                data_to_insert.setdefault('state'),
+                data_to_insert.setdefault('create_datetime'),
+            )
+
+            GotifyNotifier(title=title, message=text, token_name='logs').send_message()
+
+
+class MongoHandle(object):
+    def __init__(self, db, collection, del_db=False, del_collection=False, auto_remove=0):
+        self.client = pymongo.MongoClient(MONGO_LINK)
+        self.db = db
+        self.collection = collection
+
+        if del_db and db:
+            # 检查数据库是否存在
+            if db in self.client.list_database_names():
+                # 删除数据库
+                self.client.drop_database(db)
+        self.db = self.client[db]
+
+        if del_collection and self.collection:
+            # 检查集合是否存在
+            if self.collection in self.db.list_collection_names():
+                # 删除集合
+                self.db.drop_collection(collection)
+        self.collection = self.db[collection]
+
+        if auto_remove:
+            self.auto_remove_data(auto_remove)
+
+    def write_data(self, data):
+        self.collection.insert_one(data)
+
+    def load_data(self):
+        # MongoDB 会在第一次写入时自动创建数据库和集合
+        return list(self.collection.find({}, {'_id': False}))
+
+    def auto_remove_data(self, day):
+        for data in self.collection.find({'create_time': {'$lt': int(time.time()) - day * 24 * 60 * 60}}):
+            self.collection.delete_one({'_id': data['_id']})
+
+
+class GotifyNotifier:
+    def __init__(self, title, message, token_name=''):
+        self.gotify_url = 'https://gotify.erhe.top'
+        self.app_token = self.match_token_name(token_name)
+        self.title = title
+        self.message = message
+
+    def match_token_name(self, name):
+        token_name_dict = {}
+        # 读取项目根目录下的 gotify_config.json 文件
+        gotify_config_path = os.path.join(PROJECT_PATH, 'gotify_config.json')
+        with open(gotify_config_path, 'r') as f:
+            token_name_dict = json.load(f)
+        token = token_name_dict.get(name)
+        if token:
+            return token
+        else:
+            return token_name_dict['base']
+
+    def send_message(self):
+        # 构建POST请求的headers
+        headers = {
+            'Content-Type': 'application/json'
+        }
+
+        # 构建POST请求的body
+        body = {
+            'title': self.title,
+            'message': self.message
+        }
+
+        # 发送POST请求
+        with httpx.Client() as client:
+            response = client.post(
+                url=f"{self.gotify_url}/message?token={self.app_token}",
+                headers=headers,
+                json=body
+            )
+
+        # 或者可以使用 curl
+        # curl -k "https://gotify.erhe.top/message?token=A0Xg6ZE5946iBYg" -F "title=测试发送信息" -F "message=假装有信息,测试发送" -F "priority=5"
+
+        # 检查响应状态码
+        if response.status_code == 200:
+            print('Gotify Message sent successfully!')
+        else:
+            print('Failed to send message:', response.text)

+ 0 - 54
utils/utils_gotify.py

@@ -1,54 +0,0 @@
-# -*- coding: utf-8 -*-
-import httpx
-import json
-import os
-
-PROJECT_PATH = os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo')
-
-class GotifyNotifier:
-    def __init__(self, title, message, token_name=''):
-        self.gotify_url = 'https://gotify.erhe.top'
-        self.app_token = self.match_token_name(token_name)
-        self.title = title
-        self.message = message
-
-    def match_token_name(self, name):
-        token_name_dict = {}
-        # 读取项目根目录下的 gotify_config.json 文件
-        gotify_config_path = os.path.join(PROJECT_PATH, 'gotify_config.json')
-        with open(gotify_config_path, 'r') as f:
-            token_name_dict = json.load(f)
-        token = token_name_dict.get(name)
-        if token:
-            return token
-        else:
-            return token_name_dict['base']
-
-    def send_message(self):
-        # 构建POST请求的headers
-        headers = {
-            'Content-Type': 'application/json'
-        }
-
-        # 构建POST请求的body
-        body = {
-            'title': self.title,
-            'message': self.message
-        }
-
-        # 发送POST请求
-        with httpx.Client() as client:
-            response = client.post(
-                url=f"{self.gotify_url}/message?token={self.app_token}",
-                headers=headers,
-                json=body
-            )
-
-        # 或者可以使用 curl
-        # curl -k "https://gotify.erhe.top/message?token=A0Xg6ZE5946iBYg" -F "title=测试发送信息" -F "message=假装有信息,测试发送" -F "priority=5"
-
-        # 检查响应状态码
-        if response.status_code == 200:
-            print('Gotify Message sent successfully!')
-        else:
-            print('Failed to send message:', response.text)

+ 0 - 81
utils/utils_logs_handle.py

@@ -1,81 +0,0 @@
-# -*- coding: UTF-8 -*-
-'''
-获取每天日期,新建 logs 文件
-存到 logs 文件夹中
-'''
-import time
-from datetime import datetime
-import os
-import sys
-
-sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
-
-from utils.utils_mongo_handle import MongoHandle
-from base.base_load_config import load_config, get_base_path
-
-config_json = load_config()
-base_project = get_base_path()
-
-
-class LogsHandle(object):
-    def __init__(self):
-        self.now_day = time.strftime('%Y-%m-%d', time.localtime())
-        db = 'logs'
-        collection = 'logs_' + self.now_day
-        self.mongo = MongoHandle(db=db, collection=collection, del_db=False, del_collection=False, auto_remove=0)
-
-    def logs_generate(self):
-        data_to_insert = {
-            "title": "logs",
-            "context": 'generate logs',
-            "state": "create",
-            "create_time": int(time.time()),
-            "create_datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
-        }
-
-        self.mongo.collection.insert_one(data_to_insert)
-
-    def logs_send(self):
-        subject = 'auto collection logs'
-        title = 'auto collection - logs: {}'.format(self.now_day)
-        text = ''
-
-        # TODO
-        # 从 mongodb 读取日志, 拼接 text, 发送邮件
-        # 查询所有文档
-        cursor = self.mongo.collection.find()
-        # 遍历结果集
-        for record in cursor:
-            text += "logs_source: {}, logs_detail: {}, state: {} logs_create_time: {}\n\n".format(
-                record.setdefault('title'),
-                record.setdefault('content'),
-                record.setdefault('state'),
-                record.setdefault('create_datetime'),
-            )
-
-        S = SendEmail(subject=subject, title=title, text=text)
-        S.send()
-
-    def logs_write(self, title_source=None, content=None, state=None, send_now=False):
-        data_to_insert = {
-            "title": title_source,
-            "context": content,
-            "state": state,
-            "create_time": int(time.time()),
-            "create_datetime": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
-        }
-
-        self.mongo.collection.insert_one(data_to_insert)
-
-        if send_now:
-            subject = 'auto collection'
-            title = 'auto collection - running logs: {}'.format(self.now_day)
-            text = 'logs_source: {}, logs_detail: {}, state: {} logs_create_time: {}'.format(
-                data_to_insert.setdefault('title'),
-                data_to_insert.setdefault('content'),
-                data_to_insert.setdefault('state'),
-                data_to_insert.setdefault('create_datetime'),
-            )
-
-            Send = SendEmail(subject=subject, title=title, text=text)
-            Send.send()

+ 0 - 62
utils/utils_mongo_handle.py

@@ -1,62 +0,0 @@
-# -*-coding: utf-8 -*-
-import pymongo
-from pymongo import errors
-import time
-import sys
-import os
-
-sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
-
-from base.base_load_config import load_config, get_base_path
-
-config_json = load_config()
-base_project = get_base_path()
-
-DB_USER = config_json.get('DB_USER')
-DB_PASSWORD = config_json.get('DB_PASSWORD')
-DB_IP = config_json.get('DB_IP')
-DB_PORT = config_json.get('DB_PORT')
-MONGO_LINK = f'mongodb://{DB_USER}:{DB_PASSWORD}@{DB_IP}:{DB_PORT}/'
-
-
-class MongoHandle(object):
-    def __init__(self, db, collection, del_db=False, del_collection=False, auto_remove=0):
-        self.client = pymongo.MongoClient(MONGO_LINK)
-        self.db = db
-        self.collection = collection
-
-        if del_db and db:
-            # 检查数据库是否存在
-            if db in self.client.list_database_names():
-                # 删除数据库
-                self.client.drop_database(db)
-        self.db = self.client[db]
-
-        if del_collection and self.collection:
-            # 检查集合是否存在
-            if self.collection in self.db.list_collection_names():
-                # 删除集合
-                self.db.drop_collection(collection)
-        self.collection = self.db[collection]
-
-        if auto_remove:
-            self.auto_remove_data(auto_remove)
-
-    def write_data(self, data):
-        self.collection.insert_one(data)
-
-    def load_data(self):
-        # MongoDB 会在第一次写入时自动创建数据库和集合
-        return list(self.collection.find({}, {'_id': False}))
-
-    def auto_remove_data(self, day):
-        for data in self.collection.find({'create_time': {'$lt': int(time.time()) - day * 24 * 60 * 60}}):
-            self.collection.delete_one({'_id': data['_id']})
-
-# if __name__ == '__main__':
-#     mongo = MongoHandle('test_db', 'test_collection', False, False, 0)
-#     mongo.collection.insert_one({'name': 'test'})
-#     mongo.collection.insert_many([{'name': 'test1'}, {'name': 'test2'}])
-#     print(mongo.collection.find_one())
-#     print(mongo.collection.find())
-#     print('done!')