LTWS 协议解析器
Project description
LTWS 解析器
用于解析和验证 LTWS (Little Tree Wallpaper Source) 协议 v3.0 的 Python 库。
特性
- 🚀 支持解析
.ltws文件(不压缩的 TAR 格式) - 📝 支持解析目录结构的壁纸源
- ✅ 完整的配置验证
- 🛠️ 提供打包工具
- 🔧 变量替换引擎
- 📊 详细的错误报告
安装
pip install ltws-parser
快速开始
1. 解析壁纸源
python
from ltws import LTWSParser
# 创建解析器
parser = LTWSParser()
# 解析 .ltws 文件
source = parser.parse("my_wallpaper_source.ltws")
# 或解析目录
source = parser.parse("my_wallpaper_source/")
# 使用壁纸源
print(f"名称: {source.name}")
print(f"版本: {source.version}")
print(f"API数量: {len(source.apis)}")
2. 验证壁纸源
python
from ltws import LTWSValidator
# 创建验证器
validator = LTWSValidator()
# 验证壁纸源
is_valid = validator.validate_source(source)
# 获取验证报告
report = validator.get_validation_report()
print(f"验证通过: {report['passed']}")
print(f"错误: {report['errors']}")
print(f"警告: {report['warnings']}")
3. 使用变量引擎
python
from ltws import VariableEngine
# 创建变量引擎
engine = VariableEngine()
# 替换变量
template = "https://api.example.com/wallpapers?date={{date_iso}}&random={{random_string:8}}"
result = engine.replace(template)
print(result) # https://api.example.com/wallpapers?date=2024-01-15&random=abc123de
4. 打包壁纸源
python
from ltws import LTWSPackager
# 创建打包工具
packager = LTWSPackager()
# 打包目录为 .ltws 文件
packager.pack("my_wallpaper_source/", "output.ltws")
命令行工具
安装后可以使用 ltws 命令行工具:
bash
# 验证壁纸源
ltws validate my_wallpaper_source/
# 打包壁纸源
ltws pack my_wallpaper_source/ output.ltws
# 查看 .ltws 文件信息
ltws inspect output.ltws
# 测试壁纸源
ltws test my_wallpaper_source/
API 参考
LTWSParser
主要解析器类,用于解析壁纸源。
python
parser = LTWSParser(strict=True)
source = parser.parse(path)
errors = parser.get_errors()
warnings = parser.get_warnings()
LTWSValidator
验证器类,用于验证壁纸源配置。
python
validator = LTWSValidator()
is_valid = validator.validate_source(source)
report = validator.get_validation_report()
LTWSPackager
打包工具类,用于创建 .ltws 文件。
python
packager = LTWSPackager(strict=True)
packager.pack(source_dir, output_file, overwrite=False)
VariableEngine
变量替换引擎,支持内置变量和自定义变量。
python
engine = VariableEngine()
result = engine.replace(template, context)
数据模型
库提供完整的数据模型:
WallpaperSource: 壁纸源完整对象WallpaperAPI: API 定义Category: 分类定义Parameter: 参数定义RequestConfig: 请求配置FieldMapping: 字段映射
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
ltws_parser-1.1.3.tar.gz
(18.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ltws_parser-1.1.3.tar.gz.
File metadata
- Download URL: ltws_parser-1.1.3.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e5bbb511fb0c7a3f93b9fb1f754721db910449f7cf636e9cd128195fbad1f3d
|
|
| MD5 |
dfbe3c8d092b9ddec6495d1974f54546
|
|
| BLAKE2b-256 |
197f093e2b4d2821591bd4bbe44b75ff81e913cdf772e24adec6040c80b1d2b1
|
File details
Details for the file ltws_parser-1.1.3-py3-none-any.whl.
File metadata
- Download URL: ltws_parser-1.1.3-py3-none-any.whl
- Upload date:
- Size: 21.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de97414b720ee6cc9e3d29d260d3a08fe2b3e4babc0b57085b45b6bbad098701
|
|
| MD5 |
1ed53b75f1fa0c27b0642168deb4c4cd
|
|
| BLAKE2b-256 |
2e5d271e054d9c392368431e20fffd1ce5c2e28c2e2f4c44e3b3ba2d2b8ec683
|