forked from zv0n/lunch-go
Fresh's triumphant return
This commit is contained in:
parent
1aab0d7a4f
commit
4a9f5296a5
@ -54,7 +54,7 @@ func refresh(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//restaurants = append(restaurants, r.NewFreshRestaurant("http://www.fresh-menu.cz/", "Fresh", 1))
|
restaurants = append(restaurants, r.NewFreshRestaurant("http://www.fresh-menu.cz/", "Fresh", 1))
|
||||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/2752-u-drevaka-beergrill.html", "U Dřeváka", 2))
|
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/2752-u-drevaka-beergrill.html", "U Dřeváka", 2))
|
||||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/4116-padagali.html", "Padagali", 3))
|
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/4116-padagali.html", "Padagali", 3))
|
||||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/5448-light-of-india.html", "Light of India", 4))
|
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/5448-light-of-india.html", "Light of India", 4))
|
||||||
|
@ -24,7 +24,31 @@ func NewFreshRestaurant(url string, name string, id int) *FreshRestaurant {
|
|||||||
return restaurant
|
return restaurant
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIndexFromDay(line string) int {
|
||||||
|
if len(line) < 3 || line[:3] == "Pol" {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
ascii := line[:2]
|
||||||
|
unicode := line[:3]
|
||||||
|
if ascii == "Po" {
|
||||||
|
return 0
|
||||||
|
} else if unicode == "Út" {
|
||||||
|
return 1
|
||||||
|
} else if ascii == "St" {
|
||||||
|
return 2
|
||||||
|
} else if unicode == "Čt" {
|
||||||
|
return 3
|
||||||
|
} else if unicode == "Pá" {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func (restaurant *FreshRestaurant) Parse() {
|
func (restaurant *FreshRestaurant) Parse() {
|
||||||
|
defer func() {
|
||||||
|
recover()
|
||||||
|
}()
|
||||||
|
|
||||||
restaurant.clearMenus()
|
restaurant.clearMenus()
|
||||||
resp, err := http.Get(restaurant.url)
|
resp, err := http.Get(restaurant.url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -62,12 +86,16 @@ func (restaurant *FreshRestaurant) Parse() {
|
|||||||
meals := [5][]string{}
|
meals := [5][]string{}
|
||||||
prices := [5][]int{}
|
prices := [5][]int{}
|
||||||
scanner := bufio.NewScanner(strings.NewReader(pdftxt.Body))
|
scanner := bufio.NewScanner(strings.NewReader(pdftxt.Body))
|
||||||
curIndex := -1
|
curIndex := 0
|
||||||
pricesIndex := -1
|
pricesIndex := -1
|
||||||
pricesSection := false
|
pricesSection := false
|
||||||
emptyLine := false
|
emptyLine := false
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
|
dayIndex := getIndexFromDay(line)
|
||||||
|
if dayIndex != -1 {
|
||||||
|
curIndex = dayIndex
|
||||||
|
}
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
emptyLine = true
|
emptyLine = true
|
||||||
pricesSection = false
|
pricesSection = false
|
||||||
@ -80,13 +108,9 @@ func (restaurant *FreshRestaurant) Parse() {
|
|||||||
emptyLine = false
|
emptyLine = false
|
||||||
// 10 because soup name starts after 10 and vacations have no soup provided
|
// 10 because soup name starts after 10 and vacations have no soup provided
|
||||||
if !pricesSection && len(line) > 10 && line[:3] == "Pol" {
|
if !pricesSection && len(line) > 10 && line[:3] == "Pol" {
|
||||||
curIndex++
|
|
||||||
meals[curIndex] = append(meals[curIndex], line[10:])
|
meals[curIndex] = append(meals[curIndex], line[10:])
|
||||||
prices[curIndex] = append(prices[curIndex], -1)
|
prices[curIndex] = append(prices[curIndex], -1)
|
||||||
}
|
}
|
||||||
if curIndex < 0 {
|
|
||||||
curIndex++
|
|
||||||
}
|
|
||||||
if !pricesSection && line[1] == '.' && len(line) > 2 {
|
if !pricesSection && line[1] == '.' && len(line) > 2 {
|
||||||
meals[curIndex] = append(meals[curIndex], line[3:])
|
meals[curIndex] = append(meals[curIndex], line[3:])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user