Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
*.pyc
*.egg-info/
.venv/
.DS_Store
5 changes: 4 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ version = "0.2.0"
description = "Python SDK for the WeChat iLink Bot API"
readme = "README.md"
requires-python = ">=3.11"
dependencies = ["aiohttp"]
dependencies = [
"aiohttp",
"qrcode>=8.2",
]
license = { text = "MIT" }

[tool.setuptools.packages.find]
Expand Down
29 changes: 27 additions & 2 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions python/weixin_bot/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ def _clear_credentials_sync(token_path: str | Path | None) -> None:


def _print_qr_instructions(url: str) -> None:
_log("在微信中打开以下链接完成登录:")
sys.stderr.write(f"{url}\n")
import qrcode

try:
qr = qrcode.QRCode(border=1)
qr.add_data(url)
qr.make(fit=True)
qr.print_ascii(tty=False)
print("请使用微信扫描上方二维码完成登录。")
except Exception:
_log("在微信中打开以下链接完成登录:")
sys.stderr.write(f"{url}\n")


async def load_credentials(token_path: str | Path | None = None) -> Credentials | None:
Expand Down
11 changes: 2 additions & 9 deletions python/weixin_bot/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
from dataclasses import dataclass
from datetime import datetime
from enum import IntEnum
from typing import Literal, TypedDict
from typing import TYPE_CHECKING, Literal, TypedDict

try:
if TYPE_CHECKING:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

To fix the issues that typecheckers can't correctly detect MessageItem fields as NotRequired.

from typing import NotRequired, TypeAlias
except ImportError: # pragma: no cover - Python < 3.11 runtime compatibility
class _NotRequiredCompat:
def __class_getitem__(cls, item):
return item

NotRequired = _NotRequiredCompat # type: ignore[assignment]
TypeAlias = object # type: ignore[assignment]


class MessageType(IntEnum):
Expand Down