Skip to content

Commit

Permalink
fix: green star not being populated correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ngshiheng committed Nov 15, 2024
1 parent 06fbfdd commit 20b13a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,9 @@ func (a *App) Crawl() {
address = strings.Replace(address, "\n", " ", -1)

description := e.ChildText(restaurantDescriptionXPath)
distinction := e.ChildText(restaurantDistinctionXPath)

distinctions := e.ChildTexts(restaurantDistinctionXPath)
distinction := michelin.SelectedRestaurants
if len(distinctions) > 0 {
distinction = parser.ParseDistinction(distinctions[0])
}

greenStar := false
if len(distinctions) > 1 {
greenStar = parser.ParseGreenStar(distinctions[len(distinctions)-1])
}
greenStar := e.ChildText(restaurantGreenStarXPath)

priceAndCuisine := e.ChildText(restaurantPriceAndCuisineXPath)
price, cuisine := parser.SplitUnpack(priceAndCuisine, "·")
Expand All @@ -356,9 +348,9 @@ func (a *App) Crawl() {
Address: address,
Cuisine: cuisine,
Description: parser.TrimWhiteSpaces(description),
Distinction: distinction,
Distinction: parser.ParseDistinction(distinction),
FacilitiesAndServices: strings.Join(facilitiesAndServices, ","),
GreenStar: greenStar,
GreenStar: parser.ParseGreenStar(greenStar),
Location: e.Request.Ctx.Get("location"),
Latitude: e.Request.Ctx.Get("latitude"),
Longitude: e.Request.Ctx.Get("longitude"),
Expand Down
1 change: 1 addition & 0 deletions pkg/crawler/xpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
restaurantAddressXPath = "//*[@class='data-sheet__block--text'][1]"
restaurantDescriptionXPath = "//*[@class='data-sheet__description']"
restaurantDistinctionXPath = "//*[@class='data-sheet__classification-item--content'][2]"
restaurantGreenStarXPath = "//*[@class='classfication-content' and contains(text(),'Green Star')]"
restaurantFacilitiesAndServicesXPath = "//*[@class='restaurant-details__services']//li"
restaurantGoogleMapsXPath = "//*[@class='google-map__static']/iframe"
restaurantNameXPath = "//*[@class='data-sheet__title']"
Expand Down

0 comments on commit 20b13a7

Please sign in to comment.