Documentation
¶
Overview ¶
Package svgastronomie provides functions to fetch the weekly menu of a SV restaurant from sv-gastronomie.de
Index ¶
Constants ¶
const ( BaseURL string = "https://sv-gastronomie.de" MenuURL string = BaseURL + "/menu" MenuTemplateURL string = BaseURL + "/menu/%s/%s" // %s is the restaurant URL )
Below are constants used in the svgastronomie package.
Variables ¶
This section is empty.
Functions ¶
func DefaultCacheDirectories ¶ added in v0.2.0
DefaultCacheDirectories returns the default cache directories for Playwright.
- Windows: %USERPROFILE%\AppData\Local
- macOS: ~/Library/Caches
- Linux: ~/.cache
func EnsureInstalled ¶ added in v0.2.0
func EnsureInstalled()
EnsureInstalled attempts to install Playwright or panics if installation fails.
func EnsureInstalledAndClearTerminal ¶ added in v0.2.1
func EnsureInstalledAndClearTerminal()
EnsureInstalledAndClearTerminal attempts to install Playwright and clears the terminal screen.
func Install ¶
func Install() error
Install installs Playwright by downloading the necessary browser binaries.
func IsInstalled ¶ added in v0.2.0
func IsInstalled() bool
IsInstalled checks if Playwright is usable by attempting to start and stop it.
func Uninstall ¶ added in v0.2.0
func Uninstall() error
Uninstall deletes the playwright cache dir which equals to uninstalling playwright.
func ValidateURL ¶ added in v0.2.2
ValidateURL checks if the given URL is valid for scraping.
Types ¶
type Day ¶
type Day struct {
Time time.Time `json:"time"` // Time is the current date in the format YYYY-MM-DD 00:00:00 UTC.
Dishes []Dish `json:"dishes"`
}
Day represents the menu for a specific day.
type Dish ¶
type Dish struct {
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
Tags []string `json:"tags"`
}
Dish represents a single dish available on a specific day.
type Restaurant ¶
type Restaurant struct {
URL string `json:"url"`
Location string `json:"location"`
MenuCard string `json:"menu_card"`
Week Week `json:"week"`
}
Restaurant represents a restaurant available on sv-gastronomie.de.
func ScrapeRestaurant ¶
func ScrapeRestaurant( url string, handleNewDay func(day Day), ) (*Restaurant, error)
ScrapeRestaurant scrapes the restaurant's page and returns a Restaurant object.
Playwright needs to be installed for this function to work.
Use sv.EnsureInstalled() or sv.Install() dependind on your needs before calling this function.
The handleNewDay is an optional callback function that can be used to handle new days as they are scraped.
Browser automation flow is sequential and clearer as one function.