Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

FrozenYogurtPuff
Copy link

  • 添加订阅平台 Twitter
  • 修改了 Readme

@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Base: 79.68% // Head: 80.84% // Increases project coverage by +1.15% 🎉

Coverage data is based on head (7b10da2) compared to base (cce34ab).
Patch coverage: 94.73% of modified lines in pull request are covered.

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     
Flag Coverage Δ
smoke-test 80.84% <94.73%> (+1.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/plugins/nonebot_bison/platform/twitter.py 94.73% <94.73%> (ø)
src/plugins/nonebot_bison/send.py 79.36% <0.00%> (-2.12%) ⬇️
src/plugins/nonebot_bison/scheduler/aps.py 100.00% <0.00%> (+5.55%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@felinae98 felinae98 left a 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然后重新请求的功能,我也得想想这个怎么做

Comment on lines +25 to +31
_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/",
}
Copy link
Collaborator

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个类主要包含了两个功能:

  1. 提供 Twitter 请求时的 Header 和 cookies 能数据
  2. 产生请求的 params, 解析返回的内容

前者可以放到 ScheduleConfig 中,重载里面的相关函数可以自定义实例化 Twitter 类使用传入的 client,详情看 bilibili 的 schedule conf

).raise_for_status()

@classmethod
async def got(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got 这个函数在 rsshub 代码的语境中有明确的定于,但是在 bison 的代码中就有点不明就里,所以这个函数名最好改改

@felinae98
Copy link
Collaborator

当然整体完成度已经很高了

@FrozenYogurtPuff
Copy link
Author

大概看了一下,看起来用 bison ScheduleConfig 向 Platform 中注入 httpx Client 的方式也可以完成代码中实现的逻辑,但是不能实现失败后reset session然后重新请求的功能,我也得想想这个怎么做

https://www.python-httpx.org/advanced/#event-hooks 或许可行?在 Response 中添加一个 Event Hook,若 403 则重新配置 session。

@felinae98
Copy link
Collaborator

不太行,稍微看了一下 httpx 的源代码,event_hooks 里只能执行同步的代码,不能执行异步的逻辑。
所以要不在发现 credentials 过期的时候抛出一个异常,然后执行 ScheduleConfig 中的某个函数(暂定refresh_client?),再重新访问

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants