From 53bbc81a36f9c8d61655060e41428cf86d10a8d7 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Sat, 13 May 2017 11:06:36 +0200 Subject: [PATCH] server: Save date of parsed meals --- server/server.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/server/server.go b/server/server.go index 05e911b..8ccd5bb 100644 --- a/server/server.go +++ b/server/server.go @@ -22,6 +22,7 @@ type ( Day int `json:"day"` Mensa string `json:"mensa"` Meals []Meal `json:"meals"` + Date string `json:"date"` } ) @@ -73,12 +74,22 @@ func writeToFile(content []byte) error { } func operate(mensa string, day int) (Menu, error) { - meals, err := parseHTML(fmt.Sprintf("http://www.studentenwerk-goettingen.de/speiseplan.html?no_cache=1&day=%vpush=0&selectmensa=%s", day, mensa)) + document, err := goquery.NewDocument(fmt.Sprintf("http://www.studentenwerk-goettingen.de/speiseplan.html?no_cache=1&day=%vpush=0&selectmensa=%s", day, mensa)) if err != nil { return Menu{}, err } - return Menu{Day: day, Mensa: mensa, Meals: meals}, nil + meals, err := parseMeals(document) + if err != nil { + return Menu{}, err + } + + date := parseDate(document) + return Menu{Day: day, Mensa: mensa, Meals: meals, Date: date}, nil +} + +func parseDate(doc *goquery.Document) string { + return strip(doc.Find("#speise-head2_datum").Text()) } func strip(old string) string { @@ -87,12 +98,7 @@ func strip(old string) string { return new } -func parseHTML(url string) ([]Meal, error) { - doc, err := goquery.NewDocument(url) - if err != nil { - return nil, err - } - +func parseMeals(doc *goquery.Document) ([]Meal, error) { meals := []Meal{} doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { meal := Meal{