mirror of
https://github.com/LeRoid-hub/Mensa-API.git
synced 2025-01-31 03:34:57 +00:00
propper models
This commit is contained in:
parent
65013d6f12
commit
a5bb066df0
@ -5,3 +5,9 @@ type Meal struct {
|
||||
Price string
|
||||
Attributes string
|
||||
}
|
||||
|
||||
func (m *Meal) SetMeal(name string, price string, attributes string) {
|
||||
m.Name = name
|
||||
m.Price = price
|
||||
m.Attributes = attributes
|
||||
}
|
||||
|
@ -4,3 +4,11 @@ type Menu struct {
|
||||
Name string
|
||||
Meal []Meal
|
||||
}
|
||||
|
||||
func (m *Menu) SetMenu(name string) {
|
||||
m.Name = name
|
||||
}
|
||||
|
||||
func (m *Menu) AddMeal(meal Meal) {
|
||||
m.Meal = append(m.Meal, meal)
|
||||
}
|
||||
|
@ -4,3 +4,11 @@ type Day struct {
|
||||
DayName string
|
||||
Menu []Menu
|
||||
}
|
||||
|
||||
func (d *Day) SetDay(dayName string) {
|
||||
d.DayName = dayName
|
||||
}
|
||||
|
||||
func (d *Day) AddMenu(menu Menu) {
|
||||
d.Menu = append(d.Menu, menu)
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
|
||||
func ScrapeMensa(h io.ReadCloser) models.Mensa {
|
||||
var mensa models.Mensa
|
||||
var mensaName = ""
|
||||
var mensaLocation = ""
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(h)
|
||||
if err != nil {
|
||||
@ -17,7 +19,7 @@ func ScrapeMensa(h io.ReadCloser) models.Mensa {
|
||||
}
|
||||
|
||||
doc.Find("h1.aw-title-header-title").First().Each(func(i int, s *goquery.Selection) {
|
||||
mensa.Name = s.Text()
|
||||
mensaName = s.Text()
|
||||
})
|
||||
|
||||
doc.Find("a.panel-body").Each(func(i int, s *goquery.Selection) {
|
||||
@ -29,14 +31,16 @@ func ScrapeMensa(h io.ReadCloser) models.Mensa {
|
||||
l = strings.Replace(l, "<br>", " ", -1)
|
||||
l = strings.Replace(l, "</br>", " ", -1)
|
||||
|
||||
mensa.Location = l
|
||||
mensaLocation = l
|
||||
})
|
||||
|
||||
mensa.SetMensa(mensaName, mensaLocation)
|
||||
|
||||
//Day
|
||||
var day models.Day
|
||||
|
||||
doc.Find("h2.aw-menu-title").Each(func(i int, s *goquery.Selection) {
|
||||
day.DayName = s.Text()
|
||||
day.SetDay(s.Text())
|
||||
})
|
||||
|
||||
//Menu
|
||||
@ -45,25 +49,29 @@ func ScrapeMensa(h io.ReadCloser) models.Mensa {
|
||||
var menu models.Menu
|
||||
|
||||
s.Find("h3.aw-meal-category-name").Each(func(i int, t *goquery.Selection) {
|
||||
menu.Name = t.Text()
|
||||
menu.SetMenu(t.Text())
|
||||
})
|
||||
|
||||
//Meal
|
||||
var meal models.Meal
|
||||
|
||||
s.Find("div.aw-meal").Each(func(i int, t *goquery.Selection) {
|
||||
mealName := ""
|
||||
mealPrice := ""
|
||||
mealAttributes := ""
|
||||
t.Find("p.aw-meal-description").First().Each(func(i int, u *goquery.Selection) {
|
||||
meal.Name = u.Text()
|
||||
mealName = u.Text()
|
||||
})
|
||||
t.Find("div.aw-meal-price").First().Each(func(i int, u *goquery.Selection) {
|
||||
meal.Price = u.Text()
|
||||
mealPrice = u.Text()
|
||||
})
|
||||
t.Find("p.aw-meal-attributes").First().Each(func(i int, u *goquery.Selection) {
|
||||
meal.Attributes = u.Text()
|
||||
mealAttributes = u.Text()
|
||||
})
|
||||
menu.Meal = append(menu.Meal, meal)
|
||||
meal.SetMeal(mealName, mealPrice, mealAttributes)
|
||||
menu.AddMeal(meal)
|
||||
})
|
||||
day.Menu = append(day.Menu, menu)
|
||||
day.AddMenu(menu)
|
||||
})
|
||||
mensa.AddDay(day)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user