前言
这是一款由倦意
原创开发的一款wordpress子比主题插件,大致功能是可以通过RSS接口生成一个友链朋友圈的功能,还是挺不错的,有需要的朋友可以下载测试。
插件预览
![图片[1]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227215302405-image-950x524.png!/format/webp/lossless/true)
![图片[2]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227215341485-image-950x515.png!/format/webp/lossless/true)
教程如下
- 部署FreshRSS:
在Github上下载FreshRSS的最新版
https://github.com/FreshRSS/FreshRSS
因为我是用宝塔,所以接下来都是在宝塔上实现,其他运维软件请自行寻找对应方法。
在宝塔上新建一个网站,这里不需要创建数据库,因为我们在后面要使用SQLite。
![图片[3]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227222400559-image-950x598.png!/format/webp/lossless/true)
并将刚刚下载的FreshRSS解压到目录里面去。
在PHP设置中,安装fileinfo
扩展
![图片[4]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227223529901-50ccbfc895d381fd5abee4364358e56d_20240226181552893-QQE688AAE59BBE20240226181540.jpg!/format/webp/lossless/true)
打开网站,我们开始根据提示安装
这里唯一要注意的是数据库配置里面要选择SQLite
- 配置FreshRSS:
搭建好之后,登陆进去之后【设置->管理->认证
】去开启允许api
![图片[5]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227224118552-8bb905a0b44687ac9ee79ebf5b973845.png!/format/webp/lossless/true)
进入【设置->账户->账户管理->API 管理
】设置密码并提交保存,记住设置的api密码
![图片[6]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227224401173-bc9a5b5ff3283e66bb63127c94ad35e7.png!/format/webp/lossless/true)
我们点进去下面这个链接,保存你的API地址:
![图片[7]-子比主题插件 友链朋友圈功能插件-AA源码网 | 源码收藏](https://images.aaym.net/2024/02/20240227225027389-image.png!/format/webp/lossless/true)
- 配置爬虫文件
请确保您已经正确安装Python,一般宝塔自带Python,如未安装,可在本站搜索相关教程。
在网站目录下创建一个spider.py文件,写入以下代码:
(爬虫文件作者obaby,项目链接:https://github.com/obaby/Baby-Freshrss-Client)
- 代码
import json
import time
import html2text
import requests
from bs4 import BeautifulSoup
from pyfiglet import Figlet
FRESHRSS_HOST = 'https://www.aaym.net' #不带最后的/
USERNAME = 'obaby'
PASSWD = '1234567890'
labels = ['集美们'] # 输出的订阅标签list
WRITE_TO_FILE_COUNT = 60
SUB_MAX_ITEMS_COUNT = 2
JSON_FILE_PATH = '/home/wwwroot/wwww.aaym.net/rss.json'
def print_hi(name):
print('*' * 100)
# f = Figlet(font='slant')
f = Figlet()
print(f.renderText('obaby@mars'))
print('FreshRss Client')
print('Verson: 23.12.24')
print('闺蜜圈:https://dayi.ma')
print('Blog: http://oba.by')
print('欢迎帮姐姐推广闺蜜圈啊')
print('*' * 100)
def get_token():
print('[*] Login to get token.')
resp = requests.get(FRESHRSS_HOST+'/api/greader.php/accounts/ClientLogin?Email='+USERNAME+'&Passwd='+ PASSWD).text
# print(resp)
token = resp.split('Auth=')[1].replace('\r','').replace('\n','')
print('[*] Token =',token)
print('[*] ', '-'*100 )
return token
def get_rss_items_list(token):
heaers = {
"Authorization":"GoogleLogin auth=" +token,
"Accept-Encoding":"gzip, deflate",
"User-Agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; wbx 1.0.0; wbxapp 1.0.0; Zoom 3.6.0)",
}
resp = requests.get(FRESHRSS_HOST+'/api/greader.php/reader/api/0/stream/contents/reading-list?n=99999999999&output=json', headers=heaers).text
# print(resp)
return resp
def get_rss_addr_list(token):
heaers = {
"Authorization": "GoogleLogin auth=" + token,
"User-Agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; Tablet PC 2.0; wbx 1.0.0; wbxapp 1.0.0; Zoom 3.6.0)",
}
resp = requests.get(
FRESHRSS_HOST+'/api/greader.php/reader/api/0/subscription/list?output=json&n=10000',
headers=heaers).text
# print(resp)
return resp
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('obaby')
token = get_token()
# body=get_rss_items_list(token)
addr_list = get_rss_addr_list(token)
ajs = json.loads(addr_list)
# print(ajs)
subs = ajs['subscriptions']
print('[*] All subscriptions=',len(subs) )
selected_usb = {}
for s in subs:
cats = s['categories']
for c in cats:
if c['label'] in labels:
# sd = {s['id']:{
# 'title':s['title'],
# 'iconUrl':s['iconUrl']
# }}
selected_usb[s['id']]={
'title':s['title'],
'iconUrl':s['iconUrl']
}
# print(selected_usb)
print('[*] Selected label subscriptions=', len(selected_usb))
body = get_rss_items_list(token)
js = json.loads(body)
print('[*] Total rss item count=',len(js['items']))
sub_count_list = {}
items = js['items']
items = sorted(items, key = lambda item:item['published'], reverse=True)
formated_item = []
for i in items:
string_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(i['published']))
# content = html2text.html2text(i['summary']['content'])
soup = BeautifulSoup(i['summary']['content'], 'html.parser')
content = soup.get_text()
content = content.replace('\r','').replace('\n','')[:100] + '……'
stream_id = i['origin']['streamId']
if not stream_id in selected_usb.keys():
# print(stream_id)
continue
ni = {
"site_name": i['origin']['title'],
"title": i['title'],
"link": i['alternate'][0]['href'],
"time": string_time,
"description": content,
"icon": selected_usb[i['origin']['streamId']]['iconUrl'],
"published":i['published']
}
# formated_item.append(ni)
if stream_id in sub_count_list.keys():
if sub_count_list[stream_id] >=SUB_MAX_ITEMS_COUNT:
continue
else:
formated_item.append(ni)
sub_count_list[stream_id] += 1
else:
formated_item.append(ni)
sub_count_list[stream_id] =1
# print(formated_item)
# print(len(formated_item))
print('[*] Selected labeled rss item count=',len(js['items']))
print('[*] Write json to file......')
for ff in formated_item:
print(ff['time'], ff['title'])
with open(JSON_FILE_PATH, 'w',encoding='utf8') as f:
# 使用json.dump()函数将序列化后的JSON格式的数据写入到文件中
json.dump(formated_item[:WRITE_TO_FILE_COUNT], f, indent=4,ensure_ascii=False)
print('[*] Write json to file done')
print('[*] Write to file items count=', WRITE_TO_FILE_COUNT)
print('[*] Sub items max count=', SUB_MAX_ITEMS_COUNT)
print('[*] All finished.')
print('~' * 200)
FRESHRSS_HOST = 'https://www.aaym.net'
RSSApi地址,填写第二步保存的api地址,后面的api/greader.php不用填写
USERNAME = 'obaby'
后台的用户名
PASSWD = '1234567890'
第二步设置的api密码,注意是api密码不是后台密码
labels = ['集美们']
订阅的分类
WRITE_TO_FILE_COUNT = 60
# 最后写入到json文件的订阅数量
SUB_MAX_ITEMS_COUNT = 2
# 每个站点最多展示的条目
JSON_FILE_PATH = '/home/wwwroot/wwww.aaym.net/rss.json'
输出的json文件路径配置,请放到网站目录下
- 运行爬虫文件
安装必要的运行库文件
pip install Figlet
pip install BeautifulSoup
pip install requests
pip install html2text
试着去执行一遍。反正缺什么补什么
在计划任务中加入以下代码:
cd 填写你的网站绝对地址
php app/actualize_script.php
python spider.py
多少小时执行一次看你心情。
- 在你的网站上显示
这里倦意做了一个小插件,可以很方便的配置,省了很多事情!
将文件丢到WordPress插件目录下,后台启动插件。
插件下载
本文结束END

暂无评论内容