|
@ -26,9 +26,12 @@ type ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
mensen = []string{ |
|
|
|
|
|
"Zentralmensa", |
|
|
|
|
|
"Nordmensa", |
|
|
|
|
|
|
|
|
mensen = map[string]string{ |
|
|
|
|
|
"Zentralmensa": "zentralmensa", |
|
|
|
|
|
"Nordmensa": "nordmensa", |
|
|
|
|
|
"Mensa+am+Turm": "turmmensa", |
|
|
|
|
|
"Mensa+Italia": "mensaitalia", |
|
|
|
|
|
"Bistro+HAWK": "bistrohawk", |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -38,7 +41,7 @@ func main() { |
|
|
path = os.Args[1] + "/" |
|
|
path = os.Args[1] + "/" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, mensa := range mensen { |
|
|
|
|
|
|
|
|
for mensa := range mensen { |
|
|
for day := 1; day < 8; day = day + 1 { |
|
|
for day := 1; day < 8; day = day + 1 { |
|
|
menu, err := operate(mensa, day) |
|
|
menu, err := operate(mensa, day) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -52,7 +55,7 @@ func main() { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.%v.json", path, strings.ToLower(mensa), day), content, 0644) |
|
|
|
|
|
|
|
|
err = ioutil.WriteFile(fmt.Sprintf("%s/%s.%v.json", path, mensen[mensa], day), content, 0644) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err.Error()) |
|
|
fmt.Println(err.Error()) |
|
|
return |
|
|
return |
|
@ -78,6 +81,12 @@ func operate(mensa string, day int) (Menu, error) { |
|
|
return Menu{Day: day, Mensa: mensa, Meals: meals}, nil |
|
|
return Menu{Day: day, Mensa: mensa, Meals: meals}, nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func strip(old string) string { |
|
|
|
|
|
new := strings.Replace(old, "\t", "", -1) |
|
|
|
|
|
new = strings.Replace(new, "\n", "", -1) |
|
|
|
|
|
return new |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func parseHTML(url string) ([]Meal, error) { |
|
|
func parseHTML(url string) ([]Meal, error) { |
|
|
doc, err := goquery.NewDocument(url) |
|
|
doc, err := goquery.NewDocument(url) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@ -87,8 +96,8 @@ func parseHTML(url string) ([]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{ |
|
|
Category: s.Find(".ext_sits_preis").Text(), // yes, really preis
|
|
|
|
|
|
Title: s.Find(".ext_sits_essen").Text(), |
|
|
|
|
|
|
|
|
Category: strip(s.Find(".ext_sits_preis").Text()), // yes, really preis
|
|
|
|
|
|
Title: strip(s.Find(".ext_sits_essen").Text()), |
|
|
} |
|
|
} |
|
|
meals = append(meals, meal) |
|
|
meals = append(meals, meal) |
|
|
}) |
|
|
}) |
|
|