Skip to content

Commit

Permalink
docs: login_with_qrcode_term
Browse files Browse the repository at this point in the history
  • Loading branch information
z0z0r4 committed Jul 8, 2023
1 parent 71d27fe commit b05c1d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
19 changes: 0 additions & 19 deletions bilibili_api/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,6 @@ def parse_credential_url(events: dict) -> Credential:
buvid3=buvid3,
dedeuserid=dedeuserid,
ac_time_value=ac_time_value)

def anylize_event_data(events: dict) -> Union[Credential, int]:
"""
成功则返回 Credential 类,失败则返回错误代码
"""
# {'url': '', 'refresh_token': '', 'timestamp': 0, 'code': 86101, 'message': '未扫码'}
# {'url': '', 'refresh_token': '', 'timestamp': 0, 'code': 86090, 'message': '二维码已扫码未确认'}
# {'url': 'https://passport.biligame.com/x/passport-login/web/crossDomain?DedeUserID=x&DedeUserID__ckMd5=x&Expires=x&SESSDATA=x&bili_jct=x&gourl=x', 'refresh_token': 'x', 'timestamp': 1683903305723, 'code': 0, 'message': ''}
if "code" in events.keys() and events["code"] == 0:
if result == 86101:
log.configure(text="请扫描二维码↑", fg="red", font=big_font)
elif result == 86090:
log.configure(text="点下确认啊!", fg="orange", font=big_font)
elif result == 86038:
raise LoginError("二维码过期,请扫新二维码!")
elif events["data"]["code"] == 0:
return parse_credential_url(events)
elif "code" in events.keys():
raise LoginError(events["message"])

def make_qrcode(url) -> str:
qr = qrcode.QRCode()
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
``` python
from bilibili_api import login, user, sync
print("请登录:")
credential = login.login_with_qrcode()
credential = login.login_with_qrcode_term() # 在终端扫描二维码登录
# credential = login.login_with_qrcode() # 使用窗口显示二维码登录
try:
credential.raise_for_no_bili_jct() # 判断是否成功
credential.raise_for_no_sessdata() # 判断是否成功
Expand Down
12 changes: 11 additions & 1 deletion docs/modules/login.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from bilibili_api import login
---
**注意:**

`linux` 的小伙伴在使用 `login_with_qrcode` 时先装一下 `python3-tk` 吧。
建议 `linux` 的用户使用 `login_with_qrcode_term` 通过终端扫码登录,或者在使用 `login_with_qrcode` 时先装一下 `python3-tk` 吧。

``` bash
$ sudo apt-get install python3-tk
Expand Down Expand Up @@ -79,6 +79,14 @@ $ sudo apt-get install python3-tk

---

## def login_with_qrcode_term()

**推荐方式** 扫描终端二维码登录。

**Returns:** Credential 凭据类。

---

## def login_with_qrcode()

| name | type | description |
Expand All @@ -91,6 +99,8 @@ $ sudo apt-get install python3-tk

**Returns:** Credential 凭据类。

---

## def login_with_password()

| name | type | description |
Expand Down

0 comments on commit b05c1d4

Please sign in to comment.