From 66b853e5d32fa961d602a8bcfdc85b37bcd35ad7 Mon Sep 17 00:00:00 2001 From: angerstoner Date: Fri, 6 Apr 2018 23:22:06 +0200 Subject: [PATCH 1/3] added diet to json --- server/server.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/server.go b/server/server.go index 984c949..5954c7f 100644 --- a/server/server.go +++ b/server/server.go @@ -18,6 +18,7 @@ type ( Category string `json:"category"` Price string `json:"price"` Title string `json:"title"` + Diet string `json:"diet"` } // Menu contains all info to menues in a mensa on one day Menu struct { @@ -109,9 +110,11 @@ func strip(old string) string { func parseMeals(doc *goquery.Document) ([]Meal, error) { meals := []Meal{} doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { + diet, _ := s.Find(".ext_sits_speiseplan_icon").Children().Attr("alt") meal := Meal{ Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis Title: strip(s.Find(".ext_sits_essen").Text()), + Diet: strip(diet), } meals = append(meals, meal) }) From 22ef69669247259aab55016b747e06be3f97d50b Mon Sep 17 00:00:00 2001 From: angerstoner Date: Fri, 6 Apr 2018 23:22:06 +0200 Subject: [PATCH 2/3] added diet to json --- server/server.go | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/server/server.go b/server/server.go index 0966f18..842386f 100644 --- a/server/server.go +++ b/server/server.go @@ -13,19 +13,20 @@ import ( ) type ( - // Meal contains the info about a meals - Meal struct { - Category string `json:"category"` - Price string `json:"price"` - Title string `json:"title"` - } - // Menu contains all info to menues in a mensa on one day - Menu struct { - Day int `json:"day"` - Mensa string `json:"mensa"` - Meals []Meal `json:"meals"` - Date string `json:"date"` - } + // Meal contains the info about a meals + Meal struct { + Category string `json:"category"` + Price string `json:"price"` + Title string `json:"title"` + Diet string `json:"diet"` + } + // Menu contains all info to menues in a mensa on one day + Menu struct { + Day int `json:"day"` + Mensa string `json:"mensa"` + Meals []Meal `json:"meals"` + Date string `json:"date"` + } ) var ( @@ -107,13 +108,15 @@ func strip(old string) string { } 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{ - Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis - Title: strip(s.Find(".ext_sits_essen").Text()), - } - meals = append(meals, meal) - }) - return meals, nil + meals := []Meal{} + doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { + diet, _ := s.Find(".ext_sits_speiseplan_icon").Children().Attr("alt") + meal := Meal{ + Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis + Title: strip(s.Find(".ext_sits_essen").Text()), + Diet: strip(diet), + } + meals = append(meals, meal) + }) + return meals, nil } From 46daf554fc8a171c68ff39a0ace8b59e1779fbc7 Mon Sep 17 00:00:00 2001 From: angerstoner Date: Fri, 6 Apr 2018 23:44:56 +0200 Subject: [PATCH 3/3] formatted using gofmt --- server/server.go | 50 ++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/server/server.go b/server/server.go index 842386f..8419c5e 100644 --- a/server/server.go +++ b/server/server.go @@ -13,20 +13,20 @@ import ( ) type ( - // Meal contains the info about a meals - Meal struct { - Category string `json:"category"` - Price string `json:"price"` - Title string `json:"title"` - Diet string `json:"diet"` - } - // Menu contains all info to menues in a mensa on one day - Menu struct { - Day int `json:"day"` - Mensa string `json:"mensa"` - Meals []Meal `json:"meals"` - Date string `json:"date"` - } + // Meal contains the info about a meals + Meal struct { + Category string `json:"category"` + Price string `json:"price"` + Title string `json:"title"` + Diet string `json:"diet"` + } + // Menu contains all info to menues in a mensa on one day + Menu struct { + Day int `json:"day"` + Mensa string `json:"mensa"` + Meals []Meal `json:"meals"` + Date string `json:"date"` + } ) var ( @@ -108,15 +108,15 @@ func strip(old string) string { } func parseMeals(doc *goquery.Document) ([]Meal, error) { - meals := []Meal{} - doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { - diet, _ := s.Find(".ext_sits_speiseplan_icon").Children().Attr("alt") - meal := Meal{ - Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis - Title: strip(s.Find(".ext_sits_essen").Text()), - Diet: strip(diet), - } - meals = append(meals, meal) - }) - return meals, nil + meals := []Meal{} + doc.Find("table.speise-tblmain tbody tr").Each(func(i int, s *goquery.Selection) { + diet, _ := s.Find(".ext_sits_speiseplan_icon").Children().Attr("alt") + meal := Meal{ + Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis + Title: strip(s.Find(".ext_sits_essen").Text()), + Diet: strip(diet), + } + meals = append(meals, meal) + }) + return meals, nil }