Documentation
¶
Overview ¶
Package webread reads Moodle's own pages.
It exists for what the APIs cannot reach. On a site with mobile web services switched off there is no token, and the endpoint a browser session can use exposes only a handful of functions — assignments and grades are not among them. The pages are the only remaining source.
Reading a page is worse than calling an API in every way, so the rules here are stricter to compensate:
- Read only. Nothing here submits a form or follows an action.
- Anchor on what Moodle generates from data, not on what it shows a person. A class built from a database value survives translation; the words beside it do not.
- When an anchor is missing, say the page changed shape. Guessing from whatever else is on the page is how a scraper reports a confident wrong answer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Activity ¶
type Activity struct {
// CMID is the course module id, which is the only identifier a page
// carries. The activity's own id appears nowhere in the markup.
CMID string
// Module is the activity type, such as "assign" or "forum".
Module string
Name string
URL string
}
Activity is one thing on a course page.
func ParseCourseActivities ¶
ParseCourseActivities reads course/view.php.
It anchors on the link to each activity rather than on the course layout, which differs by course format — weekly, topics, single activity — while the links are the same in all of them.
type AssignPage ¶ added in v0.2.0
type AssignPage struct {
// Name is empty when the page does not carry the attribute.
Name string
// CourseID is empty when the body carries no course class.
CourseID string
// Description is the description's markup, unchanged. Empty both for an
// assignment without one and for a page that hides it from students
// until the assignment opens.
Description string
Attachments []FileLink
}
AssignPage is what an assignment page says about the assignment itself.
The dates are on the page too, but only as prose the site formatted in its own language; they are left to the calendar, which states them as numbers.
func ParseAssignPage ¶ added in v0.2.0
func ParseAssignPage(markup string) (AssignPage, error)
ParseAssignPage reads the assignment's own details off mod/assign/view.php.
type AssignStatus ¶
type AssignStatus struct {
// Status is Moodle's own word: new, draft, submitted or reopened. It is
// read from a class token, so it matches what the web service API reports
// for the same submission.
Status string
// Graded reports whether the work has been marked.
Graded bool
// Locked reports that Moodle will not accept changes.
Locked bool
// Files are the submitted files, where the page lists them.
Files []FileLink
}
AssignStatus is what an assignment page says about the caller's submission.
func ParseAssignStatus ¶
func ParseAssignStatus(markup string) (AssignStatus, error)
ParseAssignStatus reads mod/assign/view.php.
The status comes from a class Moodle generates from the database value. Its absence is meaningful rather than a gap: Moodle omits the class in exactly one case, when there is no submission to describe, so an anchored table with no status token means nothing has been submitted.
type CourseTotal ¶
type CourseTotal struct {
// CourseID comes from the row's own link. A row whose link this build
// cannot read is dropped rather than reported without one: a total that
// cannot be tied to a course is not something to show a student.
CourseID string
Name string
// Grade is Moodle's own rendering. It is empty when the report shows a
// dash, which means nothing has been marked — not that the total is zero.
Grade string
}
CourseTotal is one course's line in the overview report.
func ParseOverview ¶
func ParseOverview(markup string) ([]CourseTotal, error)
ParseOverview reads grade/report/overview/index.php.
This page is the reason a browser-session account can be told its totals at all: no web service and no AJAX endpoint on such a site will answer for the overview report, and the command used to say reading pages could not do it.
type DiscussionRow ¶ added in v0.2.0
type DiscussionRow struct {
ID string
Name string
Author string
LastAuthor string
CreatedAt *time.Time
ModifiedAt *time.Time
Pinned bool
Locked bool
}
DiscussionRow is one thread on a forum page.
The number of replies is on the row too, but only as a bare number in a cell with no marker of its own, so it is not read.
type FileLink ¶ added in v0.2.0
type FileLink struct {
Name string
// URL is the page's own link into pluginfile.php, which a browser session
// can download.
URL string
}
FileLink is a file a page links to.
type ForumPage ¶ added in v0.2.0
type ForumPage struct {
Discussions []DiscussionRow
// MorePages reports a paging bar: the threads above are the first page.
MorePages bool
}
ForumPage is what mod/forum/view.php lists.
func ParseForumPage ¶ added in v0.2.0
ParseForumPage reads the discussion list off mod/forum/view.php.
type Grade ¶
type Grade struct {
Name string
// Grade is Moodle's own rendering — "85.00", a letter, or a scale word.
// It is empty when nothing has been marked, which the report shows as a
// dash.
Grade string
// Range is the item's range as the report prints it, such as "0–100".
Range string
// Percentage is empty when the report shows none, which includes anything
// graded on a scale.
Percentage string
Feedback string
// Total marks the course total rather than an activity. Its maximum counts
// only what has been graded, so it is never the sum of the rows above.
Total bool
}
Grade is one row of the user's grade report.
func ParseGrades ¶
ParseGrades reads grade/report/user/index.php.
Every value is taken from a cell Moodle labels with a generated column key. The words in the header row are translated; the keys are not.