PyBot/开发文档/自主开发文档.md

40 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 个人监测源接入
#### 配置信息
- 路径:./config/
- 配置输出:参考下面函数
```python
def get_debug_config(): # 函数名称,获取调试配置信息
with open('./config/config.yaml', 'r', encoding="utf-8") as file: # 获取配置文件路径
config = yaml.safe_load(file)
debug = f"{config['debug']}" # 加载需要的配置
return debug # 返回配置信息
```
#### 爬虫程序
- 路径:./spider/
- 开发方法使用普通爬虫程序然后提取其中的有用信息以json格式存储于./resources/JSON/中
#### 分析程序
- 路径:./GotoSend/
- 开发方法将json文件中各元素依次存储于./resources/db/内利用sqlite技术存储过程中记得将时间格式化年月日 时分秒使用cursor查询数据库中符合筛选条件的文章最后构造发送文本以markdown+数列的形式返回return
###### 注意事项RSS类订阅信息大多结构类似仅需复制其他RSS源爬虫如common.py进行保留字段删改即可在分析模块中仅需处理时间格式并且注意字段的删改即可复用然后可以现在单独创建函数也可以选择合并入send_job_RSS函数中
#### 核心程序
- 路径:./Core.py
- 开发方法先引入爬虫和分析模块import直接创建新函数然后再main_loop函数中执行即可
参考代码:
```python
from config.check_config import get_core_config, get_debug_config, get_kewords_config # 引入配置信息
from spider.sougou_wx import sougou_wx_main # 引入爬虫模块
from GotoSend.sougou_wx import Src_sougou_wx # 引入分析模块
def send_job_SX(): # 创建新函数
Sogou_WX = get_kewords_config('Sogou_WX') # 获取配置信息
sougou_wx_main(Sogou_WX) # 爬虫爬取信息
result_sx_long = Src_sougou_wx(False) # 获取长文本信息
result_sx_short = Src_sougou_wx(True) # 获取短文本信息
webhook_url, timestamp, sign = gen_sign() # 飞书时间密钥生成
check_avaliable(result_sx_long, result_sx_short, "微信公众号关键词相关内容", webhook_url, timestamp, sign) # 进入筛选程序分发到各渠道
```
- 温馨提示您还可更改send_first_message函数使程序的首次运行提示更加符合程序的运行。