|
|
@ -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{ |
|
|
|