Skip to content

Commit 96851ad

Browse files
committed
feat: add GreenStar column to indicate that restaurant has a MICHELIN Green Star award
1 parent f56caa4 commit 96851ad

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

pkg/crawler/crawler.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ func (a *App) Crawl() {
148148
description := e.ChildText(restaurantDescriptionXPath)
149149

150150
distinctions := e.ChildTexts(restaurantDistinctionXPath)
151-
distinction := parser.ParseDistinction(distinctions[0]) // NOTE: [Three Stars: Exceptional cuisine MICHELIN Green Star]
152-
if distinction == "" {
153-
log.WithFields(log.Fields{"url": url, "distinctions": distinctions}).Warn("invalid distinctions")
151+
distinction := parser.ParseDistinction(distinctions[0])
152+
greenStar := false
153+
if len(distinctions) > 1 {
154+
greenStar = parser.ParseDistinction(distinctions[len(distinctions)-1]) == michelin.GreenStar
154155
}
156+
155157
priceAndCuisine := e.ChildText(restaurantPriceAndCuisineXPath)
156158
price, cuisine := parser.SplitUnpack(priceAndCuisine, "·")
157159

@@ -174,6 +176,7 @@ func (a *App) Crawl() {
174176
Description: parser.TrimWhiteSpaces(description),
175177
Distinction: distinction,
176178
FacilitiesAndServices: strings.Join(facilitiesAndServices, ","),
179+
GreenStar: greenStar,
177180
Latitude: e.Request.Ctx.Get("latitude"),
178181
Location: e.Request.Ctx.Get("location"),
179182
Longitude: e.Request.Ctx.Get("longitude"),

pkg/michelin/restaurant.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Restaurant struct {
99
Description string
1010
Distinction string // Comma-separated string
1111
FacilitiesAndServices string // Comma-separated string
12+
GreenStar bool
1213
Latitude string
1314
Location string
1415
Longitude string

pkg/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func ParseDistinction(distinction string) string {
4949
case "michelin green star":
5050
return michelin.GreenStar
5151
default:
52+
log.WithFields(log.Fields{"distinctions": distinction}).Warn("invalid distinctions")
5253
return ""
5354
}
5455
}

0 commit comments

Comments
 (0)