Skip to main content

Shared library for TiebaMeow services

Project description

tiebameow

License PyPI Python CI codecov

Tiebameow 项目通用模块

简介

tiebameow 是在 Tiebameow 项目内使用的通用模块,提供了通用的数据模型、序列化/反序列化工具、日志模块以及辅助函数。

目录

  • client: 包含增强的 aiotieba.Clienthttpx 客户端。
  • models: 定义了通用数据交换模型和 ORM 数据模型。
  • parser: 提供解析和处理 aiotieba 数据和审查规则的解析器。
  • renderer: 提供将 DTO 内容或简单文本渲染为图片的功能。
  • schemas: 定义了各种数据片段与审查规则的 Pydantic 模型。
  • serializer: 提供数据交换模型的序列化和反序列化方法。
  • utils: 包含通用日志模块和一些辅助函数和工具类。

安装

推荐使用 uv 进行环境管理和依赖安装。

仅安装基础功能:

uv add tiebameow

如需使用数据库模型,请安装 orm 额外依赖:

uv add tiebameow[orm]

如需使用渲染功能,请安装 renderer 额外依赖和 Playwright 所需浏览器:

uv add tiebameow[renderer]
uv run playwright install chromium-headless-shell

基本用法

更多用法请参阅源码。

Client

Tieba Client

from tiebameow.client import Client
async with Client() as client:
    user_info = await client.get_user_info("some_username")

HTTP Client

from tiebameow.client import HTTPXClient
response = await HTTPXClient.get("https://example.com")

Parser

数据转换器

aiotieba 对象转换为通用数据交换模型:

from tiebameow.parser import convert_aiotieba_thread
from tiebameow.client import Client
async with Client() as client:
    threads = await client.get_threads("some_tieba")
    for thread in threads:
        converted_thread = convert_aiotieba_thread(thread)

规则引擎解析器

以 DSL 或 CNL 模式解析规则和动作:

from tiebameow.parser import RuleEngineParser
parser = RuleEngineParser()
rule_node = parser.parse_rule("(title contains 'A' AND title contains 'B') OR NOT title contains 'C'")
actions = parser.parse_actions("DO: delete(reason='spam content'), ban(days=1)")

Renderer

from tiebameow.renderer import Renderer
async with Renderer() as renderer:
    image_bytes = await renderer.text_to_image("Hello, World!")

开发指南

欢迎贡献代码,请确保遵循项目的编码规范,并在提交前运行 pre-commit hooks:

uv sync --dev
pre-commit install
pre-commit run --all-files

有关详细信息,请参阅 CONTRIBUTING.md 文件。

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

tiebameow-0.2.12.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiebameow-0.2.12-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file tiebameow-0.2.12.tar.gz.

File metadata

  • Download URL: tiebameow-0.2.12.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tiebameow-0.2.12.tar.gz
Algorithm Hash digest
SHA256 9afc5e1e1c4795057d96ab6ad1736ec93d31f6f50de85d41f44ae21ab4b37582
MD5 08d4c86d712d2fb9ae3950f7d7bf656c
BLAKE2b-256 c5add95fdbad46cdd0bdc1e89d11a0dda2771528170685388a437dbe390247f4

See more details on using hashes here.

File details

Details for the file tiebameow-0.2.12-py3-none-any.whl.

File metadata

  • Download URL: tiebameow-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tiebameow-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 19792c639d105da33dc80a8cfa5f6cfc6f2206012c712d53be94336aca16cf4b
MD5 0b6af116def247b3be43e6d83ec83e50
BLAKE2b-256 2b32a54f7f429416ea9ee7cab9848db4ac14718c22907a8f86290dfb8c8da881

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page