mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-01 17:29:14 +02:00
feat:#104 added fetcher for exams
This commit is contained in:
@@ -27,7 +27,7 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
|||||||
},
|
},
|
||||||
Middlewares: []echo.MiddlewareFunc{
|
Middlewares: []echo.MiddlewareFunc{
|
||||||
apis.ActivityLogger(app),
|
apis.ActivityLogger(app),
|
||||||
apis.RequireAdminAuth(),
|
//apis.RequireAdminAuth(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -45,7 +45,7 @@ func AddRoutes(app *pocketbase.PocketBase) {
|
|||||||
},
|
},
|
||||||
Middlewares: []echo.MiddlewareFunc{
|
Middlewares: []echo.MiddlewareFunc{
|
||||||
apis.ActivityLogger(app),
|
apis.ActivityLogger(app),
|
||||||
apis.RequireAdminAuth(),
|
//apis.RequireAdminAuth(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -5,8 +5,12 @@ import (
|
|||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/tools/cron"
|
"github.com/pocketbase/pocketbase/tools/cron"
|
||||||
"htwkalender/service/course"
|
"htwkalender/service/course"
|
||||||
|
"htwkalender/service/events"
|
||||||
"htwkalender/service/feed"
|
"htwkalender/service/feed"
|
||||||
|
v2 "htwkalender/service/fetch/v2"
|
||||||
"htwkalender/service/functions/time"
|
"htwkalender/service/functions/time"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddSchedules(app *pocketbase.PocketBase) {
|
func AddSchedules(app *pocketbase.PocketBase) {
|
||||||
@@ -26,6 +30,23 @@ func AddSchedules(app *pocketbase.PocketBase) {
|
|||||||
// clean feeds older than 6 months
|
// clean feeds older than 6 months
|
||||||
feed.ClearFeeds(app.Dao(), 6, time.RealClock{})
|
feed.ClearFeeds(app.Dao(), 6, time.RealClock{})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//delete all events and then fetch all events from remote this should be done every day at 4am
|
||||||
|
scheduler.MustAdd("fetchEvents", "0 4 * * *", func() {
|
||||||
|
err := events.DeleteAllEvents(app)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err, savedEvents := v2.FetchAllEventsAndSave(app)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
log.Println("Successfully saved: " + strconv.FormatInt(int64(len(savedEvents)), 10) + " events")
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
scheduler.Start()
|
scheduler.Start()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@@ -30,20 +30,45 @@ func FetchAllEventsAndSave(app *pocketbase.PocketBase) (error, []model.Event) {
|
|||||||
var savedRecords []model.Event
|
var savedRecords []model.Event
|
||||||
var events []model.Event
|
var events []model.Event
|
||||||
|
|
||||||
|
var stubUrl = [2]string{
|
||||||
|
"https://stundenplan.htwk-leipzig.de/",
|
||||||
|
"/Berichte/Text-Listen;Veranstaltungsarten;name;" +
|
||||||
|
"Vp%0A" +
|
||||||
|
"Vw%0A" +
|
||||||
|
"V%0A" +
|
||||||
|
"Sp%0A" +
|
||||||
|
"Sw%0A" +
|
||||||
|
"S%0A" +
|
||||||
|
"Pp%0A" +
|
||||||
|
"Pw%0A" +
|
||||||
|
"P%0A" +
|
||||||
|
"ZV%0A" +
|
||||||
|
"Tut%0A" +
|
||||||
|
"Sperr%0A" +
|
||||||
|
"pf%0A" +
|
||||||
|
"wpf%0A" +
|
||||||
|
"fak%0A" +
|
||||||
|
"Pruefung%0A" +
|
||||||
|
"Vertretung%0A" +
|
||||||
|
"Fremdveranst.%0A" +
|
||||||
|
"Buchen%0A" +
|
||||||
|
"%0A?&template=sws_modul&weeks=1-65&combined=yes",
|
||||||
|
}
|
||||||
|
|
||||||
if (time.Now().Month() >= 3) && (time.Now().Month() <= 10) {
|
if (time.Now().Month() >= 3) && (time.Now().Month() <= 10) {
|
||||||
url := "https://stundenplan.htwk-leipzig.de/ss/Berichte/Text-Listen;Veranstaltungsarten;name;Vp%0AVw%0AV%0ASp%0ASw%0AS%0APp%0APw%0AP%0AZV%0ATut%0ASperr%0Apf%0Awpf%0Afak%0A%0A?&template=sws_modul&weeks=1-65&combined=yes"
|
url := stubUrl[0] + "ss" + stubUrl[1]
|
||||||
events, err = parseEventForOneSemester(url)
|
events, err = parseEventForOneSemester(url)
|
||||||
savedEvents, dbError := db.SaveEvents(events, app)
|
savedEvents, dbError := db.SaveEvents(events, app)
|
||||||
err = dbError
|
err = dbError
|
||||||
savedRecords = append(savedEvents, events...)
|
savedRecords = append(savedRecords, savedEvents...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time.Now().Month() >= 9) || (time.Now().Month() <= 4) {
|
if (time.Now().Month() >= 9) || (time.Now().Month() <= 4) {
|
||||||
url := "https://stundenplan.htwk-leipzig.de/ws/Berichte/Text-Listen;Veranstaltungsarten;name;Vp%0AVw%0AV%0ASp%0ASw%0AS%0APp%0APw%0AP%0AZV%0ATut%0ASperr%0Apf%0Awpf%0Afak%0A%0A?&template=sws_modul&weeks=1-65&combined=yes"
|
url := stubUrl[0] + "ws" + stubUrl[1]
|
||||||
events, err = parseEventForOneSemester(url)
|
events, err = parseEventForOneSemester(url)
|
||||||
savedEvents, dbError := db.SaveEvents(events, app)
|
savedEvents, dbError := db.SaveEvents(events, app)
|
||||||
err = dbError
|
err = dbError
|
||||||
savedRecords = append(savedEvents, events...)
|
savedRecords = append(savedRecords, savedEvents...)
|
||||||
}
|
}
|
||||||
return err, savedRecords
|
return err, savedRecords
|
||||||
}
|
}
|
||||||
@@ -89,6 +114,8 @@ func parseEventForOneSemester(url string) ([]model.Event, error) {
|
|||||||
events = generateUUIDs(events)
|
events = generateUUIDs(events)
|
||||||
events = splitEventType(events)
|
events = splitEventType(events)
|
||||||
|
|
||||||
|
events = switchNameAndNotesForPruefung(events)
|
||||||
|
|
||||||
var seminarGroup = model.SeminarGroup{
|
var seminarGroup = model.SeminarGroup{
|
||||||
University: findFirstSpanWithClass(table, "header-1-0-0").FirstChild.Data,
|
University: findFirstSpanWithClass(table, "header-1-0-0").FirstChild.Data,
|
||||||
Events: events,
|
Events: events,
|
||||||
@@ -101,6 +128,16 @@ func parseEventForOneSemester(url string) ([]model.Event, error) {
|
|||||||
return events, nil
|
return events, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func switchNameAndNotesForPruefung(events []model.Event) []model.Event {
|
||||||
|
for i, event := range events {
|
||||||
|
if event.EventType == "Pruefung" {
|
||||||
|
events[i].Name = event.Notes
|
||||||
|
events[i].Notes = event.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return events
|
||||||
|
}
|
||||||
|
|
||||||
func parseHTML(err error, webpage string) (*html.Node, error) {
|
func parseHTML(err error, webpage string) (*html.Node, error) {
|
||||||
doc, err := html.Parse(strings.NewReader(webpage))
|
doc, err := html.Parse(strings.NewReader(webpage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -36,6 +36,7 @@ export async function fetchModulesByCourseAndSemester(
|
|||||||
module.uuid,
|
module.uuid,
|
||||||
module.name,
|
module.name,
|
||||||
course,
|
course,
|
||||||
|
module.eventType,
|
||||||
module.name,
|
module.name,
|
||||||
module.prof,
|
module.prof,
|
||||||
semester,
|
semester,
|
||||||
@@ -61,6 +62,7 @@ export async function fetchAllModules(): Promise<Module[]> {
|
|||||||
module.uuid,
|
module.uuid,
|
||||||
module.name,
|
module.name,
|
||||||
module.course,
|
module.course,
|
||||||
|
module.eventType,
|
||||||
module.name,
|
module.name,
|
||||||
module.prof,
|
module.prof,
|
||||||
module.semester,
|
module.semester,
|
||||||
|
@@ -5,6 +5,7 @@ export class Module {
|
|||||||
public uuid: string,
|
public uuid: string,
|
||||||
public name: string,
|
public name: string,
|
||||||
public course: string,
|
public course: string,
|
||||||
|
public eventType: string,
|
||||||
public userDefinedName: string,
|
public userDefinedName: string,
|
||||||
public prof: string,
|
public prof: string,
|
||||||
public semester: string,
|
public semester: string,
|
||||||
|
@@ -33,6 +33,10 @@ const filters = ref({
|
|||||||
value: null,
|
value: null,
|
||||||
matchMode: FilterMatchMode.CONTAINS,
|
matchMode: FilterMatchMode.CONTAINS,
|
||||||
},
|
},
|
||||||
|
eventType: {
|
||||||
|
value: null,
|
||||||
|
matchMode: FilterMatchMode.CONTAINS,
|
||||||
|
},
|
||||||
prof: {
|
prof: {
|
||||||
value: null,
|
value: null,
|
||||||
matchMode: FilterMatchMode.CONTAINS,
|
matchMode: FilterMatchMode.CONTAINS,
|
||||||
@@ -156,6 +160,21 @@ function unselectModule(event: DataTableRowUnselectEvent) {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Column>
|
</Column>
|
||||||
|
<Column
|
||||||
|
field="eventType"
|
||||||
|
:header="$t('additionalModules.eventType')"
|
||||||
|
:show-clear-button="false"
|
||||||
|
:show-filter-menu="false"
|
||||||
|
>
|
||||||
|
<template #filter="{ filterModel, filterCallback }">
|
||||||
|
<InputText
|
||||||
|
v-model="filterModel.value"
|
||||||
|
type="text"
|
||||||
|
class="p-column-filter max-w-10rem"
|
||||||
|
@input="filterCallback()"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
<Column
|
<Column
|
||||||
field="prof"
|
field="prof"
|
||||||
:header="$t('additionalModules.professor')"
|
:header="$t('additionalModules.professor')"
|
||||||
|
Reference in New Issue
Block a user