Skip to main content

广西大学文件管理系统 Python SDK

Project description

gxu-wjxt — 广西大学文件管理系统 Python SDK

wjxt.gxu.edu.cn 的 Python SDK,提供 API 封装、文件下载、数据解析,支持同步和异步。

安装

pip install gxu-wjxt

详细使用指南见 GUIDE.md,包含所有 API 用法、数据类参考、最佳实践和完整示例。

开发安装:

git clone https://github.com/halfaradish/GxuWjxtClient.git
cd GxuWjxtClient
pip install -e .

项目结构

.
├── src/gxu_wjxt/
│   ├── __init__.py          # 公开 API 导出
│   ├── client.py            # 同步客户端
│   ├── async_client.py      # 异步客户端
│   ├── crawler.py           # 文件下载爬虫
│   ├── config.py            # 配置管理
│   ├── exceptions.py        # 异常层次
│   ├── types.py             # 数据类
│   ├── _base.py             # 内部工具函数
│   └── cli.py               # CLI 入口
├── client.py                # 向后兼容 shim
├── crawler.py               # 向后兼容 shim
├── demo.py                  # 演示脚本
├── pyproject.toml           # 打包配置
├── api.md                   # API 接口文档
├── config.example.json      # 配置文件模板
└── README.md

快速开始

1. 配置凭证(三选一)

方式 A — 配置文件:

cp config.example.json config.json
# 编辑 config.json
{"username": "your_student_id", "password": "your_password"}

方式 B — 环境变量:

export WJXT_USERNAME=your_student_id
export WJXT_PASSWORD=your_password

方式 C — 直接传参(推荐):

from gxu_wjxt import WjxtClient
client = WjxtClient(username="学号", password="密码")

2. 运行演示

python demo.py

使用方式

同步客户端

from gxu_wjxt import WjxtClient

with WjxtClient(username="学号", password="密码") as client:
    client.login()

    # 获取部门列表
    depts = client.get_departments()
    for d in depts:
        print(f"[{d.id}] {d.tn_decoded}")

    # 获取分页文件列表
    files, page_info = client.get_file_list_structured(page=1)
    print(f"第{page_info.current_page}/{page_info.total_pages}页, "
          f"共{page_info.total_items}条")

    # 惰性遍历全部文件(自动翻页)
    for f in client.iter_files(max_pages=5):
        print(f"[{f.index}] {f.department}: {f.title} ({f.date})")

    # 获取文件详情
    detail = client.get_file_detail(file_id=61424)
    for att in detail.download_urls:
        print(f"  附件: {att.filename} -> {att.url}")

    # 下载文件
    path = client.download_file(file_id=61424, save_dir="./downloads")

    # 电话簿
    contacts = client.parse_phone_list()
    for c in contacts:
        print(f"{c.name}: {c.phone}")

    client.logout()

异步客户端

import asyncio
from gxu_wjxt import AsyncWjxtClient

async def main():
    async with AsyncWjxtClient(username="学号", password="密码") as client:
        await client.login()

        # 异步遍历文件列表
        async for f in client.iter_files(max_pages=3):
            print(f.title)

        await client.logout()

asyncio.run(main())

文件爬虫

from gxu_wjxt import WjxtClient, FileCrawler

client = WjxtClient(username="学号", password="密码")
client.login()

crawler = FileCrawler(client, download_dir="./downloads", workers=3)

# 爬取全部(指定最大页数、仅未读)
stats = crawler.crawl_all(max_pages=5, unread_only=True)

# 按部门爬取
stats = crawler.crawl_department(dept_id=16, dept_name="学工部")

# 遍历所有部门
stats = crawler.crawl_all_departments(max_pages=3)

# 控制提前停止:连续 N 页无匹配记录时自动停止(默认 3,设 0 禁用)
stats = crawler.crawl_all(unread_only=True, max_empty_pages=5)

print(f"下载: {stats.downloaded}, 跳过: {stats.skipped}, 失败: {stats.failed}")
client.close()

CLI 命令行

# pip install 后
gxu-wjxt -o ./downloads -d 16 -n 3 --workers 3

# 或
python -m gxu_wjxt.cli -o ./downloads -d all --dry-run

# 兼容旧用法
python crawler.py -o ./downloads --after 2026-03-01
参数 说明
-o, --output 下载目录(默认 ./downloads
-d, --dept 部门 ID 或 all
-n, --max-pages 最多爬取页数
--after 日期过滤 YYYY-MM-DD
--unread-only 仅下载未读文件
--workers 并发线程数(默认 1)
--max-empty-pages 连续 N 页无匹配时停止(默认 3,0 禁用)
--dry-run 预览模式
-u, --username 用户名
-p, --password 密码

配置优先级

构造函数参数 > 环境变量 > 配置文件 > 默认值
from gxu_wjxt import WjxtConfig

# 环境变量
config = WjxtConfig.from_env()

# 配置文件
config = WjxtConfig.from_file("config.json")

# 自定义
config = WjxtConfig(
    base_url="https://wjxt.gxu.edu.cn",
    myteip="172.28.222.133--2",
    timeout=30.0,
    retry_count=3,
    download_dir="./my_downloads",
)

输出目录结构

downloads/
├── download_history.json          # 下载记录(断点续爬)
├── 学工部(处)、武装部(就业中心)/
│   └── 2026-05-16_关于xxx通报/
│       ├── 2026-05-16_关于xxx通报.html    # 文件正文
│       ├── 附件1.doc
│       └── 附件2.xlsx
└── 校团委/
    └── ...

API 覆盖

共 19 个端点,覆盖认证、文件管理、搜索、用户、电话簿、业务办理。详见 api.md

模块 端点
认证 Login.aspx, default.aspx, Exiting.aspx
主页/导航 Wjxt_UI/default.aspx, WebUI.aspx?id=2/4
文件管理 PageList.aspx, qstwj.aspx, showfile.aspx, Right.aspx
文件下载 /filezip/uploadfile/{year}/{month}/{filename}
搜索 search.aspx, filesearch.aspx
用户管理 userEditPss.aspx
电话簿 phoneList.aspx
业务办理 business/business_*.aspx

依赖

注意事项

  • 搜索功能当前返回"系统维护中",非 SDK 问题
  • 大量文件列表中约 50% 为纯文本公告,无附件可下载
  • 默认 0.5 秒翻页间隔,避免对服务器造成压力
  • config.json 包含敏感信息,已加入 .gitignore
  • 客户端支持 with 语句自动关闭连接

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

gxu_wjxt-1.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

gxu_wjxt-1.0.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file gxu_wjxt-1.0.1.tar.gz.

File metadata

  • Download URL: gxu_wjxt-1.0.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for gxu_wjxt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 67674fc813a92827f708c6f6bcf42a2fd5c7aadd31b75b538346b0382b9ba8bc
MD5 84d70df5026bd0f720c6413ee0f553db
BLAKE2b-256 841ff4200d6d9832e4f1dfc857cc9f2c47bd869b4bdd971e160685c4aa010cdd

See more details on using hashes here.

File details

Details for the file gxu_wjxt-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gxu_wjxt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for gxu_wjxt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29bb3091c96c719207b188553f42da796d09c7563099d717c3685c90f4ab6eb0
MD5 76dab3cc3714b6c0da518bf5658625cd
BLAKE2b-256 1146c1fc80f12d04be8401aaf6d8798cfe68ac735703d859f7a56180a01e78f3

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