feat: add official academic calendar source adapter - #255
Open
SabrinaTso wants to merge 2 commits into
Open
Conversation
|
9 tasks
There was a problem hiding this comment.
Pull request overview
Adds a read-only adapter for NTHU’s official academic-calendar ICS feed.
Changes:
- Adds bounded fetching and source-faithful ICS parsing.
- Preserves metadata, hashes, and event time semantics.
- Adds fixtures, tests, package exports, and the
icalendardependency.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Summary |
|---|---|
tests/test_academic_calendar.py |
Adapter and parser tests. Nit (2 votes): Correct the reported verification count. |
tests/fixtures/academic_calendar/official_nthu_115_excerpt.source.json |
Fixture provenance metadata. |
tests/fixtures/academic_calendar/official_nthu_115_excerpt.ics |
Deterministic ICS fixture. |
src/data_api/domain/academic_calendar/services.py |
Fetching and parsing implementation. Moderate (2 votes): Reject mixed DATE/DATE-TIME DTSTART/DTEND pairs and count them as skipped. |
src/data_api/domain/academic_calendar/__init__.py |
Academic-calendar domain exports. |
src/data_api/domain/__init__.py |
Registers the academic-calendar domain. |
requirements.txt |
Adds the icalendar dependency. |
Suppressed comments (2)
src/data_api/domain/academic_calendar/services.py:93
- The
tryaroundCalendar.from_icalmakes anyValueErrorraised while decoding one malformedVEVENTa document-levelAcademicCalendarParseError. Thus an invalidDTSTART/DTENDin one sibling can prevent later valid events from being walked, contrary to the stated skip/count behavior. Use a tolerant per-component parse boundary (or otherwise retain successfully parsed siblings) so only the offendingVEVENTis counted and skipped.
try:
calendar = Calendar.from_ical(ics_content)
except (TypeError, ValueError) as exc:
raise AcademicCalendarParseError(f"Unable to parse VCALENDAR document: {exc}") from exc
src/data_api/domain/academic_calendar/services.py:63
- The 10-second timeout is configured only when this function creates
active_client; an injectedAsyncClientcan have a different timeout or no timeout at all, so this source request can exceed the adapter's stated bound. Passtimeout=10.0tostream(or otherwise enforce it per request) so the timeout remains an invariant for injected clients too.
async with active_client.stream(
"GET", OFFICIAL_NTHU_ICS_URL, follow_redirects=False
) as response:
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+120
to
+121
| end = _optional_decoded_value(component, "DTEND") | ||
| all_day = isinstance(start, date) and not isinstance(start, datetime) |
| class TestOfficialNTHUCalendarParser: | ||
| """The adapter preserves source semantics instead of guessing dates.""" | ||
|
|
||
| def test_uses_the_stable_public_google_ics_feed(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
VEVENTs, disable redirects, use a 10-second timeout, and cap streamed ICS input at 5 MiBScope
This is the source-adapter foundation for #184. It intentionally does not add
/academic-calendar, cache/storage, an MCP tool, or multi-source policy yet; those can be reviewed separately once the source contract is accepted.Verification
python -m pytest tests/test_academic_calendar.py— 8 passedpython -m pytest -n auto tests— 687 passedpython -m pre_commit run --all-filesSource provenance
The runtime feed is the stable public ICS endpoint for the same
nthu.acad@gmail.comGoogle Calendar embedded by NTHU Academic Affairs. The fixture metadata retains the official publication page, retrieval timestamp, and source snapshot digest.