rhul-attendance-bot 0.1.48__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- RHUL_attendance_bot.py +580 -0
- app_paths.py +74 -0
- auto_login.py +739 -0
- discord_broadcast.py +70 -0
- display_manager.py +274 -0
- fetch_ics.py +103 -0
- local_2fa.py +31 -0
- rhul_attendance_bot-0.1.48.dist-info/METADATA +234 -0
- rhul_attendance_bot-0.1.48.dist-info/RECORD +14 -0
- rhul_attendance_bot-0.1.48.dist-info/WHEEL +5 -0
- rhul_attendance_bot-0.1.48.dist-info/entry_points.txt +2 -0
- rhul_attendance_bot-0.1.48.dist-info/licenses/LICENSE +22 -0
- rhul_attendance_bot-0.1.48.dist-info/top_level.txt +8 -0
- update.py +67 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rhul-attendance-bot
|
|
3
|
+
Version: 0.1.48
|
|
4
|
+
Summary: RHUL attendance automation bot
|
|
5
|
+
Author: PandaQuQ
|
|
6
|
+
License:
|
|
7
|
+
MIT License
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
[Additional Clause]
|
|
19
|
+
For any commercial use, attribution to the original author (PandaQuQ) is required.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: Repository, https://github.com/PandaQuQ/RHUL_attendance_bot
|
|
30
|
+
Keywords: automation,attendance,selenium,rhul
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
33
|
+
Classifier: Operating System :: OS Independent
|
|
34
|
+
Requires-Python: >=3.9
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE
|
|
37
|
+
Requires-Dist: ics
|
|
38
|
+
Requires-Dist: rich
|
|
39
|
+
Requires-Dist: selenium
|
|
40
|
+
Requires-Dist: webdriver-manager
|
|
41
|
+
Requires-Dist: pynput
|
|
42
|
+
Requires-Dist: ntplib
|
|
43
|
+
Requires-Dist: pyotp
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# RHUL Attendance Bot
|
|
47
|
+
[中文](https://github.com/PandaQuQ/RHUL_attendance_bot/blob/main/README_CN.md)
|
|
48
|
+
---
|
|
49
|
+

|
|
50
|
+

|
|
51
|
+

|
|
52
|
+

|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
The RHUL Attendance Bot automates attendance marking for Royal Holloway students by using web automation. The script checks your calendar events, triggers attendance based on specified conditions, and provides real-time logging using Rich library for better visualization.
|
|
56
|
+

|
|
57
|
+

|
|
58
|
+
## Features
|
|
59
|
+
|
|
60
|
+
- **Automated Attendance**: Automatically opens the attendance page and marks your attendance based on your calendar events.
|
|
61
|
+
- **Manual Trigger**: Allows manual attendance marking via keyboard shortcuts.
|
|
62
|
+
- **Real-Time Logging**: Displays logs using Rich library for a better visual experience.
|
|
63
|
+
- **Environment and Dependency Checks**: Ensures the script is run in the proper environment and all dependencies are installed.
|
|
64
|
+
- **System Time Synchronization Check**: Checks if the system time is synchronized with the NTP server.
|
|
65
|
+
- **Auto-Update Feature**: Detects script updates and prompts the user to update.
|
|
66
|
+
- **Auto Login with 2FA**: Handles Microsoft login, switches to verification code, and auto-fills TOTP from your saved secret.
|
|
67
|
+
- **Automatic Timetable Download**: On first run, automatically fetches your ICS timetable into the `ics/` folder—no manual download needed.
|
|
68
|
+
- **Discord Webhook Notifications (optional)**: Sends start/stop, login success, and attendance success messages with your profile name when a webhook URL is configured.
|
|
69
|
+
|
|
70
|
+
## Prerequisites
|
|
71
|
+
|
|
72
|
+
1. **Python 3.9 or above**: Ensure that Python is installed. If not, download and install it from [python.org](https://www.python.org/downloads/).
|
|
73
|
+
2. **Google Chrome Browser**: The script uses Chrome for web automation. Make sure it is installed.
|
|
74
|
+
3. **Virtual Environment (Recommended)**: Run the script inside a Python virtual environment to avoid dependency conflicts.
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
Install Google Chrome if you don't have it yet: [download page](https://www.google.com/chrome/) (macOS users can also `brew install --cask google-chrome`).
|
|
79
|
+
|
|
80
|
+
### Step 1: Clone the Repository
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git clone https://github.com/PandaQuQ/RHUL_attendance_bot.git
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Step 2: Navigate to the Project Directory
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
cd RHUL_attendance_bot
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Step 3: Set Up a Virtual Environment (Recommended)
|
|
93
|
+
|
|
94
|
+
#### On Windows:
|
|
95
|
+
```bash
|
|
96
|
+
python -m venv venv
|
|
97
|
+
venv\Scripts\activate
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### On macOS/Linux:
|
|
101
|
+
```bash
|
|
102
|
+
python3 -m venv venv
|
|
103
|
+
source venv/bin/activate
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Step 4: Install Dependencies
|
|
107
|
+
|
|
108
|
+
#### Option A: Install from PyPI (recommended)
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install rhul-attendance-bot
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Option B: Install from source
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install -r requirements.txt
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Step 5: (Optional) Prepare ICS Manually
|
|
121
|
+
|
|
122
|
+
The bot now auto-downloads your timetable on first run and stores it in `ics/`. You only need manual prep if the auto download fails:
|
|
123
|
+
|
|
124
|
+
- Go to [Royal Holloway Timetable](https://intranet.royalholloway.ac.uk/students/study/timetable/your-timetable.aspx) and log in.
|
|
125
|
+
- Choose `Calendar Download`, click `View Timetable`, then `Android™ and others` to get the `.ics` link.
|
|
126
|
+
- Download the `.ics` and place it into the `ics` folder at the project root (create it if missing).
|
|
127
|
+
|
|
128
|
+
## Usage
|
|
129
|
+
|
|
130
|
+
1. **Navigate to the Script Directory**:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
cd RHUL_attendance_bot
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
2. **Activate the Virtual Environment**:
|
|
137
|
+
|
|
138
|
+
#### On Windows:
|
|
139
|
+
```bash
|
|
140
|
+
venv\Scripts\activate
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### On macOS/Linux:
|
|
144
|
+
```bash
|
|
145
|
+
source venv/bin/activate
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
3. **Run the Script**:
|
|
149
|
+
|
|
150
|
+
#### From PyPI install:
|
|
151
|
+
```bash
|
|
152
|
+
rhul-attendance-bot
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### From source:
|
|
156
|
+
```bash
|
|
157
|
+
python RHUL_attendance_bot.py
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
> **✅ Auto Login + 2FA**
|
|
161
|
+
>
|
|
162
|
+
> The bot now handles Microsoft login and the verification-code MFA flow automatically using your stored credentials and local TOTP secret. On first run, complete onboarding (credentials/secret); the timetable is downloaded automatically.
|
|
163
|
+
|
|
164
|
+
4. **Profile Selection**:
|
|
165
|
+
|
|
166
|
+
- Use `-user <profile_name>` to pick a specific profile, e.g.:
|
|
167
|
+
```bash
|
|
168
|
+
rhul-attendance-bot -user Alice
|
|
169
|
+
```
|
|
170
|
+
- If `-user` is not provided, the app will list existing profiles and ask you to choose (or create a new one).
|
|
171
|
+
|
|
172
|
+
5. **Keyboard Shortcuts**:
|
|
173
|
+
|
|
174
|
+
- **Manually Trigger the Next Event**: Press `[`, then `]`
|
|
175
|
+
- **Exit the Script**: Press `[`, then `q`
|
|
176
|
+
|
|
177
|
+
## Important Notes
|
|
178
|
+
|
|
179
|
+
- **Dependencies**: Make sure all required dependencies are installed by following the instructions in the `requirements.txt` file.
|
|
180
|
+
- **Virtual Environment**: Using a virtual environment is highly recommended to avoid conflicts with global packages.
|
|
181
|
+
- **System Time**: If the system time is not synchronized with the NTP server, the script will prompt you to synchronize your system clock.
|
|
182
|
+
- **Supported Platforms**: The script supports Windows, macOS, and Linux.
|
|
183
|
+
|
|
184
|
+
### Multi-Profile Usage
|
|
185
|
+
|
|
186
|
+
Profiles are stored under `~/.rhul_attendance_bot/profiles/<profile_name>`. Each profile has its own:
|
|
187
|
+
|
|
188
|
+
- `credentials.json`
|
|
189
|
+
- `2fa_config.json`
|
|
190
|
+
- `ics/`
|
|
191
|
+
- `chrome_user_data/`
|
|
192
|
+
- `automation.log`
|
|
193
|
+
|
|
194
|
+
Use `-user` to switch profiles at runtime.
|
|
195
|
+
|
|
196
|
+
> **🔐 Security Note - Login Session Duration**
|
|
197
|
+
>
|
|
198
|
+
> ~~A session typically lasts about one week; you may need to manually re-login after it expires.~~
|
|
199
|
+
> The bot now auto-renews login with stored credentials + TOTP. Sessions are refreshed automatically; monitor occasionally in case the institution changes its 2FA policy.
|
|
200
|
+
|
|
201
|
+
## Configuration
|
|
202
|
+
|
|
203
|
+
To configure the script, modify the relevant parameters inside the code or create a configuration file (not provided in this version). Future versions may include more flexible configuration options.
|
|
204
|
+
|
|
205
|
+
## Updating
|
|
206
|
+
|
|
207
|
+
If an update is detected, the script will prompt you to update. You can choose to update by typing `y` or skip it by typing `n`.
|
|
208
|
+
|
|
209
|
+
## Troubleshooting
|
|
210
|
+
|
|
211
|
+
1. **Chrome WebDriver Issues**: Make sure that the correct version of the ChromeDriver is being used. The script uses `webdriver-manager` to automatically manage ChromeDriver versions.
|
|
212
|
+
2. **Dependency Issues**: If you encounter errors related to missing modules, reinstall via `pip install rhul-attendance-bot` or use `pip install -r requirements.txt` from source.
|
|
213
|
+
3. **Virtual Environment Issues**: If you face issues while running the script, try setting up a fresh virtual environment and reinstalling the dependencies.
|
|
214
|
+
|
|
215
|
+
## TODO
|
|
216
|
+
|
|
217
|
+
Current focus / future ideas:
|
|
218
|
+
|
|
219
|
+
- ✅ **2FA Integration**: Microsoft verification-code path with TOTP auto-fill is implemented.
|
|
220
|
+
- ✅ **Automatic Login**: Stored credentials + TOTP drive a fully automatic login flow.
|
|
221
|
+
- ✅ **2FA Code Reading**: OTP is generated locally from your saved secret.
|
|
222
|
+
- ✅ **Discord Webhook Bot**: Discord webhook notifications for attendance status, login, and lifecycle (optional; disable by leaving webhook URL empty)
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
This project is licensed under the MIT License with an additional clause. See the [LICENSE](LICENSE) file for details.
|
|
227
|
+
|
|
228
|
+
## Acknowledgments
|
|
229
|
+
|
|
230
|
+
- Thanks to the developers of [Rich](https://github.com/Textualize/rich), [Selenium](https://www.selenium.dev/), and [ics.py](https://github.com/C4ptainCrunch/ics.py) for their amazing libraries.
|
|
231
|
+
|
|
232
|
+
## Contact
|
|
233
|
+
|
|
234
|
+
For questions or suggestions, please feel free to reach out via the [GitHub repository](https://github.com/PandaQuQ/RHUL_attendance_bot). Feedback and contributions are welcome!
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
RHUL_attendance_bot.py,sha256=J-5aSVrfGL1gjlGgsBcb_QYW4OEXL81mFVL0kLgqE-I,24193
|
|
2
|
+
app_paths.py,sha256=1VnUSQBaXCbAzDjivhCHyRTZJ3aHKMj6ewkcaMVDuHg,2161
|
|
3
|
+
auto_login.py,sha256=CfSr2kiUz7SyfEAHDaZmisiSXO3RXuSUIm_QU087iEE,34654
|
|
4
|
+
discord_broadcast.py,sha256=0hRJ_vronQK_TvRgC06NNWxaj8892h-Q7Hzmrp3-lB4,2615
|
|
5
|
+
display_manager.py,sha256=iRPWxwFiQWSvWl-QazKsiaLbvX2T7LPPFItfMZ52-Yg,11079
|
|
6
|
+
fetch_ics.py,sha256=5G2SYuYALqRxmT8TqUMTvNBvMHeoXuJueI9agyyApKs,4617
|
|
7
|
+
local_2fa.py,sha256=2PY6XtczgIxjKqWls9DeN27MWLIiNKbQdk9E3GZVJxU,729
|
|
8
|
+
update.py,sha256=kw_KWBJLu20JpMMmJQAAxu2ZZIlcUeRxppaVGr3S1r8,2354
|
|
9
|
+
rhul_attendance_bot-0.1.48.dist-info/licenses/LICENSE,sha256=iBk7hceb7NgwcLnsFlT_v2SE2-m9i8CzsjlvBw8xmPg,1075
|
|
10
|
+
rhul_attendance_bot-0.1.48.dist-info/METADATA,sha256=gx0sOQD_9mo0QzcFONZZHET94OD9-NFQPvIi7fzNze0,9721
|
|
11
|
+
rhul_attendance_bot-0.1.48.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
12
|
+
rhul_attendance_bot-0.1.48.dist-info/entry_points.txt,sha256=TH2lA3ukDDxlnFr2CIy0xd1ZbsaO6FMjuUTDUIbkShs,65
|
|
13
|
+
rhul_attendance_bot-0.1.48.dist-info/top_level.txt,sha256=TABKd3ZTI6hvA899O5XSRt0lk58h9dxrv6QHChtJqmU,102
|
|
14
|
+
rhul_attendance_bot-0.1.48.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
[Additional Clause]
|
|
14
|
+
For any commercial use, attribution to the original author (PandaQuQ) is required.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
update.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
import threading
|
|
5
|
+
import subprocess
|
|
6
|
+
import logging
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _prompt_update_with_timeout(timeout=10):
|
|
10
|
+
user_input = {"val": None}
|
|
11
|
+
|
|
12
|
+
def _reader():
|
|
13
|
+
try:
|
|
14
|
+
user_input["val"] = input().strip().lower()
|
|
15
|
+
except Exception:
|
|
16
|
+
user_input["val"] = None
|
|
17
|
+
|
|
18
|
+
t = threading.Thread(target=_reader, daemon=True)
|
|
19
|
+
t.start()
|
|
20
|
+
for remaining in range(timeout, 0, -1):
|
|
21
|
+
if user_input["val"] is not None:
|
|
22
|
+
break
|
|
23
|
+
print(
|
|
24
|
+
f"\rA new update is available. Update now? (y/n) Auto-skip in {remaining}s: ",
|
|
25
|
+
end="",
|
|
26
|
+
flush=True,
|
|
27
|
+
)
|
|
28
|
+
time.sleep(1)
|
|
29
|
+
print()
|
|
30
|
+
return user_input["val"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def check_for_updates(logger=None, timeout=10):
|
|
34
|
+
try:
|
|
35
|
+
if not os.path.isdir(os.path.join(os.getcwd(), ".git")):
|
|
36
|
+
if logger:
|
|
37
|
+
logger.info("Update check skipped (no git repo detected).", extra={"gray": True})
|
|
38
|
+
return
|
|
39
|
+
local_commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
|
|
40
|
+
remote_commit = subprocess.check_output(["git", "ls-remote", "origin", "HEAD"]).decode().split()[0]
|
|
41
|
+
if local_commit != remote_commit:
|
|
42
|
+
if logger:
|
|
43
|
+
logger.info("New update detected.")
|
|
44
|
+
user_input = _prompt_update_with_timeout(timeout=timeout)
|
|
45
|
+
if user_input in ("", "y", "yes"):
|
|
46
|
+
if logger:
|
|
47
|
+
logger.info("Updating the script...")
|
|
48
|
+
subprocess.check_call(["git", "pull"])
|
|
49
|
+
if logger:
|
|
50
|
+
logger.info("Update successful. Restarting the script...")
|
|
51
|
+
os.execv(sys.executable, [sys.executable] + sys.argv)
|
|
52
|
+
else:
|
|
53
|
+
if logger:
|
|
54
|
+
logger.info("Skipping update. Continuing with the current version.")
|
|
55
|
+
else:
|
|
56
|
+
if logger:
|
|
57
|
+
logger.info("No updates found. Continuing execution.", extra={"gray": True})
|
|
58
|
+
except (FileNotFoundError, subprocess.CalledProcessError) as e:
|
|
59
|
+
if logger:
|
|
60
|
+
logger.info("Update check skipped (git not available).", extra={"gray": True})
|
|
61
|
+
else:
|
|
62
|
+
raise
|
|
63
|
+
except Exception as e:
|
|
64
|
+
if logger:
|
|
65
|
+
logger.error(f"Failed to check for updates: {e}", exc_info=True)
|
|
66
|
+
else:
|
|
67
|
+
raise
|