基于 webhook 的博文提交器
Project description
submitter
✨ 基于 webhook 的博文提交器 ✨
教程
下面这段代码是适配的我自己在阿里云上创建的 webhook 实例。这个实例是通过扫描哔哩哔哩二维码来实现账户验证的,所以我们在创建账号时要先获取B站的验证链接,生成二维码。此时程序会通过输入暂停住,用手机扫码后稍等三秒再回车就可以通过验证了。Token
信息也会打印在屏幕上,可以保存在代码里,这样下次登录就不用账号密码了,例如 @AliClient(ping=30, token=token)
就不用再提供账号密码。其中这里的 ping=30
含义是每 30
秒向服务器报告一次自己在线,这样后续在网站上就可以看到自己的提交器是否还在正常工作,但是这个不是强制的,如果你不想报告自身状态,设置 ping=-1
这样的负数即可。
接下来就是提交器正式工作内容了,这里从 submitter.adapter.weibo
导入了适配器 Weibo
,顾名思义就是将微博博文适配成 webhook 规定的博文结构的工具。它的具体使用方法还请阅读源代码,非常简单易懂,通过阅读源码你也可以学习如何编写一个别的平台的适配器。后面我们从适配器中取出了第一个收集到的博文,并且发送至服务器用以测试任务 Task
,这是 webhook/model/user.go 中定义的一种请求结构,用来实现广播博文,也就是 webhook
的实现。
希望这个工具对你有用!
from qrcode import QRCode
from submitter import Client, Task
from submitter.adapter.weibo import Weibo
class AliClient(Client):
def __init__(self, uid: str = "", password: str = "", token: str = "", ping: float = -1):
super().__init__("http://gin.web-framework-m88s.1990019364850918.cn-hangzhou.fc.devsapp.net", uid, password, token, ping)
async def register(self) -> str:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.54",
"Referer": "https://www.bilibili.com",
}
resp = await self.session.get("https://passport.bilibili.com/x/passport-login/web/qrcode/generate", headers=headers)
result = resp.json()
qr = QRCode(border=0)
qr.add_data(result["data"]["url"])
qr.make()
qr.print_ascii()
input("扫描二维码完成登录后按下回车继续注册")
data = {
"uid": self.uid,
"password": self.password,
"qrcode_key": result["data"]["qrcode_key"],
}
if await self.post("/register", json=data) == "success":
return await self.token(self.uid, self.password)
@AliClient(uid="your_bilibili_uid", password="the_account_password_you_want_to_use_to_submit_blog")
async def main(self: AliClient):
token = await self.register()
self.log.info(f"Token[{token}]")
@AliClient(ping=30, token=token)
async def ali(self: AliClient):
async with Weibo(preload=["7198559139"]) as w:
for mid in w.blogs:
log = await self.test(
blog=w.blogs[mid],
task=Task(
public=True,
enable=True,
name="接收测试",
method="POST",
url="https://httpbin.org/post",
body="{{ json . }}",
README="接收所有微博",
),
)
self.log.info(log)
break
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file post-submitter-0.5.0.tar.gz
.
File metadata
- Download URL: post-submitter-0.5.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 980293ba89af92766044a91c02a34dc5c1bf91b7dc36472d5a4cc20ac5c9f6f5 |
|
MD5 | a0f8d46b1812f6e9aeb4d10c2abfad02 |
|
BLAKE2b-256 | 82c0f37fda8b54eec6f5c7291ee69eca942efd9621a561beb86a0d105fe77488 |
File details
Details for the file post_submitter-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: post_submitter-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da71d99c384c1088542ed7822d8c42e89be7da6e0ef491859070e933e736ffe9 |
|
MD5 | f7f33bed76556bae77e360a36474a36f |
|
BLAKE2b-256 | 01063b4b844651fdefa3f621abd1f0dcf9611eaf6372f91c1df5ae3227df6f16 |