diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..e857061
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2021 felinae98
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index c3a3965..37f18bb 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,12 @@
-# hk-reporter 通用订阅推送插件
+
+
hk-reporter 通用订阅推送插件
+
+
+
+[](https://pypi.org/project/nonebot-hk-reporter/)
+[](https://qm.qq.com/cgi-bin/qm/qr?k=pXYMGB_e8b6so3QTqgeV6lkKDtEeYE4f&jump_from=webapi)
+
+
## 简介
一款自动爬取各种站点,社交平台更新动态,并将信息推送到QQ的机器人。基于 [`NoneBot2`](https://github.com/nonebot/nonebot2 ) 开发(诞生于明日方舟的蹲饼活动)
@@ -9,13 +17,13 @@
* 文字
* 不支持视频
* 不支持转发的内容
-* bilibili
+* Bilibili
* 图片
* 专栏
* 文字
* 视频链接
* 不支持转发的内容
-* rss
+* RSS
* 从description中提取图片
* 文字
@@ -25,6 +33,15 @@
本项目可作为单独插件使用,仅包含订阅相关功能(绝对simple和stupid),也可直接克隆项目进行使用(包含自动同意superuser,自动接受入群邀请等功能)
作为插件使用请安装`nonebot-hk-reporter`包,并在`bot.py`中加载`nonebot_hk_reporter`插件;或直接克隆本项目进行使用
配置与安装请参考[nonebot2文档](https://v2.nonebot.dev/)
+
+Docker部署方法
+
+Docker镜像地址为`felinae98/nonebot-hk-reporter`对应main分支,`felinae98/nonebot-hk-reporter:arknights`对应arknights分支。例子:
+```bash
+docker run --name nonebot-hk-reporter --network -d -e 'SUPERUSERS=[]' -v :/data -e 'hk_reporter_config_path=/data' -e 'HK_REPORTER_USE_PIC=True' -e 'HK_REPORTER_USE_LOCAL=True' felinae98/nonebot-hk-reporter
+```
+go-cqhttp镜像可使用`felinae98/go-cqhttp-ffmpeg`(数据目录为`/data`),需要注意,两个容器需要在同一个network中。
+
### 配置变量
* `HK_REPORTER_CONFIG_PATH` (str) 配置文件保存目录,如果不设置,则为当前目录下的`data`文件夹
@@ -37,26 +54,26 @@
* 查询订阅:`查询订阅`
* 删除订阅(仅管理员和群主):`删除订阅`
-平台代码包含:weibo,bilibili,rss
+平台代码包含:Weibo,Bilibili,RSS
各平台uid
下面均以pc站点为例
-* weibo
+* Weibo
* 对于一般用户主页`https://weibo.com/u/6441489862?xxxxxxxxxxxxxxx`,`/u/`后面的数字即为uid
* 对于有个性域名的用户如:`https://weibo.com/arknights`,需要点击左侧信息标签下“更多”,链接为`https://weibo.com/6279793937/about`,其中中间数字即为uid
-* bilibili
+* Bilibili
* 主页链接一般为`https://space.bilibili.com/161775300?xxxxxxxxxx`,数字即为uid
-* rss
- * rss链接即为uid
+* RSS
+ * RSS链接即为uid
### 文字转图片
-因为可能要发送长文本,所以bot很可能被风控,如有需要请开启以图片形式发送文字,本项目使用的图片转文字方法是chromium(经典杀鸡用牛刀)。
+因为可能要发送长文本,所以bot很可能被风控,如有需要请开启以图片形式发送文字,本项目使用的文字转图片方法是Chromium(经典杀鸡用牛刀)。
-如果确定要开启推荐自行安装chromium,设置使用本地chromium,并且保证服务器有比较大的内存。
+如果确定要开启推荐自行安装Chromium,设置使用本地Chromium,并且保证服务器有比较大的内存。
## 功能
-* 定时爬取制定网站
+* 定时爬取指定网站
* 通过图片发送文本,防止风控
* 使用队列限制发送频率
diff --git a/pyproject.toml b/pyproject.toml
index c01f96b..d5e1996 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-hk-reporter"
-version = "0.2.2"
+version = "0.2.5"
description = "Subscribe message from social medias"
authors = ["felinae98 "]
license = "MIT"
@@ -8,8 +8,8 @@ homepage = "https://github.com/felinae98/nonebot-hk-reporter"
keywords = ["nonebot", "nonebot2", "qqbot"]
readme = "README.md"
packages = [
- { include = "hk_reporter/*.py", from = "./src/plugins/" },
- { include = "hk_reporter/platform/*.py", from = "./src/plugins/" }
+ { include = "nonebot_hk_reporter/*.py", from = "./src/plugins/" },
+ { include = "nonebot_hk_reporter/platform/*.py", from = "./src/plugins/" }
]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
diff --git a/src/plugins/hk_reporter/__init__.py b/src/plugins/nonebot_hk_reporter/__init__.py
similarity index 100%
rename from src/plugins/hk_reporter/__init__.py
rename to src/plugins/nonebot_hk_reporter/__init__.py
diff --git a/src/plugins/hk_reporter/config.py b/src/plugins/nonebot_hk_reporter/config.py
similarity index 100%
rename from src/plugins/hk_reporter/config.py
rename to src/plugins/nonebot_hk_reporter/config.py
diff --git a/src/plugins/hk_reporter/config_manager.py b/src/plugins/nonebot_hk_reporter/config_manager.py
similarity index 100%
rename from src/plugins/hk_reporter/config_manager.py
rename to src/plugins/nonebot_hk_reporter/config_manager.py
diff --git a/src/plugins/hk_reporter/platform/__init__.py b/src/plugins/nonebot_hk_reporter/platform/__init__.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/__init__.py
rename to src/plugins/nonebot_hk_reporter/platform/__init__.py
diff --git a/src/plugins/hk_reporter/platform/arkninghts.py b/src/plugins/nonebot_hk_reporter/platform/arkninghts.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/arkninghts.py
rename to src/plugins/nonebot_hk_reporter/platform/arkninghts.py
diff --git a/src/plugins/hk_reporter/platform/bilibili.py b/src/plugins/nonebot_hk_reporter/platform/bilibili.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/bilibili.py
rename to src/plugins/nonebot_hk_reporter/platform/bilibili.py
diff --git a/src/plugins/hk_reporter/platform/platform.py b/src/plugins/nonebot_hk_reporter/platform/platform.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/platform.py
rename to src/plugins/nonebot_hk_reporter/platform/platform.py
diff --git a/src/plugins/hk_reporter/platform/rss.py b/src/plugins/nonebot_hk_reporter/platform/rss.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/rss.py
rename to src/plugins/nonebot_hk_reporter/platform/rss.py
diff --git a/src/plugins/hk_reporter/platform/utils.py b/src/plugins/nonebot_hk_reporter/platform/utils.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/utils.py
rename to src/plugins/nonebot_hk_reporter/platform/utils.py
diff --git a/src/plugins/hk_reporter/platform/weibo.py b/src/plugins/nonebot_hk_reporter/platform/weibo.py
similarity index 100%
rename from src/plugins/hk_reporter/platform/weibo.py
rename to src/plugins/nonebot_hk_reporter/platform/weibo.py
diff --git a/src/plugins/hk_reporter/plugin_config.py b/src/plugins/nonebot_hk_reporter/plugin_config.py
similarity index 100%
rename from src/plugins/hk_reporter/plugin_config.py
rename to src/plugins/nonebot_hk_reporter/plugin_config.py
diff --git a/src/plugins/hk_reporter/post.py b/src/plugins/nonebot_hk_reporter/post.py
similarity index 100%
rename from src/plugins/hk_reporter/post.py
rename to src/plugins/nonebot_hk_reporter/post.py
diff --git a/src/plugins/hk_reporter/scheduler.py b/src/plugins/nonebot_hk_reporter/scheduler.py
similarity index 100%
rename from src/plugins/hk_reporter/scheduler.py
rename to src/plugins/nonebot_hk_reporter/scheduler.py
diff --git a/src/plugins/hk_reporter/send.py b/src/plugins/nonebot_hk_reporter/send.py
similarity index 100%
rename from src/plugins/hk_reporter/send.py
rename to src/plugins/nonebot_hk_reporter/send.py
diff --git a/src/plugins/hk_reporter/types.py b/src/plugins/nonebot_hk_reporter/types.py
similarity index 100%
rename from src/plugins/hk_reporter/types.py
rename to src/plugins/nonebot_hk_reporter/types.py
diff --git a/src/plugins/hk_reporter/utils.py b/src/plugins/nonebot_hk_reporter/utils.py
similarity index 74%
rename from src/plugins/hk_reporter/utils.py
rename to src/plugins/nonebot_hk_reporter/utils.py
index c351c69..74d4b0f 100644
--- a/src/plugins/hk_reporter/utils.py
+++ b/src/plugins/nonebot_hk_reporter/utils.py
@@ -5,8 +5,10 @@ import nonebot
from nonebot import logger
import base64
from pyppeteer import launch
+from pyppeteer.chromium_downloader import check_chromium, download_chromium
from html import escape
from hashlib import sha256
+from tempfile import NamedTemporaryFile
from .plugin_config import plugin_config
@@ -19,6 +21,10 @@ class Singleton(type):
supported_target_type = ('weibo', 'bilibili', 'rss', 'arknights')
+if not plugin_config.hk_reporter_use_local and not check_chromium():
+ os.environ['PYPPETEER_DOWNLOAD_HOST'] = 'http://npm.taobao.org/mirrors'
+ download_chromium()
+
class Render(metaclass=Singleton):
def __init__(self):
@@ -44,14 +50,14 @@ class Render(metaclass=Singleton):
return str(data)
async def text_to_pic(self, text: str) -> str:
- hash_text = sha256(text.encode()).hexdigest()[:20]
lines = text.split('\n')
parsed_lines = list(map(lambda x: '{}
'.format(escape(x)), lines))
html_text = '{}
'.format(''.join(parsed_lines))
- with open('/tmp/text-{}.html'.format(hash_text), 'w') as f:
- f.write(html_text)
- data = await self.render('file:///tmp/text-{}.html'.format(hash_text), target='div')
- os.remove('/tmp/text-{}.html'.format(hash_text))
+ with NamedTemporaryFile('wt', suffix='.html', delete=False) as tmp:
+ tmp_path = tmp.name
+ tmp.write(html_text)
+ data = await self.render('file://{}'.format(tmp_path), target='div')
+ os.remove(tmp_path)
return data
async def text_to_pic_cqcode(self, text:str) -> str:
@@ -61,10 +67,10 @@ class Render(metaclass=Singleton):
# logger.debug(code)
return code
-async def parse_text(text: str):
+async def parse_text(text: str) -> str:
+ 'return raw text if don\'t use pic, otherwise return rendered opcode'
if plugin_config.hk_reporter_use_pic:
- r = Render()
- return await r.text_to_pic_cqcode(text)
+ render = Render()
+ return await render.text_to_pic_cqcode(text)
else:
return text
-