360 Secure SkillHub
360 安全技能中心

Elective

围绕 elective crate(北大选课网命令行客户端)说明其架构、源码文件与命令:支持 IAAA SSO 登录、单/双学位会话、查看与浏览课程、设置自动选课目标并启动轮询循环,以及配置 manual、UTool、TTShiTu、Yunma 等验证码识别后端。会话持久化到本地配置目录,凭据经密钥环/环境变量/交互读取;不含课表统合查看能力。

wjsoj
wjsoj
热度 47.89
最近更新 2026-05-18 11:40:57
分类:开发依赖:代码执行 / 读写文件 / 第三方 API应用场景:代码生成 / 调试排错 / API 集成 / 自动化脚本 ...

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add pku-elective
Metadata
name
elective
description
PKU Course Selection (选课网) CLI tool built in Rust. Use this skill when working on the elective crate, debugging elective commands, adding features, or when the user mentions 选课, elective, course selection, auto-enroll, CAPTCHA solving, dual-degree, or elective.pku.edu.cn. Also use when dealing with CAPTCHA recognition backends (utool/ttshitu/yunma), automated course enrollment loops, or elective SSO callback. **NOT for general course schedule / 课表 / 这学期上什么课 questions — use the `treehole` skill (`treehole course`) instead, which gives a unified weekly grid with 主修+辅修+双学位. The `elective show` command only sees one program at a time and easily misses courses from the other program for dual-degree students.**
version
2.0.0

Elective - 北大选课网 CLI

A CLI client for PKU's course selection system with auto-enrollment automation.

Architecture

  • Crate location: crates/elective/
  • Auth flow: IAAA SSO (app_id="elective") → elective SSO endpoint callback
  • API: HTML scraping + CAPTCHA handling (base64 image recognition)
  • Automation: Polling loop for auto-enrollment with configurable interval

Key Source Files

  • src/main.rs — Clap CLI with subcommands
  • src/commands.rs — Command implementations including auto-enroll loop
  • src/api.rs — HTML scraping, CAPTCHA image extraction
  • src/display.rs — Terminal output formatting
  • src/client.rs — reqwest client builders

CLI Commands

Command Alias Function
login IAAA login (supports --dual for dual-degree students)
logout / status Session management
show View current course selections
list ls Browse available courses for add/drop
set Add a course to auto-enroll target list
unset Remove from auto-enroll targets
config-captcha Configure CAPTCHA solver backend
launch Start auto-enrollment polling loop
otp TOTP 2FA management

CAPTCHA Backends

The config-captcha command supports multiple recognition backends:

  • manual — Display CAPTCHA image, user inputs answer
  • utool — UTool OCR service
  • ttshitu — TTShiTu recognition API
  • yunma — Yunma recognition API

Auto-Login for AI Agents

# Check session status
info-auth check

# Auto-login (reads credentials from OS keyring, no password needed)
elective login -p                  # single degree
elective login -p --dual major     # dual degree - major
elective login -p --dual minor     # dual degree - minor

Note: Dual-degree students MUST specify --dual major or --dual minor, otherwise login will fail with an error.

Development Notes

  • Auto-enrollment loop: configurable check interval (default 15s), polls for open slots
  • Dual-degree students use --dual flag at login for separate session
  • CAPTCHA images are base64-encoded, decoded and sent to recognition backend
  • All user-facing strings in Chinese
  • Error handling: anyhow::Result with .context("中文描述")
  • Session persisted to ~/.config/info/elective/
  • Credentials resolved via info_common::credential (keyring → env → interactive)