6 Commits

Author SHA1 Message Date
zv0n 4a9f5296a5 Fresh's triumphant return 2024-04-10 20:01:35 +02:00
zv0n 1aab0d7a4f Temporarily disable Fresh 2024-01-08 09:25:37 +01:00
zv0n ff80a109e8 Fix Fresh parsing 2024-01-03 21:45:55 +01:00
zv0n 09ed5c108e Add restaurant 'Na Růžku' 2023-10-05 11:51:47 +02:00
zv0n a37ef637ce Tao: clear permanent menu before each parse 2023-08-27 17:49:46 +02:00
zv0n a270bf12ff Restaurant: fix JSON marshalling 2023-08-27 17:49:30 +02:00
4 changed files with 36 additions and 2 deletions
+1
View File
@@ -65,6 +65,7 @@ func main() {
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/7470-the-immigrant-.html", "The Immigrant", 9))
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/2721-selepka.html", "Šelepka", 10))
restaurants = append(restaurants, r.NewTaoRestaurant("https://www.taorestaurant.cz/tydenni_menu/nabidka/", "Tao", 11))
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/3854-na-ruzku.html", "Na Růžku", 12))
refreshInternal()
fmt.Println("Initial parsing finished")
+29 -2
View File
@@ -24,7 +24,31 @@ func NewFreshRestaurant(url string, name string, id int) *FreshRestaurant {
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() {
defer func() {
recover()
}()
restaurant.clearMenus()
resp, err := http.Get(restaurant.url)
if err != nil {
@@ -62,12 +86,16 @@ func (restaurant *FreshRestaurant) Parse() {
meals := [5][]string{}
prices := [5][]int{}
scanner := bufio.NewScanner(strings.NewReader(pdftxt.Body))
curIndex := -1
curIndex := 0
pricesIndex := -1
pricesSection := false
emptyLine := false
for scanner.Scan() {
line := scanner.Text()
dayIndex := getIndexFromDay(line)
if dayIndex != -1 {
curIndex = dayIndex
}
if len(line) == 0 {
emptyLine = true
pricesSection = false
@@ -80,7 +108,6 @@ func (restaurant *FreshRestaurant) Parse() {
emptyLine = false
// 10 because soup name starts after 10 and vacations have no soup provided
if !pricesSection && len(line) > 10 && line[:3] == "Pol" {
curIndex++
meals[curIndex] = append(meals[curIndex], line[10:])
prices[curIndex] = append(prices[curIndex], -1)
}
+5
View File
@@ -55,6 +55,10 @@ func (restaurant *Restaurant) clearMenus() {
}
}
func (restaurant *Restaurant) clearPermanentMenus() {
restaurant.permanent = []Meal{}
}
func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
return json.Marshal(&RestaurantJSON{
Id: restaurant.id,
@@ -66,6 +70,7 @@ func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
func (restaurant *Restaurant) GetSpecificDayObject(days []int) RestaurantJSON {
obj := RestaurantJSON{
Id: restaurant.id,
Restaurant: restaurant.name,
PermanentMeals: restaurant.permanent,
}
+1
View File
@@ -24,6 +24,7 @@ func NewTaoRestaurant(url string, name string, id int) *TaoRestaurant {
func (restaurant *TaoRestaurant) Parse() {
restaurant.clearMenus()
restaurant.clearPermanentMenus()
resp, err := http.Get(restaurant.url)
if err != nil {
return