bananas

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

README

Bananas

GoDoc Go Report Card

Bananas is a Go library for interfacing with the dining hall menus at the University of California Santa Cruz

Usage

See the godoc linked above.

Documentation

Overview

Package bananas is a Go library for interfacing with the dining hall menus at the University of California Santa Cruz

Origins

At UCSC there are five (5) dining halls. One for each pair of colleges in the ten college system.

Each dining hall has it's own menu that can be viewed online here: https://nutrition.sa.ucsc.edu Many students have built third party menu viewers -- each with their own method of parsing the website (manual web scraping is necessary as there is no public API). And this is where bananas comes in. Bananas will serve as the engine for a new API server that is in development, so that students can build custom web views, apps etc. .

Bananas will also be available for everyone, so that they too can build awesome stuff with it.

Usage

To use bananas simply call MenuFor with one item from each of the following lists:

Dining Halls (Choose one (1)):

bananas.PorterKresge // Porter and Kresge Dining Hall
bananas.NineTen // College Nine and Ten Dining Hall
bananas.CowellStevenson // Cowell and Steventson Dining Hall
bananas.CarsonOakes // Rachel Carson and Oakes Dining Hall
bananas.CrownMerrill // Crown and Merrill Dining Hall

Meals (Choose one (1)):

bananas.Breakfast // For breakfast
bananas.Lunch // For lunch
bananas.Dinner // For dinner
bananas.LateNight // For late night

Time:

Any struct that is time.Time will satisfy this parameter. Note that the actual time (e.g 12:00PM) is ignored and only the date is used.

Examples

Here are some common uses for bananas.

// Get the lunch menu for today's meal at RCC and Oakes Dining Hall.
banana.MenuFor(bananas.CarsonOakes, bananas.Lunch, time.Now())

// For tomorrow's dinner menu at College 9 & 10.
banana.MenuFor(bananas.NineTen, bananas.Dinner, time.Now().Add(24 * time.Hour))

Note that each of these calls will make two (2) http requests. One for the menu data, and another to set the cookies.

If you would like to only have one http request per call use bananas.Client

// Make a client.
c := bananas.Client{}
// Get the menu as normal.
c.MenuFor(bananas.CarsonOakes, bananas.Lunch, time.Now())

Index

Constants

This section is empty.

Variables

View Source
var (
	// NineTen is the Nine & Ten Dining Hall
	NineTen = DiningHall{
		LocationName:   "Colleges Nine & Ten Dining Hall",
		LocationNumber: "40",
	}
	// CowellStevenson is the Cowell Stevenson Dining Hall
	CowellStevenson = DiningHall{
		LocationName:   "Cowell Stevenson Dining Hall",
		LocationNumber: "05",
	}
	// CrownMerrill is the Crown Merrill Dining Hall
	CrownMerrill = DiningHall{
		LocationName:   "Crown Merrill Dining Hall",
		LocationNumber: "20",
	}
	// PorterKresge is the Porter Kresge Dining Hall
	PorterKresge = DiningHall{
		LocationName:   "Porter Kresge Dining Hall",
		LocationNumber: "25",
	}
	// CarsonOakes is the Rachel Carson Oakes Dining Hall
	CarsonOakes = DiningHall{
		LocationName:   "Rachel Carson Oakes Dining Hall",
		LocationNumber: "30",
	}
)

Functions

func MenuFor(dh DiningHall, ml Meal, date time.Time) ([]string, error)

MenuFor returns a slice of menu items given a dining hall, a meal, and a date.

Types

type Client added in v0.0.3

type Client struct {
	// contains filtered or unexported fields
}

Client is meant to be used when multiple menus want to be accessed.

It is preferred over MenuFrom because it will avoid making a call to the main UCSC nutritional page for cookies.

func (*Client) MenuFor added in v0.0.3

func (c *Client) MenuFor(dh DiningHall, ml Meal, date time.Time) ([]string, error)

MenuFor is equivalent to the standalone MenuFor function.

The primary difference between the two is that the one that uses a client maintains cookies across calls and only updates them when need be.

type DiningHall

type DiningHall struct {
	LocationName   string
	LocationNumber string
}

DiningHall represents a dining hall according to UCSC's nutritional website.

type Meal

type Meal string

Meal represents all possible meals at UCSC.

const (
	// Breakfast represents a breakfast meal.
	Breakfast Meal = "Breakfast"
	// Lunch represents a lunch meal.
	Lunch Meal = "Lunch"
	// Dinner represents a dinner meal.
	Dinner Meal = "Dinner"
	// LateNight represents a late night meal.
	LateNight Meal = "Late Night"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL