Compare commits
No commits in common. "a7591c9868dab6e243fb687f2cb50801f645957b" and "e92675574a14a89e3430e276a85e38e5b849759d" have entirely different histories.
a7591c9868
...
e92675574a
@ -54,17 +54,14 @@ 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"))
|
||||||
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"))
|
||||||
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"))
|
||||||
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"))
|
||||||
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/2609-pizzeria-al-capone.html", "Al Capone"))
|
||||||
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/3830-suzies-steak-pub.html", "Suzie's"))
|
||||||
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/6468-diva-bara.html", "Divá Bára"))
|
||||||
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/6695-u-karla.html", "U Karla"))
|
||||||
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()
|
refreshInternal()
|
||||||
fmt.Println("Initial parsing finished")
|
fmt.Println("Initial parsing finished")
|
||||||
|
@ -15,10 +15,17 @@ type FreshRestaurant struct {
|
|||||||
Restaurant
|
Restaurant
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFreshRestaurant(url string, name string, id int) *FreshRestaurant {
|
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 {
|
||||||
restaurant := new(FreshRestaurant)
|
restaurant := new(FreshRestaurant)
|
||||||
restaurant.SetDefaultValues()
|
restaurant.SetDefaultValues()
|
||||||
restaurant.id = id
|
|
||||||
restaurant.url = url
|
restaurant.url = url
|
||||||
restaurant.name = name
|
restaurant.name = name
|
||||||
return restaurant
|
return restaurant
|
||||||
|
@ -14,10 +14,17 @@ type MenickaRestaurant struct {
|
|||||||
Restaurant
|
Restaurant
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMenickaRestaurant(url string, name string, id int) *MenickaRestaurant {
|
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 {
|
||||||
restaurant := new(MenickaRestaurant)
|
restaurant := new(MenickaRestaurant)
|
||||||
restaurant.SetDefaultValues()
|
restaurant.SetDefaultValues()
|
||||||
restaurant.id = id
|
|
||||||
restaurant.url = url
|
restaurant.url = url
|
||||||
restaurant.name = name
|
restaurant.name = name
|
||||||
return restaurant
|
return restaurant
|
||||||
|
@ -16,7 +16,6 @@ type RestaurantInterface interface {
|
|||||||
|
|
||||||
type Restaurant struct {
|
type Restaurant struct {
|
||||||
RestaurantInterface
|
RestaurantInterface
|
||||||
id int
|
|
||||||
url string
|
url string
|
||||||
name string
|
name string
|
||||||
menus [7]Menu
|
menus [7]Menu
|
||||||
@ -24,7 +23,6 @@ type Restaurant struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RestaurantJSON struct {
|
type RestaurantJSON struct {
|
||||||
Id int `json:"id"`
|
|
||||||
Restaurant string `json:"restaurant"`
|
Restaurant string `json:"restaurant"`
|
||||||
DailyMenus []Menu `json:"dailymenus"`
|
DailyMenus []Menu `json:"dailymenus"`
|
||||||
PermanentMeals []Meal `json:"permanentmeals"`
|
PermanentMeals []Meal `json:"permanentmeals"`
|
||||||
@ -57,7 +55,6 @@ func (restaurant *Restaurant) clearMenus() {
|
|||||||
|
|
||||||
func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
|
func (restaurant *Restaurant) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(&RestaurantJSON{
|
return json.Marshal(&RestaurantJSON{
|
||||||
Id: restaurant.id,
|
|
||||||
Restaurant: restaurant.name,
|
Restaurant: restaurant.name,
|
||||||
DailyMenus: restaurant.menus[:],
|
DailyMenus: restaurant.menus[:],
|
||||||
PermanentMeals: restaurant.permanent,
|
PermanentMeals: restaurant.permanent,
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
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