diff options
author | Franck Cuny <franck@fcuny.net> | 2024-03-12 19:43:43 -0700 |
---|---|---|
committer | Franck Cuny <franck@fcuny.net> | 2024-03-12 19:44:39 -0700 |
commit | b39c79e8c2ab65ba1e09380748467e9a9bc86260 (patch) | |
tree | c1d47950f4b2fe7c2a1bb8ec800e9305e1828efc /cmd | |
parent | fix a typo and update 1password config (diff) | |
download | world-b39c79e8c2ab65ba1e09380748467e9a9bc86260.tar.gz |
`cbpt` get cheeseboard's pizza for the week
For example: ``` Tue Mar 12: Cremini mushroom, red onion, goat cheese, mozzarella, garlic olive oil, oregano, parsley Wed Mar 13: The Cheese Board Margherita: Crushed tomato, fresh mozzarella made in Berkeley by Belfiore, mozzarella, garlic olive oil, fresh basil Thu Mar 14: Organic cauliflower (Avalos Farm), green onion, mozzarella, house made arugula-pistachio pesto Fri Mar 15: Our first asparagus pizza of the season!Fresh asparagus, cremini and baby shiitake mushroom, gouda cheese, mozzarella, garlic olive oil, parsley Sat Mar 16: A celebration of St. Patrick's Day!Roasted Yukon Gold potato, caramelized onion, Irish cheddar cheese, mozzarella, garlic olive oil, oregano, parsley ```
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/cbpt/main.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/cbpt/main.go b/cmd/cbpt/main.go new file mode 100644 index 0000000..075f084 --- /dev/null +++ b/cmd/cbpt/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "fmt" + "regexp" + "strings" + + "github.com/gocolly/colly" +) + +const ( + cheeseboardURL = "https://cheeseboardcollective.coop/pizza/" +) + +var ( + boilerPlateParBake = regexp.MustCompile(`Parbake pizza is available in the bakery from \d a.m. to \d p.m., while supplies last.`) + boilerPlateParBakeLunch = regexp.MustCompile(`Parbake pizza is available in the bakery from \d a.m. to \d p.m..Lunch from 1\d:30-\d:30 and dinner from \d-\d.`) + boilerPlateNoHotPizza = regexp.MustCompile(`No hot pizza today.`) + cheeseboardIsClosed = regexp.MustCompile(`The Pizzeria is closed today`) +) + +type Pizza struct { + Date string + Toppings string +} + +func main() { + c := colly.NewCollector() + + c.OnRequest(func(r *colly.Request) { + fmt.Println("Visiting", r.URL) + }) + + var pizzas []Pizza + + c.OnHTML("div.pizza-list", func(e *colly.HTMLElement) { + e.ForEach("article", func(c int, el *colly.HTMLElement) { + var pizza Pizza + pizza.Date = el.ChildText("div.date") + toppings := el.ChildText("div.menu > p:nth-child(2)") + if cheeseboardIsClosed.MatchString(toppings) { + return + } + toppings = boilerPlateParBake.ReplaceAllString(toppings, "") + toppings = boilerPlateParBakeLunch.ReplaceAllString(toppings, "") + toppings = boilerPlateNoHotPizza.ReplaceAllString(toppings, "") + toppings = strings.TrimLeft(toppings, " ") + pizza.Toppings = toppings + pizzas = append(pizzas, pizza) + }) + }) + + c.Visit(cheeseboardURL) + for _, pizza := range pizzas { + fmt.Printf("%s: %s\n", pizza.Date, pizza.Toppings) + } +} |