worsaga 0.1.0__tar.gz
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.
- worsaga-0.1.0/LICENSE +201 -0
- worsaga-0.1.0/MANIFEST.in +4 -0
- worsaga-0.1.0/PKG-INFO +298 -0
- worsaga-0.1.0/README.md +273 -0
- worsaga-0.1.0/pyproject.toml +33 -0
- worsaga-0.1.0/setup.cfg +4 -0
- worsaga-0.1.0/src/worsaga/__init__.py +74 -0
- worsaga-0.1.0/src/worsaga/banner.py +220 -0
- worsaga-0.1.0/src/worsaga/cli.py +918 -0
- worsaga-0.1.0/src/worsaga/client.py +161 -0
- worsaga-0.1.0/src/worsaga/config.py +137 -0
- worsaga-0.1.0/src/worsaga/deadlines.py +101 -0
- worsaga-0.1.0/src/worsaga/extraction.py +386 -0
- worsaga-0.1.0/src/worsaga/materials.py +431 -0
- worsaga-0.1.0/src/worsaga/mcp_server.py +255 -0
- worsaga-0.1.0/src/worsaga/summaries.py +1336 -0
- worsaga-0.1.0/src/worsaga.egg-info/PKG-INFO +298 -0
- worsaga-0.1.0/src/worsaga.egg-info/SOURCES.txt +29 -0
- worsaga-0.1.0/src/worsaga.egg-info/dependency_links.txt +1 -0
- worsaga-0.1.0/src/worsaga.egg-info/entry_points.txt +2 -0
- worsaga-0.1.0/src/worsaga.egg-info/requires.txt +9 -0
- worsaga-0.1.0/src/worsaga.egg-info/top_level.txt +1 -0
- worsaga-0.1.0/tests/test_banner.py +271 -0
- worsaga-0.1.0/tests/test_cli.py +1228 -0
- worsaga-0.1.0/tests/test_client.py +88 -0
- worsaga-0.1.0/tests/test_config.py +245 -0
- worsaga-0.1.0/tests/test_deadlines.py +83 -0
- worsaga-0.1.0/tests/test_download.py +468 -0
- worsaga-0.1.0/tests/test_extraction.py +397 -0
- worsaga-0.1.0/tests/test_materials.py +397 -0
- worsaga-0.1.0/tests/test_summaries.py +1270 -0
worsaga-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Yamin Mushtaq
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
worsaga-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: worsaga
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Study kit for university LMS systems, starting with Moodle
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Keywords: moodle,lms,education,study,mcp
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Topic :: Education
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: platformdirs>=2.10
|
|
18
|
+
Requires-Dist: pymupdf>=1.23
|
|
19
|
+
Requires-Dist: rich>=13.0
|
|
20
|
+
Provides-Extra: mcp
|
|
21
|
+
Requires-Dist: mcp>=1.0; extra == "mcp"
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# Worsaga
|
|
27
|
+
|
|
28
|
+
Worsaga is a study kit for university LMS systems.
|
|
29
|
+
|
|
30
|
+
This repository is the **open-source core** of Worsaga — the CLI and the MCP server — released under the Apache License 2.0 (see [LICENSE](LICENSE)). The wider Worsaga platform, app, and architecture are developed separately and are not part of this repo.
|
|
31
|
+
|
|
32
|
+
## Platform support
|
|
33
|
+
|
|
34
|
+
- Supported now: **Moodle**
|
|
35
|
+
- Coming soon: **Blackboard**, **Canvas**
|
|
36
|
+
|
|
37
|
+
Worsaga is intentionally positioned as a broader LMS study layer, not a Moodle-only product. Moodle just happens to be the first integration.
|
|
38
|
+
|
|
39
|
+
## What's in this repo
|
|
40
|
+
|
|
41
|
+
This repo contains only the open-core pieces:
|
|
42
|
+
|
|
43
|
+
- The `worsaga` command-line interface.
|
|
44
|
+
- The `worsaga.mcp_server` MCP server for agents.
|
|
45
|
+
- The read-only Moodle client and supporting Python modules they share.
|
|
46
|
+
|
|
47
|
+
The broader Worsaga product — hosted platform, end-user app, and overall system architecture — lives outside this repository and is not open source. Issues, PRs, and discussions here should stay scoped to the CLI and MCP core.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
### Install
|
|
52
|
+
|
|
53
|
+
Pick whichever tool you already have:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
uv tool install worsaga # recommended — adds worsaga to PATH automatically
|
|
57
|
+
pipx install worsaga # alternative
|
|
58
|
+
pip install worsaga # if you just want the library, or don't have uv/pipx
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Windows note:** If `worsaga` is not recognised after `pip install`, the Python
|
|
62
|
+
Scripts folder may not be on your PATH. Either:
|
|
63
|
+
|
|
64
|
+
1. Add it manually — find the path with:
|
|
65
|
+
```
|
|
66
|
+
py -c "import site; print(site.getusersitepackages())"
|
|
67
|
+
```
|
|
68
|
+
Then add that directory to your PATH in **Windows Settings > System > Environment Variables**.
|
|
69
|
+
|
|
70
|
+
2. Or use the module form directly (works immediately, no PATH changes needed):
|
|
71
|
+
```
|
|
72
|
+
py -m worsaga.cli courses
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Set up credentials
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
worsaga setup
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The setup command will prompt for your Moodle URL, API token, and user ID, then verify
|
|
82
|
+
the connection and save credentials. See [Getting a Moodle API token](#getting-a-moodle-api-token) below if you don't have a token yet.
|
|
83
|
+
|
|
84
|
+
Non-interactive setup (for scripts and agents):
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
worsaga setup --url https://moodle.example.ac.uk --token YOUR_TOKEN
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Getting a Moodle API token
|
|
91
|
+
|
|
92
|
+
### Via the Moodle web interface (recommended)
|
|
93
|
+
|
|
94
|
+
1. Log in to your Moodle site in a browser.
|
|
95
|
+
2. Click your profile picture (top right) → **Preferences**.
|
|
96
|
+
3. Under **User account**, click **Security keys**.
|
|
97
|
+
4. Find the **Moodle mobile web service** row.
|
|
98
|
+
5. Click **Reset** to generate a new token (or copy the existing one if shown).
|
|
99
|
+
6. Copy the token string — this is the long alphanumeric value you need for setup.
|
|
100
|
+
|
|
101
|
+
> **Tip:** Copy the token value itself (a long string of letters and numbers), not the key name like "Webservice-A3JsY" shown in the table.
|
|
102
|
+
|
|
103
|
+
### Via the token URL (advanced)
|
|
104
|
+
|
|
105
|
+
If the method above doesn't work for your institution, you can request a token directly:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
https://<your-moodle>/login/token.php?username=YOUR_USER&password=YOUR_PASS&service=moodle_mobile_app
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Note:** Only use this over HTTPS. Never share your token.
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
Credentials are resolved in this order:
|
|
116
|
+
|
|
117
|
+
1. **Explicit arguments** passed to `MoodleConfig.load(url=..., token=...)`
|
|
118
|
+
2. **Environment variables**: `WORSAGA_URL`, `WORSAGA_TOKEN`, `WORSAGA_USERID`
|
|
119
|
+
3. **Config file** (first found):
|
|
120
|
+
- `$WORSAGA_CREDS_PATH` (if set)
|
|
121
|
+
- Platform-native config directory (see below)
|
|
122
|
+
|
|
123
|
+
The config directory is determined by `platformdirs` so it follows each OS's conventions: `~/.config/worsaga/` on Linux, `~/Library/Application Support/worsaga/` on macOS, and `%APPDATA%\worsaga\` on Windows. Run `worsaga config` to see the active path on your system, or `worsaga config --json` for machine-readable output.
|
|
124
|
+
|
|
125
|
+
### Config file format
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"url": "https://moodle.example.ac.uk",
|
|
130
|
+
"token": "your_token_here",
|
|
131
|
+
"userid": 12345
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Environment variables
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
export WORSAGA_URL="https://moodle.example.ac.uk"
|
|
139
|
+
export WORSAGA_TOKEN="your_token_here"
|
|
140
|
+
export WORSAGA_USERID="12345"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## CLI usage
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
worsaga courses # List enrolled courses
|
|
147
|
+
worsaga deadlines # Show upcoming deadlines (14-day window)
|
|
148
|
+
worsaga deadlines --days 7 # Shorter look-ahead
|
|
149
|
+
worsaga contents 12345 # Show sections for course ID 12345
|
|
150
|
+
worsaga contents EC100 # Look up by course short-code
|
|
151
|
+
worsaga contents MG488 # Prefix match: finds MG488_2526 if unique
|
|
152
|
+
worsaga contents EC100 --week 3 # Filter to a specific week
|
|
153
|
+
worsaga materials EC100 # List all downloadable materials (discovery)
|
|
154
|
+
worsaga materials EC100 --week 3 # Materials for week 3 only
|
|
155
|
+
worsaga download EC100 --week 3 --match slides # Download a file (authenticated)
|
|
156
|
+
worsaga download EC100 --week 3 --index 0 # Download by index
|
|
157
|
+
worsaga summary EC100 --week 3 # AI-generated study notes for a week
|
|
158
|
+
worsaga setup # Guided first-time setup
|
|
159
|
+
worsaga update # Show the safe upgrade command
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Add `--json` before the command for machine-readable JSON output:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
worsaga --json courses
|
|
166
|
+
worsaga --json deadlines
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## MCP server
|
|
170
|
+
|
|
171
|
+
For use with Claude Code, OpenClaw, or other MCP-capable agents:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pip install "worsaga[mcp]"
|
|
175
|
+
python -m worsaga.mcp_server
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
The server runs as a stdio-based MCP server. Tools: `list_courses`, `get_deadlines`, `get_course_contents`, `get_week_materials` (discovery), `search_course_content`, `get_weekly_summary`, `download_material` (authenticated fetch).
|
|
179
|
+
|
|
180
|
+
**Claude Code**: Add to your Claude Code settings / MCP Servers config:
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"mcpServers": {
|
|
184
|
+
"worsaga": {
|
|
185
|
+
"command": "python",
|
|
186
|
+
"args": ["-m", "worsaga.mcp_server"]
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
Set `WORSAGA_URL`, `WORSAGA_TOKEN`, `WORSAGA_USERID` as environment variables or in `~/.config/worsaga/config.json`.
|
|
192
|
+
|
|
193
|
+
**OpenClaw**: Add to your agent or gateway config:
|
|
194
|
+
```yaml
|
|
195
|
+
mcpServers:
|
|
196
|
+
moodle:
|
|
197
|
+
command: python
|
|
198
|
+
args: ["-m", "worsaga.mcp_server"]
|
|
199
|
+
env:
|
|
200
|
+
WORSAGA_URL: "https://your-moodle.example.ac.uk"
|
|
201
|
+
WORSAGA_TOKEN: "your_token_here"
|
|
202
|
+
WORSAGA_USERID: "12345"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## CI
|
|
206
|
+
|
|
207
|
+
Packaging and install smoke tests run automatically on every push and pull request across Linux, macOS, and Windows. The workflow builds both sdist and wheel, installs each in a clean virtual environment, and verifies the CLI entrypoints work.
|
|
208
|
+
|
|
209
|
+
## Development
|
|
210
|
+
|
|
211
|
+
To work on worsaga itself (contributors / developers):
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git clone <repo-url> && cd worsaga
|
|
215
|
+
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
216
|
+
pip install -e '.[dev]'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Running tests
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pytest
|
|
223
|
+
|
|
224
|
+
# On Windows, if pytest isn't found on PATH:
|
|
225
|
+
py -m pytest
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Safety
|
|
229
|
+
|
|
230
|
+
This package is **read-only by design**. Every Moodle API call is checked against a hardcoded allowlist in `ALLOWED_FUNCTIONS` inside the client module. Write-like operations — submitting assignments, posting forum replies, uploading files, creating events, deleting content — are blocked with a `SafetyError` before any network request is made.
|
|
231
|
+
|
|
232
|
+
- Your token cannot modify anything on Moodle/Canvas/Blackboard, even accidentally.
|
|
233
|
+
- Agents (Claude Code, OpenClaw, etc.) can use these tools safely.
|
|
234
|
+
- Treat your API token like a password: never commit it to git, never share it, use HTTPS only.
|
|
235
|
+
|
|
236
|
+
### Known limitations
|
|
237
|
+
|
|
238
|
+
- **Token portability varies by institution.** Some Moodle instances require specific web-service configurations. Check with your Moodle administrator about enabling REST web services.
|
|
239
|
+
- **Rate limiting.** Moodle servers may throttle rapid API calls. The package handles errors gracefully but cannot bypass institutional limits.
|
|
240
|
+
- **Only Moodle REST API v2 is supported.**
|
|
241
|
+
- **Course discovery by short-code uses prefix matching** (e.g. "MG488" matches "MG488_2526") — see CLI usage above.
|
|
242
|
+
|
|
243
|
+
## For Agent Authors
|
|
244
|
+
|
|
245
|
+
worsaga is designed to be agent-friendly:
|
|
246
|
+
|
|
247
|
+
- Zero configuration needed for discovery — call `list_courses()` with no arguments to explore.
|
|
248
|
+
- Self-documenting tool names and clear purpose descriptions.
|
|
249
|
+
- Structured output by default — use `--json` on CLI, or rely on structured dict/JSON from the Python API.
|
|
250
|
+
- Graceful degradation with clear error messages when credentials are missing.
|
|
251
|
+
|
|
252
|
+
### Discovery vs. download
|
|
253
|
+
|
|
254
|
+
There are two distinct steps — **discovery** and **download** — with separate commands for each:
|
|
255
|
+
|
|
256
|
+
| Purpose | CLI | MCP tool |
|
|
257
|
+
|---------|-----|----------|
|
|
258
|
+
| **List** available files (metadata only) | `worsaga materials` | `get_week_materials()` |
|
|
259
|
+
| **Download** a file (authenticated) | `worsaga download` | `download_material()` |
|
|
260
|
+
|
|
261
|
+
`materials` / `get_week_materials` return metadata including a `file_url` field. This URL is the raw Moodle address retained for **provenance only** — do not fetch it directly, as it requires token authentication that is handled internally by `download` / `download_material`.
|
|
262
|
+
|
|
263
|
+
### Downloading materials
|
|
264
|
+
|
|
265
|
+
The `download` command (CLI) and `download_material` tool (MCP) provide authenticated file downloads without exposing the Moodle token. The flow:
|
|
266
|
+
|
|
267
|
+
1. **Discover** materials: `worsaga materials EC100 --week 3`
|
|
268
|
+
2. **Download** one: `worsaga download EC100 --week 3 --match slides`
|
|
269
|
+
|
|
270
|
+
If multiple materials match, you get a structured candidate list with indices:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
worsaga --json download EC100 --week 3
|
|
274
|
+
# → {"error": "3 materials match. Use --index ...", "candidates": [...]}
|
|
275
|
+
|
|
276
|
+
worsaga --json download EC100 --week 3 --index 0
|
|
277
|
+
# → {"local_path": "/path/to/week3_slides.pdf", "file_name": "week3_slides.pdf", ...}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
The same workflow is available via MCP:
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
get_week_materials(course_id=42, week="3") # discover
|
|
284
|
+
download_material(course_id=42, week="3", match="slides") # fetch
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Example integration in an agent system prompt:
|
|
288
|
+
```
|
|
289
|
+
You have access to worsaga. First run list_courses() to see available courses,
|
|
290
|
+
then get_deadlines() to check upcoming work, then explore specific courses with
|
|
291
|
+
get_course_contents(). To see what files are available, use get_week_materials(). To
|
|
292
|
+
fetch a file, use download_material() — it handles authentication internally. Never
|
|
293
|
+
fetch file_url values directly; always use download_material().
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
This repo — the worsaga CLI and MCP server — is released under the [Apache License 2.0](LICENSE). The rest of the Worsaga platform (hosted service, end-user app, and overall system architecture) is developed separately and is not covered by this license.
|