mirror of
https://github.com/rachelos/we-mp-rss.git
synced 2026-09-24 16:02:42 +08:00
v1.4.1
This commit is contained in:
@@ -6,7 +6,7 @@ class Article(Base):
|
||||
title = Column(String(500))
|
||||
pic_url = Column(String(500))
|
||||
url=Column(String(500))
|
||||
content = Column(MEDIUMTEXT)
|
||||
content = Column(Text)
|
||||
description=Column(String(800))
|
||||
status = Column(Integer,default=1)
|
||||
publish_time = Column(Integer)
|
||||
|
||||
+31
-28
@@ -6,39 +6,42 @@ import yaml
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from .base import WxGather
|
||||
|
||||
from core.log import logger
|
||||
# 继承 BaseGather 类
|
||||
class MpsApi(WxGather):
|
||||
|
||||
# 重写 content_extract 方法
|
||||
def content_extract(self, url):
|
||||
session=self.session
|
||||
r = session.get(url, headers=self.headers)
|
||||
if r.status_code == 200:
|
||||
text = r.text
|
||||
if text is None:
|
||||
return
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
# 找到内容
|
||||
js_content_div = soup.find('div', {'id': 'js_content'})
|
||||
# 移除style属性中的visibility: hidden;
|
||||
if js_content_div is None:
|
||||
return
|
||||
js_content_div.attrs.pop('style', None)
|
||||
# 找到所有的img标签
|
||||
img_tags = js_content_div.find_all('img')
|
||||
# 遍历每个img标签并修改属性,设置宽度为1080p
|
||||
for img_tag in img_tags:
|
||||
if 'data-src' in img_tag.attrs:
|
||||
img_tag['src'] = img_tag['data-src']
|
||||
del img_tag['data-src']
|
||||
if 'style' in img_tag.attrs:
|
||||
style = img_tag['style']
|
||||
# 使用正则表达式替换width属性
|
||||
style = re.sub(r'width\s*:\s*\d+\s*px', 'width: 1080px', style)
|
||||
img_tag['style'] = style
|
||||
return js_content_div.prettify()
|
||||
return None
|
||||
try:
|
||||
session=self.session
|
||||
r = session.get(url, headers=self.headers)
|
||||
if r.status_code == 200:
|
||||
text = r.text
|
||||
if text is None:
|
||||
return
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
# 找到内容
|
||||
js_content_div = soup.find('div', {'id': 'js_content'})
|
||||
# 移除style属性中的visibility: hidden;
|
||||
if js_content_div is None:
|
||||
return
|
||||
js_content_div.attrs.pop('style', None)
|
||||
# 找到所有的img标签
|
||||
img_tags = js_content_div.find_all('img')
|
||||
# 遍历每个img标签并修改属性,设置宽度为1080p
|
||||
for img_tag in img_tags:
|
||||
if 'data-src' in img_tag.attrs:
|
||||
img_tag['src'] = img_tag['data-src']
|
||||
del img_tag['data-src']
|
||||
if 'style' in img_tag.attrs:
|
||||
style = img_tag['style']
|
||||
# 使用正则表达式替换width属性
|
||||
style = re.sub(r'width\s*:\s*\d+\s*px', 'width: 1080px', style)
|
||||
img_tag['style'] = style
|
||||
return js_content_div.prettify()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return ""
|
||||
# 重写 get_Articles 方法
|
||||
def get_Articles(self, faker_id:str=None,Mps_id:str=None,Mps_title="",CallBack=None,begin=0,MaxPage:int=1,interval=1,Gather_Content=False,Item_Over_CallBack=None,Over_CallBack=None):
|
||||
super().Start(mp_id=Mps_id)
|
||||
|
||||
+31
-28
@@ -6,39 +6,42 @@ import yaml
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from .base import WxGather
|
||||
|
||||
from core.log import logger
|
||||
# 继承 BaseGather 类
|
||||
class MpsWeb(WxGather):
|
||||
|
||||
# 重写 content_extract 方法
|
||||
def content_extract(self, url):
|
||||
session=self.session
|
||||
r = session.get(url, headers=self.headers)
|
||||
if r.status_code == 200:
|
||||
text = r.text
|
||||
if text is None:
|
||||
return
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
# 找到内容
|
||||
js_content_div = soup.find('div', {'id': 'js_content'})
|
||||
# 移除style属性中的visibility: hidden;
|
||||
if js_content_div is None:
|
||||
return
|
||||
js_content_div.attrs.pop('style', None)
|
||||
# 找到所有的img标签
|
||||
img_tags = js_content_div.find_all('img')
|
||||
# 遍历每个img标签并修改属性,设置宽度为1080p
|
||||
for img_tag in img_tags:
|
||||
if 'data-src' in img_tag.attrs:
|
||||
img_tag['src'] = img_tag['data-src']
|
||||
del img_tag['data-src']
|
||||
if 'style' in img_tag.attrs:
|
||||
style = img_tag['style']
|
||||
# 使用正则表达式替换width属性
|
||||
style = re.sub(r'width\s*:\s*\d+\s*px', 'width: 1080px', style)
|
||||
img_tag['style'] = style
|
||||
return js_content_div.prettify()
|
||||
return None
|
||||
try:
|
||||
session=self.session
|
||||
r = session.get(url, headers=self.headers)
|
||||
if r.status_code == 200:
|
||||
text = r.text
|
||||
if text is None:
|
||||
return
|
||||
soup = BeautifulSoup(text, 'html.parser')
|
||||
# 找到内容
|
||||
js_content_div = soup.find('div', {'id': 'js_content'})
|
||||
# 移除style属性中的visibility: hidden;
|
||||
if js_content_div is None:
|
||||
return
|
||||
js_content_div.attrs.pop('style', None)
|
||||
# 找到所有的img标签
|
||||
img_tags = js_content_div.find_all('img')
|
||||
# 遍历每个img标签并修改属性,设置宽度为1080p
|
||||
for img_tag in img_tags:
|
||||
if 'data-src' in img_tag.attrs:
|
||||
img_tag['src'] = img_tag['data-src']
|
||||
del img_tag['data-src']
|
||||
if 'style' in img_tag.attrs:
|
||||
style = img_tag['style']
|
||||
# 使用正则表达式替换width属性
|
||||
style = re.sub(r'width\s*:\s*\d+\s*px', 'width: 1080px', style)
|
||||
img_tag['style'] = style
|
||||
return js_content_div.prettify()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return ""
|
||||
# 重写 get_Articles 方法
|
||||
def get_Articles(self, faker_id:str=None,Mps_id:str=None,Mps_title="",CallBack=None,begin:int=0,MaxPage:int=1,interval=1,Gather_Content=False,Item_Over_CallBack=None,Over_CallBack=None):
|
||||
super().Start(mp_id=Mps_id)
|
||||
|
||||
@@ -26,6 +26,7 @@ def sync_models():
|
||||
# 同步模型到表结构
|
||||
from core.data_sync import ModelSync
|
||||
DB.create_tables()
|
||||
time.sleep(3)
|
||||
sync=ModelSync(eng=DB.get_engine())
|
||||
sync.sync_all()
|
||||
print_info("模型同步完成")
|
||||
|
||||
@@ -2,6 +2,7 @@ from core.models.article import Article
|
||||
from core.db import DB
|
||||
from core.wx.base import WxGather
|
||||
from time import sleep
|
||||
from core.print import print_success,print_error
|
||||
import random
|
||||
def fetch_articles_without_content():
|
||||
"""
|
||||
@@ -24,24 +25,21 @@ def fetch_articles_without_content():
|
||||
else:
|
||||
url = f"https://mp.weixin.qq.com/s/{article.id}"
|
||||
|
||||
print(f"正在处理文章: {article.id}, URL: {url}")
|
||||
print(f"正在处理文章: {article.title}, URL: {url}")
|
||||
|
||||
# 获取内容
|
||||
content = ga.content_extract(url)
|
||||
sleep(random.randint(1,5))
|
||||
sleep(random.randint(3,10))
|
||||
if content:
|
||||
# 更新内容
|
||||
article.content = content
|
||||
session.commit()
|
||||
print(f"成功更新文章 {article.title} 的内容")
|
||||
print_success(f"成功更新文章 {article.title} 的内容")
|
||||
else:
|
||||
print(f"获取文章 {article.title} 内容失败")
|
||||
print_error(f"获取文章 {article.title} 内容失败")
|
||||
|
||||
except Exception as e:
|
||||
print(f"处理过程中发生错误: {e}")
|
||||
session.rollback()
|
||||
finally:
|
||||
session.close()
|
||||
from core.task import TaskScheduler
|
||||
scheduler=TaskScheduler()
|
||||
from core.config import cfg
|
||||
|
||||
+2
-1
@@ -110,7 +110,8 @@ def web_hook(hook:MessageWebHook):
|
||||
# 处理articles参数,兼容Article对象和字典类型
|
||||
processed_articles = []
|
||||
if len(hook.articles)<=0:
|
||||
raise ValueError("没有更新到文章")
|
||||
# raise ValueError("没有更新到文章")
|
||||
logger.warning("没有更新到文章")
|
||||
return
|
||||
for article in hook.articles:
|
||||
if isinstance(article, dict):
|
||||
|
||||
+10
-5
@@ -33,9 +33,14 @@ if %WEB_FLAG%==1 (
|
||||
|
||||
REM 读取Python配置文件中的版本号
|
||||
for /f "tokens=1 delims==" %%v in ('python -c "from core.ver import VERSION; print(VERSION)"') do set VERSION=%%v
|
||||
set tag="v%VERSION%"
|
||||
if "%VERSION%"=="" (
|
||||
echo 错误:无法从core.ver.py读取版本号
|
||||
exit /b 1
|
||||
)
|
||||
set tag=v%VERSION%
|
||||
echo 当前版本: %VERSION% TAG: %tag%
|
||||
|
||||
|
||||
REM 设置comment
|
||||
if %COMMENT_FLAG%==1 (
|
||||
set comment=%USER_COMMENT%
|
||||
@@ -45,13 +50,13 @@ if %COMMENT_FLAG%==1 (
|
||||
if exist %version_file% (
|
||||
for /f "usebackq delims=" %%a in (%version_file%) do set comment=%%a
|
||||
) else (
|
||||
echo 警告:未找到对应版本号的文件 %version_file%
|
||||
echo "警告:未找到对应版本号的文件%version_file%"
|
||||
)
|
||||
)
|
||||
|
||||
echo %comment%
|
||||
echo "%comment%"
|
||||
git add .
|
||||
git tag "v%VERSION%"
|
||||
git tag -a "v%VERSION%" -m "%VERSION% %comment%"
|
||||
git commit -m "%VERSION% %comment%"
|
||||
|
||||
REM 执行git操作
|
||||
@@ -60,4 +65,4 @@ if %PUSH_FLAG%==1 (
|
||||
git push origin %tag%
|
||||
git push -u gitee main
|
||||
git push gitee %tag%
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user