From b7dceccd251d01b7d3b47e51fb8f37bb403d0f81 Mon Sep 17 00:00:00 2001 From: RachelOS <1327444968@qq.com> Date: Thu, 18 Dec 2025 15:09:59 +0800 Subject: [PATCH] =?UTF-8?q?1.4.8-=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E9=97=B4=E9=9A=94=EF=BC=8C=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E8=A2=AB=E9=A3=8E=E6=8E=A7=E6=A6=82=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/wait.py | 7 +++++++ core/wx/base.py | 7 ++++--- driver/wxarticle.py | 7 ++----- jobs/fetch_no_article.py | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 core/wait.py diff --git a/core/wait.py b/core/wait.py new file mode 100644 index 00000000..fb841849 --- /dev/null +++ b/core/wait.py @@ -0,0 +1,7 @@ +import random +import time +from core.print import print_warning +def Wait(min=10,max=60,tips:str=""): + wait=random.randint(min,max) + print_warning(f"{tips} 等待{wait}秒后重试...") + time.sleep(wait) \ No newline at end of file diff --git a/core/wx/base.py b/core/wx/base.py index 88092e9a..85e21c05 100644 --- a/core/wx/base.py +++ b/core/wx/base.py @@ -10,6 +10,7 @@ from core.print import print_error,print_info, print_warning from core.rss import RSS from driver.success import setStatus from driver.wxarticle import Web +from core.wait import Wait import random # 定义一些常见的 User-Agent USER_AGENTS = [ @@ -111,7 +112,7 @@ class WxGather: text = r.text text=self.remove_common_html_elements(text) if "当前环境异常,完成验证后即可继续访问" in text: - self.Wait(tips="当前环境异常,完成验证后即可继续访问") + Wait(tips="当前环境异常,完成验证后即可继续访问") text="" except: pass @@ -142,7 +143,7 @@ class WxGather: art["ext"]=Ext_Data # art.pop("content") self.articles.append(art) - + Wait(min=1,max=5,tips=f"获取 {data['title']}...") #通过公众号码平台接口查询公众号 def search_Biz(self,kw:str="",limit=10,offset=0): @@ -207,7 +208,7 @@ class WxGather: _cookies.append({'name':'token','value':self.token}) if CallBack is not None: CallBack(item) - self.Wait(tips=f"{item['title']} 处理完成",min=3,max=10) + self.Wait(tips=f"{item['mps_title']} 处理完成",min=3,max=10) pass def Error(self,error:str,code=None): self.Over() diff --git a/driver/wxarticle.py b/driver/wxarticle.py index 1482ecf8..3c4d5806 100644 --- a/driver/wxarticle.py +++ b/driver/wxarticle.py @@ -4,6 +4,7 @@ from .playwright_driver import PlaywrightController from typing import Dict from core.print import print_error,print_info,print_success,print_warning import time +import core.wait as Wait import base64 import re import os @@ -202,7 +203,7 @@ class WXArticleFetcher: article_data['content'] = content_backup # 避免请求过快,但只在非最后一个请求时等待 - self.Wait(3,10,tips=f"处理第 {i}/{total_count} 篇文章") + Wait(1,2,tips=f"处理第 {i}/{total_count} 篇文章") except Exception as e: print_error(f"处理文章失败 {url}: {e}") @@ -223,10 +224,6 @@ class WXArticleFetcher: with ThreadPoolExecutor() as pool: future = loop.run_in_executor(pool, self.get_article_content, url) return await future - def Wait(self,min=10,max=60,tips:str=""): - wait=random.randint(min,max) - print_warning(f"{tips}等待{wait}秒后重试...") - time.sleep(wait) def get_article_content(self, url: str) -> Dict: """获取单篇文章详细内容 diff --git a/jobs/fetch_no_article.py b/jobs/fetch_no_article.py index d9bf46ec..05402995 100644 --- a/jobs/fetch_no_article.py +++ b/jobs/fetch_no_article.py @@ -1,5 +1,6 @@ from core.models.article import Article,DATA_STATUS import core.db as db +from core.wait import Wait from core.wx.base import WxGather from time import sleep from core.print import print_success,print_error @@ -35,7 +36,6 @@ def fetch_articles_without_content(): content=Web.get_article_content(url).get("content") else: content = ga.content_extract(url) - sleep(random.randint(3,10)) if content: # 更新内容 article.content = content @@ -46,7 +46,7 @@ def fetch_articles_without_content(): print_success(f"成功更新文章 {article.title} 的内容") else: print_error(f"获取文章 {article.title} 内容失败") - + Wait(min=5,max=10,tips=f"修正 {article.title}... 完成") except Exception as e: print(f"处理过程中发生错误: {e}") finally: