Skip to main content

USST dorm electricity fees watcher and notifier

Project description

usst-e-fees

上海理工大学宿舍电费提醒工具。

它会定时查看宿舍照明电费和空调电费。余额低于你设置的金额时,会通过 Bark、Gotify、邮件或控制台提醒你。

经过测试,学校宿舍电费接口目前只能在校内网络访问。请在校园网、宿舍网络、校内服务器,或可以访问校内资源的 VPN 环境运行。

能做什么

  • 查看当前宿舍电费和电量。
  • 照明电费、空调电费可以分别设置提醒金额。
  • 余额不足时自动提醒。
  • 支持 Bark 手机推送。
  • 支持多个账号。
  • 会自动避免短时间内重复提醒。

安装

推荐使用 uv

uv tool install usst-e-fees

也可以使用 pip

pip install usst-e-fees

安装后检查命令是否可用:

usst-e-fees --help
usst-e-fees version

第一次使用

1. 生成配置文件

usst-e-fees init-config
usst-e-fees where

where 会显示配置文件位置。Windows 常见位置是:

%LOCALAPPDATA%\usst-e-fees\config.yaml

2. 配置提醒金额

打开配置文件,找到:

thresholds:
  lighting_money: 20.0
  aircon_money: 20.0

含义:

  • lighting_money:照明电费低于多少元时提醒。
  • aircon_money:空调电费低于多少元时提醒。

3. 配置 Bark 推送

如果你使用 Bark,打开配置文件,填入你的 Bark key:

notify:
  bark:
    enabled: true
    server: https://api.day.app
    key: 你的 Bark key
    group: USST E Fees

测试通知:

usst-e-fees notify-test

4. 导入登录信息

工具需要从已登录的 WeLink/宿舍电费页面请求中导入登录信息。

用 Loon 抓包后,建议导入三份信息:

  • 宿舍电费查询请求。
  • WeLink 授权刷新请求,路径里通常包含 ssoauth/v1/code
  • WeLink 登录续期请求 refresh/LoginRegrequest_body_raw

导入示例:

usst-e-fees auth-import "D:\path\to\dorm_request_header_raw.txt"
usst-e-fees auth-import "D:\path\to\welink_sso_request_header_raw.txt"
usst-e-fees auth-import-loginreg "D:\path\to\loginreg_request_body_raw.txt"

导入后测试刷新登录信息:

usst-e-fees auth-refresh

这样配置后,工具会优先自动续期 WeLink 登录,再自动换新的授权码,通常可以明显减少后续重新抓包次数。

如果以后仍然提示登录失效,再重新抓包并再次执行上面的导入命令。

查询和监控

查询一次

usst-e-fees poll-once

这个命令只显示余额,不会发送低余额提醒。

查询一次并提醒

usst-e-fees poll-once --notify

如果余额低于阈值,会发送提醒。

持续监控

usst-e-fees watch

watch 会自动发送提醒,不需要加 --notify

监控所有账号

usst-e-fees watch --all

watch --all 也会自动发送提醒。它会监控配置文件中所有 enabled: true 的账号。

防重复提醒

默认情况下,同一账号的同一种电费 6 小时内最多提醒一次。

例如空调电费一直低于阈值,工具不会每次检查都推送;等过了冷却时间才会再次提醒。余额恢复到阈值以上后,低余额状态会被清除。

多账号

可以在配置文件里添加多个账号:

accounts:
  - id: main
    name: 我的账号
    enabled: true
    session_file: sessions/main.json

  - id: roommate
    name: 室友
    enabled: true
    session_file: sessions/roommate.json

给不同账号导入登录信息:

usst-e-fees auth-import "D:\path\to\main_request_header_raw.txt" --account main
usst-e-fees auth-import "D:\path\to\roommate_request_header_raw.txt" --account roommate

监控所有账号:

usst-e-fees watch --all

常见问题

watch --all 是否自带通知?

是。watchwatch --all 都会在低于阈值时自动通知。

poll-once 会不会通知?

默认不会。要通知请使用:

usst-e-fees poll-once --notify

为什么校外运行失败?

当前学校接口经测试仅限校内网络访问。校外运行请先确认当前机器可以访问校内宿舍管理系统。

为什么过一段时间提示登录失效?

登录信息会过期。0.1.1 起已经支持用 refresh/LoginReg 自动续期,所以维护频率会比以前低很多;如果 WeLink 的长期登录信息本身也失效了,再重新用 Loon 抓包并重新导入即可。

联系方式

问题反馈:a.oxidizing172@aleeas.com

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

usst_e_fees-0.1.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

usst_e_fees-0.1.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file usst_e_fees-0.1.1.tar.gz.

File metadata

  • Download URL: usst_e_fees-0.1.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for usst_e_fees-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0dcc960d6f1f2d560f0fe41908c41ef1d6249ff213958f958e9794312775a995
MD5 69b6f962fa5d0c50c5db14ce55b9133c
BLAKE2b-256 4b836e2323a23a2d8604b537b2458856b420a7da4adc10983c86b2a0382db4b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for usst_e_fees-0.1.1.tar.gz:

Publisher: publish.yml on Nitmi/usst-e-fees

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usst_e_fees-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: usst_e_fees-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for usst_e_fees-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69c3842bd068915a090790171fe73f2e85092cd002274f85e1385a2ac58cc26d
MD5 f067551817a3665d343dd8dff82a0159
BLAKE2b-256 b79ad4782a7f37061aea050e2edbdf41c1d1eee3b9a402cee97e215c46261f25

See more details on using hashes here.

Provenance

The following attestation bundles were made for usst_e_fees-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Nitmi/usst-e-fees

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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