Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
/ RSSinn Public archive

RSSinn is a RSS generator powered by FastAPI. RSSinn 是一个基于FastAPI的RSS生成器.

License

Notifications You must be signed in to change notification settings

chinobing/RSSinn

Repository files navigation

介绍

RSSinn是一个基于python FastAPI 的RSS生成器。 利用了FastAPI 自动生成交互式文档、支持 asyncio等特点, 减少了手动创建文档的工作量。

功能说明

fetch

用于解释url,返回

  1. 带Selector的html原始数据,可用于XPath或者CSS
  2. json

参数

  1. proxy: {"proxy_server":"", "proxy_username":"", "proxy_password":""}
  2. fetch_js: True or False #利用playwright获取js加载的网页内容
  3. cache_enabled: True or False #是否cache缓存
#引入
from models.utils import fetch

#使用
response = await fetch(url)

RSS过滤

rssinn集成了内容过滤功能

  1. inculde_keywords:包含指定的关键字;
  2. exclude_keywords:不含指定关键字。

引入方式

from fastapi import APIRouter, Depends
from models.utils import filter_keywords, filter_content

使用方式, 具体可参考feeds/toscrape.py/中的quotes_with_filter例子

demo = APIRouter()

@demo.get("/demo_with_filter/",
              summary="获取带指定关键字的所有quotes",
              description="`inculde_keywords`:包含指定的关键字;`exclude_keywords`:不含指定关键字;")
async def demo_with_filter(filters=Depends(filter_keywords)):
    #获取feed代码
    ......
    
    items_list = []
    for _item in items:
        item = Item(title=_item['author'], author=_item['author'], description=_item['description'])
         # 在item项中添加下面代码即可即可
        _filter = filter_content(item, filters)
        if _filter:
            items_list.append(item)

    feed_data = {
        'title': 'toscrape with content filter',
        'link': 'toscrape.com',
        'description': "",
        'item': items_list,
    }
    feed = RSSFeed(**feed_data)
    return RSSResponse(feed)

路由: https://localhost:28085/demo?include_keywords=[]&exclude_keywords=[]

proxy

这里提供了两种proxy方式

  • 第一种, 直接在setting.yaml中填写相应的proxy
  • 第二种, 在feed脚本中单独添加, 利用了CharlesPikachu freeproxy
#引入
from models.proxy_checker import ProxyChecker

#feed的目标地址
url=http://example.com#返回proxy url
proxy = ProxyChecker.proxy(url)
response = await fetch(url,  proxy={"proxy_server": proxy})

upptime

Upptime (https://upptime.js.org) is the open-source uptime monitor and status page, powered entirely by GitHub Actions, https://github.com/upptime/upptime

请在setting.yaml中填写相应的github usernamerepo

demohttps://www.rssinn.com/upptime

redis or in-memory cache

由于过度实时加载feeds会导致服务器资源紧张, 这里引入了cache

请在setting.yaml中填写相应的cache时间(秒)和方式(redis or in-memory)

使用方式一:cache整个route返回的结果

直接引入@cached()即可

from models.decorator import cached

demo = APIRouter()

@demo.get("/example/")
@cached() 
async def example():
    pass

使用方式二:cache fetch返回的原始html

fetch中添加cache_enabled=True)即可

raw_html = await fetch(url, cache_enabled=True)

这样做的目的是:模拟增量式抓取和数据更新,防止被目标网站封禁

贡献RSS Feed方法

  1. 首先fork这个repository
  2. feeds文件夹中创建新的py脚本,并将对应的APIRoute路由的名称添加到__init__.py, 将对应的APIRoute路由的名称同时添加到根目录的routes.py
  3. 提pr

部署|Deployment

直接部署

下载 RSSinn 的源码

git clone https://github.com/chinobing/RSSinn.git
cd RSSinn

安装依赖库

pip install -r requirements.txt

国内的运行:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

运行playwright

playwright install

运行项目

uvicorn run:app --host 0.0.0.0 --port 28085

注:

  1. requires python 3.8

PDM部署(Linux)

PDM (Python Development Manager) 是一个新的 Python 项目管理器,类似Pipenv 和 Poetry。

下载 RSSinn 的源码

git clone https://github.com/chinobing/RSSinn.git
cd RSSinn

安装PDM

pip install --user pdm

执行pdm init初始化项目,并填写项目信息, 最后生成 pyproject.toml 配置文件

  • 是否要上传 PyPI
  • 依赖的 Python 版本
  • License 类型
  • 作者信息
  • 邮箱信息
  • 是否导入requirements.txt

pdm命令加入path

export PATH=/root/.local/bin:$PATH

安装/更新项目依赖库

pdm update

运行playwright

pdm run playwright install

后台运行项目命令

nohup pdm run uvicorn run:app --host 0.0.0.0 --port 28085 > log.txt 2>&1 &

调试debug命令

pdm run uvicorn run:app --host 0.0.0.0 --port 28085 --reload --debug

关闭进程命令

fuser -n tcp -k 28085

注:

  1. requires Python 3.8

Docker 部署

制作镜像文件

docker build -t "rssinn" .

创建docker容器

docker run -dit -p 28085:28085 rssinn

About

RSSinn is a RSS generator powered by FastAPI. RSSinn 是一个基于FastAPI的RSS生成器.

Topics

Resources

License

Stars

Watchers

Forks