Browse Source

server: Save date of parsed meals

vuex
Schneider 8 years ago
parent
commit
53bbc81a36
  1. 22
      server/server.go

22
server/server.go

@ -22,6 +22,7 @@ type (
Day int `json:"day"` Day int `json:"day"`
Mensa string `json:"mensa"` Mensa string `json:"mensa"`
Meals []Meal `json:"meals"` 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) { 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 { if err != nil {
return Menu{}, err 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 { func strip(old string) string {
@ -87,12 +98,7 @@ func strip(old string) string {
return new 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{} meals := []Meal{}
doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) {
meal := Meal{ meal := Meal{

Loading…
Cancel
Save