How ruoqian04/pkuautoelective works
Project type and purpose
• PKUAutoElective is a Python-based CLI automation tool (“open-source tool”) whose purpose is to automate the “补退选” phase of Peking University’s course-selection website.
• It logs into the IAAA login portal, navigates to the elective portal, solves captchas via a trained CNN model, applies user-defined selection rules, submits course-add/drop requests in a loop, and (optionally) exposes a monitoring HTTP interface via Flask.
File structure
• Top-level files:
• Docker definitions (Docker/latest.Dockerfile, monitor.Dockerfile) & DOCKER.md
• Config sample (config.sample.ini), requirements.txt, model weights (model/cnn.*.pt)
• Entry point: main.py
• Package directory autoelective/:
• cli.py – parses command-line args
• client.py – HTTP clients for IAAA and elective site
• captcha/ – CNN model loader & image processor/recognizer
• parser.py – HTML parsing (lxml)
• loop.py – main selection loop orchestrator
• monitor.py – Flask server exposing runtime stats
• hook.py, rule.py – extensibility points for user-defined rules
• config.py, const.py, environ.py – configuration & constants
• logger.py, utils.py, exceptions.py – support utilities
• Test directory: test/test_cnn.py validates the captcha module
• Deployment/Dev: Docker folder + GitHub workflows
README for additional insights
• Core sequence:
1. Read config.ini
2. Login to IAAA (with random User-Agent)
3. Navigate to elective page, fetch captcha image
4. Recognize captcha via CNN model (PyTorch + OpenCV + Pillow)
5. Build and submit POST request to add/drop courses
6. Loop with configurable interval, apply mutex/delay rules
7. Optionally, spawn a Flask monitor on a given port
• Extensibility: custom User-Agent pool, rule definitions, multi-process support
• Rectangles for internal modules
• Annotations: loop interval, thread vs. process, retry logic