-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ 添加新的订阅平台 Twitter #193
base: main
Are you sure you want to change the base?
✨ 添加新的订阅平台 Twitter #193
Conversation
FrozenYogurtPuff
commented
Feb 10, 2023
- 添加订阅平台 Twitter
- 修改了 Readme
Codecov ReportBase: 79.68% // Head: 80.84% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #193 +/- ##
==========================================
+ Coverage 79.68% 80.84% +1.15%
==========================================
Files 46 47 +1
Lines 2722 2965 +243
==========================================
+ Hits 2169 2397 +228
- Misses 553 568 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大概看了一下,看起来用 bison ScheduleConfig 向 Platform 中注入 httpx Client 的方式也可以完成代码中实现的逻辑,但是不能实现失败后reset session然后重新请求的功能,我也得想想这个怎么做
_authorization = "Bearer AAAAAAAAAAAAAAAAAAAAAPYXBAAAAAAACLXUNDekMxqa8h%2F40K4moUkGsoc%3DTYfbDKbT3jJPCEVnMYqilB28NHfOPqkca3qaAxGfsyKCs0wRbw" | ||
_header: dict[str, str] = { | ||
"authorization": _authorization, | ||
"x-twitter-client-language": "en", | ||
"x-twitter-active-user": "yes", | ||
"Referer": "https://twitter.com/", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块如果是参考了rsshub的相关代码,这里最好贴上rsshub代码的地址(如果有条件的话最好猜一猜这一串 Bearer Token 是干嘛的)
schedule_setting = {"seconds": 30} | ||
|
||
|
||
class TwitterUtils: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类主要包含了两个功能:
- 提供 Twitter 请求时的 Header 和 cookies 能数据
- 产生请求的 params, 解析返回的内容
前者可以放到 ScheduleConfig 中,重载里面的相关函数可以自定义实例化 Twitter 类使用传入的 client,详情看 bilibili 的 schedule conf
).raise_for_status() | ||
|
||
@classmethod | ||
async def got( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got 这个函数在 rsshub 代码的语境中有明确的定于,但是在 bison 的代码中就有点不明就里,所以这个函数名最好改改
当然整体完成度已经很高了 |
https://www.python-httpx.org/advanced/#event-hooks 或许可行?在 Response 中添加一个 Event Hook,若 403 则重新配置 session。 |
不太行,稍微看了一下 httpx 的源代码,event_hooks 里只能执行同步的代码,不能执行异步的逻辑。 |