Compare commits
3 Commits
e92675574a
...
a7591c9868
Author | SHA1 | Date | |
---|---|---|---|
a7591c9868 | |||
07b6b6722d | |||
82bf2a1ea4 |
@ -54,14 +54,17 @@ func refresh(c *gin.Context) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
restaurants = append(restaurants, r.NewFreshRestaurant("http://www.fresh-menu.cz/", "Fresh"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/2752-u-drevaka-beergrill.html", "U Dřeváka"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/4116-padagali.html", "Padagali"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/5448-light-of-india.html", "Light of India"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/2609-pizzeria-al-capone.html", "Al Capone"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/3830-suzies-steak-pub.html", "Suzie's"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/6468-diva-bara.html", "Divá Bára"))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/6695-u-karla.html", "U Karla"))
|
||||
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/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/2609-pizzeria-al-capone.html", "Al Capone", 5))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/3830-suzies-steak-pub.html", "Suzie's", 6))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/6468-diva-bara.html", "Divá Bára", 7))
|
||||
restaurants = append(restaurants, r.NewMenickaRestaurant("https://www.menicka.cz/6695-u-karla.html", "U Karla", 8))
|
||||
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))
|
||||
|
||||
refreshInternal()
|
||||
fmt.Println("Initial parsing finished")
|
||||
|
@ -15,17 +15,10 @@ type FreshRestaurant struct {
|
||||
Restaurant
|
||||
}
|
||||
|
||||
func MakeFreshRestaurant(url string, name string) FreshRestaurant {
|
||||
restaurant := FreshRestaurant{}
|
||||
restaurant.SetDefaultValues()
|
||||
restaurant.url = url
|
||||
restaurant.name = name
|
||||
return restaurant
|
||||
}
|
||||
|
||||
func NewFreshRestaurant(url string, name string) *FreshRestaurant {
|
||||
func NewFreshRestaurant(url string, name string, id int) *FreshRestaurant {
|
||||
restaurant := new(FreshRestaurant)
|
||||
restaurant.SetDefaultValues()
|
||||
restaurant.id = id
|
||||
restaurant.url = url
|
||||
restaurant.name = name
|
||||
return restaurant
|
||||
|
@ -14,17 +14,10 @@ type MenickaRestaurant struct {
|
||||
Restaurant
|
||||
}
|
||||
|
||||
func MakeMenickaRestaurant(url string, name string) MenickaRestaurant {
|
||||
restaurant := MenickaRestaurant{}
|
||||
restaurant.SetDefaultValues()
|
||||
restaurant.url = url
|
||||
restaurant.name = name
|
||||
return restaurant
|
||||
}
|
||||
|
||||
func NewMenickaRestaurant(url string, name string) *MenickaRestaurant {
|
||||
func NewMenickaRestaurant(url string, name string, id int) *MenickaRestaurant {
|
||||
restaurant := new(MenickaRestaurant)
|
||||
restaurant.SetDefaultValues()
|
||||
restaurant.id = id
|
||||
restaurant.url = url
|
||||
restaurant.name = name
|
||||
return restaurant
|
||||
|
@ -16,6 +16,7 @@ type RestaurantInterface interface {
|
||||
|
||||
type Restaurant struct {
|
||||
RestaurantInterface
|
||||
id int
|
||||
url string
|
||||
name string
|
||||
menus [7]Menu
|
||||
@ -23,6 +24,7 @@ type Restaurant struct {
|
||||
}
|
||||
|
||||
type RestaurantJSON struct {
|
||||
Id int `json:"id"`
|
||||
Restaurant string `json:"restaurant"`
|
||||
DailyMenus []Menu `json:"dailymenus"`
|
||||
PermanentMeals []Meal `json:"permanentmeals"`
|
||||
@ -55,6 +57,7 @@ func (restaurant *Restaurant) clearMenus() {
|
||||
|
||||
func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(&RestaurantJSON{
|
||||
Id: restaurant.id,
|
||||
Restaurant: restaurant.name,
|
||||
DailyMenus: restaurant.menus[:],
|
||||
PermanentMeals: restaurant.permanent,
|
||||
|
104
pkg/restaurants/tao.go
Normal file
104
pkg/restaurants/tao.go
Normal file
@ -0,0 +1,104 @@
|
||||
package restaurants
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
type TaoRestaurant struct {
|
||||
Restaurant
|
||||
}
|
||||
|
||||
func NewTaoRestaurant(url string, name string, id int) *TaoRestaurant {
|
||||
restaurant := new(TaoRestaurant)
|
||||
restaurant.SetDefaultValues()
|
||||
restaurant.id = id
|
||||
restaurant.url = url
|
||||
restaurant.name = name
|
||||
return restaurant
|
||||
}
|
||||
|
||||
func (restaurant *TaoRestaurant) Parse() {
|
||||
restaurant.clearMenus()
|
||||
resp, err := http.Get(restaurant.url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
doc, err := html.Parse(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// first occurence of tydenni-menu-div
|
||||
daily, err := findNodeByClass(doc, "ct-div-block tydenni-menu-div")
|
||||
if err != nil {
|
||||
fmt.Printf("Couldn't find content for restaurant \"%s\"\n", restaurant.name)
|
||||
return
|
||||
}
|
||||
for menu := daily; menu != nil; menu = menu.NextSibling {
|
||||
nameNode, err := findNodeByClass(menu, "ct-span")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
nameText, err := getText(nameNode)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
textElements := strings.Split(nameText, "..")
|
||||
meal := textElements[0]
|
||||
priceText := textElements[len(textElements)-1]
|
||||
priceNum := -1
|
||||
soup := false
|
||||
if len(priceText) < 2 {
|
||||
soup = true
|
||||
} else {
|
||||
priceNum, err = strconv.Atoi(strings.TrimLeft(strings.TrimSpace(strings.Split(priceText, "k")[0]), "."))
|
||||
if err != nil {
|
||||
priceNum = -1
|
||||
}
|
||||
}
|
||||
restaurant.AddPermanent(soup, strings.TrimSpace(meal), "", priceNum)
|
||||
}
|
||||
|
||||
special := daily.Parent.NextSibling.NextSibling
|
||||
for i := 0; i < 5; i++ {
|
||||
nameNode, err := findNodeByClass(special, "ct-span")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
nameText, err := getText(nameNode)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
textElements := strings.Split(nameText, "..")
|
||||
meal := textElements[0]
|
||||
priceText := textElements[len(textElements)-1]
|
||||
priceNum := -1
|
||||
soup := false
|
||||
if len(priceText) == 0 {
|
||||
soup = true
|
||||
} else {
|
||||
priceNum, err = strconv.Atoi(strings.TrimLeft(strings.TrimSpace(strings.Split(priceText, "k")[0]), "."))
|
||||
if err != nil {
|
||||
priceNum = -1
|
||||
}
|
||||
}
|
||||
restaurant.menus[i].Add(soup, strings.TrimSpace(meal), "", priceNum)
|
||||
special = special.NextSibling
|
||||
}
|
||||
restaurant.menus[0].SetDay("Monday")
|
||||
restaurant.menus[1].SetDay("Tuesday")
|
||||
restaurant.menus[2].SetDay("Wednesday")
|
||||
restaurant.menus[3].SetDay("Thursday")
|
||||
restaurant.menus[4].SetDay("Friday")
|
||||
restaurant.menus[5].SetDay("Saturday")
|
||||
restaurant.menus[6].SetDay("Sunday")
|
||||
}
|
Loading…
Reference in New Issue
Block a user