stwmmensa

package module
v0.0.0-...-879f890 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: MIT Imports: 9 Imported by: 0

README

stwmmensa Build Status GoDoc Go Report Card

A golang package providing tools to get the menu for Studentenwerk München canteens.

Documentation

The documentation is available on godoc.org

Documentation

Overview

Package stwmmensa provides tools to get the menu for Studentenwerk Muenchen canteens

Index

Constants

View Source
const NextDayAfter = 14

NextDayAfter is the threshold value which is used to determine, whether todays menu or tomorrows menu shall be fetched. If the processed time is equal to or greater than NextDayAfter:00 the next day is chosen. For example if NextDayAfter == 14 the next day will be chosen starting from 2PM.

Variables

This section is empty.

Functions

func FormatLIS

func FormatLIS(dishes []Dish, date time.Time, outfile string)

FormatLIS writes a HTML snippet containing the menu to the file outfile. The menu consists of a title containing the date which was given as input and a list of the Dish objects contained in dishes.

The output will look somethin like this:

<h1>
<span> class="mensa-title">Mensa</span>
<span> class="mensa-date">Donnerstag 01. Juni 2017"</span>
</h1>
<div class="mensa-box">
<div class="mensa-item">
<span class="mensa-name">Tagesgericht 1</span>
<span class="mensa-value">Kartoffeleintopf mit Majoran</span>
</div>
<div class="mensa-item">
<span class="mensa-name">Tagesgericht 2</span>
<span class="mensa-value">Prager Bratwurst (R,S)(2,3,8)</span>
</div>
<div class="mensa-item">
<span class="mensa-name">Aktionsessen 5</span>
<span class="mensa-value">Rindergeschnetzeltes Stroganoff (GQB) (R)(2,9)</span>
</div>
<div class="mensa-item">
<span class="mensa-name">Self-Service</span>
<span class="mensa-value">Fusilli mit Rucola-Pesto</span>
</div>
<div class="mensa-item">
<span class="mensa-name">Self-Service</span>
<span class="mensa-value">Bio-Penne mit Bio-Tomaten-Frischkäse-Sauce</span>
</div>
<div class="mensa-item">
<span class="mensa-name">Self-Service</span>
<span class="mensa-value">Kartoffeleintopf mit Majoran</span>
</div>
</div>

This is not valid HTML for standalone use. However this is exactly the format needed to include the menu on the infoscreen running at the kitchen of http://www.lis.ei.tum.de

func FormatValid

func FormatValid(format string) bool

FormatValid checks, whether the string format is either "xml" or "lis", which are the two supported output formats

func FormatXML

func FormatXML(dishes []Dish, date time.Time, outfile string)

FormatXML writes a XML formatted menu to the file outfile. The menu consists of a title containing the date which was given as input and a list of the Dish objects contained in dishes.

The output will be formatted like this:

<menu title="Mensa am Donnerstag den 01.06.">
<dish name="Kartoffeleintopf mit Majoran" category="Tagesgericht 1"></dish>
<dish name="Prager Bratwurst (R,S)(2,3,8)" category="Tagesgericht 2"></dish>
<dish name="Rindergeschnetzeltes Stroganoff (GQB) (R)(2,9)" category="Aktionsessen 5"></dish>
<dish name="Fusilli mit Rucola-Pesto" category="Self-Service"></dish>
<dish name="Bio-Penne mit Bio-Tomaten-Frischkäse-Sauce" category="Self-Service"></dish>
<dish name="Kartoffeleintopf mit Majoran" category="Self-Service"></dish>
</menu>

func GermanMonth

func GermanMonth(m time.Month) string

GermanMonth returns the german name for a time.Month

func GermanWeekday

func GermanWeekday(w time.Weekday) string

GermanWeekday returns the german name for a time.Weekday

func GetDate

func GetDate(now time.Time) time.Time

GetDate returns the date for which we want to show the canteen menu based on the time now. If now.Weekday() is either Saturday or Sunday the following monday will be returned by adding 48 resp. 24 hours to now. For monday through friday now itself will be returned if it is before NextDayAfter PM. If now is after NextDayAfter PM, the following day (for friday the following monday) will be returned by adding 24 hours (72 hours for friday) to now.

func LocationValid

func LocationValid(id string) bool

LocationValid checks whether string id is a valid STWM canteen ID

func UpdateMenuFile

func UpdateMenuFile(location string, format string, outfile string)

UpdateMenuFile updates (or creates) the file "outfile" with the current menu for canteen with id "location" formatted in the "format" style.

func WriteOutput

func WriteOutput(menu Menu, format string, outfile string)

WriteOutput calls either FormatLIS if format=="lis" or FormatXML in all other cases. These methods will then write to outfile.

Types

type Dish

type Dish struct {
	Category string
	Name     string
}

Dish is used to store name and category of a dish

func GetDishes

func GetDishes(url string) []Dish

GetDishes uses goquery https://github.com/PuerkitoBio/goquery to extract dishes from the Studentenwerk München canteen menu webpage located at url and returns a (possibly empty) list of Dish objects.

The output should contain only main dishes. However due to the cluttered classification by the Studentenwerk, there might still be sides/desserts which are not handled correctly. All declarations (e.g. (v) for "dish is vegan") are stripped from the dish names.

type Menu struct {
	Date     time.Time
	Location string
	Dishes   []Dish
}

Menu consists of date, canteen location id and a list of dishes

func FetchMenu

func FetchMenu(date time.Time, location string) Menu

FetchMenu fetches the menu for the canteen identified by location and the day of date from the Studentenwerk München website.

The URL is composed in the format:

http://www.studentenwerk-muenchen.de/mensa/speiseplan/speiseplan_2017-05-31_421_-de.html

The return value will be a (possibly empty) list of dishes.

type XMLDish

type XMLDish struct {
	XMLName  xml.Name `xml:"dish"`
	Name     string   `xml:"name,attr"`
	Category string   `xml:"category,attr"`
}

XMLDish is used to store information about a dish in a format than can be used to create xml-output using xml.Marshal

Notes

Bugs

  • there is no handling of holidays

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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