Browse Source

Use full menu from website

vuex
Schneider 8 years ago
parent
commit
3442b63231
  1. 22
      server/server.go

22
server/server.go

@ -19,7 +19,7 @@ type (
}
// Menu contains all info to menues in a mensa on one day
Menu struct {
Day string `json:"day"`
Day int `json:"day"`
Mensa string `json:"mensa"`
Meals []Meal `json:"meals"`
}
@ -30,11 +30,6 @@ var (
"Zentralmensa",
"Nordmensa",
}
days = []string{
"heute",
"morgen",
"uebermorgen",
}
)
func main() {
@ -44,7 +39,7 @@ func main() {
}
for _, mensa := range mensen {
for _, day := range days {
for day := 1; day < 8; day = day + 1 {
menu, err := operate(mensa, day)
if err != nil {
fmt.Println(err.Error())
@ -57,7 +52,7 @@ func main() {
return
}
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.%s.json", path, strings.ToLower(mensa), day), content, 0644)
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.%v.json", path, strings.ToLower(mensa), day), content, 0644)
if err != nil {
fmt.Println(err.Error())
return
@ -74,8 +69,8 @@ func writeToFile(content []byte) error {
return nil
}
func operate(mensa, day string) (Menu, error) {
meals, err := parseHTML(fmt.Sprintf("https://phpapp2.zvw.uni-goettingen.de/portlet_mensaplan/public/ajaxresponse/getgerichte?mensa=%s&tag=%s&preis=stu&vegetarisch=true&schweinefleisch=true&vegan=true&fisch=true&gefluegel=true&rind=true&wild=true&lamm=true&alkohol=true&knoblauch=true&sonstige_gerichte=true", mensa, day))
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))
if err != nil {
return Menu{}, err
}
@ -90,11 +85,10 @@ func parseHTML(url string) ([]Meal, error) {
}
meals := []Meal{}
doc.Find("table tr").Each(func(i int, s *goquery.Selection) {
doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) {
meal := Meal{
Category: s.Find(".gericht_kategorie").Text(),
Price: s.Find(".gericht_preis").Text(),
Title: s.Find(".spalte_gericht").Text(),
Category: s.Find(".ext_sits_preis").Text(), // yes, really preis
Title: s.Find(".ext_sits_essen").Text(),
}
meals = append(meals, meal)
})

Loading…
Cancel
Save