Code Monkey home page Code Monkey logo

eat-api's Introduction

This project has been moved to TUM-Dev/eat-api

eat-api

Build Status

Simple static API for the canteens of the Studentenwerk München as well as some other locations. By now, the following locations are supported:

Name API-key Address location
Mensa Arcisstraße mensa-arcisstr Arcisstraße 17, München
Mensa Garching mensa-garching Lichtenbergstraße 2, Garching
Mensa Leopoldstraße mensa-leopoldstr Leopoldstraße 13a, München
Mensa Lothstraße mensa-lothstr Lothstraße 13d, München
Mensa Martinsried mensa-martinsried Großhaderner Straße 6, Planegg-Martinsried
Mensa Pasing mensa-pasing Am Stadtpark 20, München
Mensa Weihenstephan mensa-weihenstephan Maximus-von-Imhof-Forum 5, Freising
StuBistro Arcisstraße stubistro-arcisstr Arcisstraße 12, München
StuBistro Goethestraße stubistro-goethestr Goethestraße 70, München
StuBistro Großhadern stubistro-grosshadern Butenandtstraße 13, Gebäude F, München
StuBistro Rosenheim stubistro-rosenheim Hochschulstraße 1, Rosenheim
StuBistro Schellingstraße stubistro-schellingstr Schellingstraße 3, München
StuCafé Adalbertstraße stucafe-adalbertstr Adalbertstraße 5, München
StuCafé Akademie Weihenstephan stucafe-akademie-weihenstephan Alte Akademie 1, Freising
StuCafé Boltzmannstraße stucafe-boltzmannstr Boltzmannstraße 15, Garching
StuCafé in der Mensa Garching stucafe-garching Lichtenbergstraße 2, Garching
StuCafé Karlstraße stucafe-karlstr Karlstraße 6, München
StuCafé Pasing stucafe-pasing Am Stadtpark 20, München
FMI Bistro Garching fmi-bistro Boltzmannstraße 3, Garching
IPP Bistro Garching ipp-bistro Boltzmannstraße 2, Garching

Ingredients list:

CLICK ME

ingredient_lookup = {
        "GQB" : "Certified Quality - Bavaria",
        "MSC" : "Marine Stewardship Council",

        "1" : "with dyestuff",
        "2" : "with preservative",
        "3" : "with antioxidant",
        "4" : "with flavor enhancers",
        "5" : "sulphured",
        "6" : "blackened (olive)",
        "7" : "waxed",
        "8" : "with phosphate",
        "9" : "with sweeteners",
        "10" : "contains a source of phenylalanine",
        "11" : "with sugar and sweeteners",
        "13" : "with cocoa-containing grease",
        "14" : "with gelatin",
        "99" : "with alcohol",

        "f" : "meatless dish",
        "v" : "vegan dish",
        "S" : "with pork",
        "R" : "with beef",
        "K" : "with veal",
        "G" : "with poultry", # mediziner mensa
        "W" : "with wild meat", # mediziner mensa
        "L" : "with lamb", # mediziner mensa
        "Kn" : "with garlic",
        "Ei" : "with chicken egg",
        "En" : "with peanut",
        "Fi" : "with fish",
        "Gl" : "with gluten-containing cereals",
        "GlW" : "with wheat",
        "GlR" : "with rye",
        "GlG" : "with barley",
        "GlH" : "with oats",
        "GlD" : "with spelt",
        "Kr" : "with crustaceans",
        "Lu" : "with lupines",
        "Mi" : "with milk and lactose",
        "Sc" : "with shell fruits",
        "ScM" : "with almonds",
        "ScH" : "with hazelnuts",
        "ScW" : "with Walnuts",
        "ScC" : "with cashew nuts",
        "ScP" : "with pistachios",
        "Se" : "with sesame seeds",
        "Sf" : "with mustard",
        "Sl" : "with celery",
        "So" : "with soy",
        "Sw" : "with sulfur dioxide and sulfites",
        "Wt" : "with mollusks",
}

Based on: Studentenwerk München

Usage

API

The actual API is provided by static JSON files, which can be found in the gh-pages branch of this repository. These files are created through automatic travis builds. You need to structure a link as follows in order to access the API:

https://srehwald.github.io/eat-api/<location>/<year>/<week-number>.json

Example

The following link would give you the menu of Mensa Garching for week 9 in 2017:

https://srehwald.github.io/eat-api/mensa-garching/2017/09.json

CLI

The JSON files are produced by the tool shown in this repository. Hence, it is either possible to access the API or use the tool itself to obtain the desired menu data. The CLI needs to be used as follows:

$ python src/main.py -h
usage: main.py [-h] [-d DATE] [-j PATH] [-c] [--openmensa PATH]
               {fmi-bistro,ipp-bistro,mensa-garching,stucafe-karlstr,mensa-pasing,mensa-arcisstr,
               stucafe-boltzmannstr,stubistro-arcisstr,stucafe-garching,mensa-martinsried,
               mensa-weihenstephan,stubistro-grosshadern,stucafe-akademie-weihenstephan,mensa-lothstr,
               stubistro-goethestr,stubistro-großhadern,mensa-arcisstrasse,stucafe-pasing,
               stubistro-rosenheim,stucafe-adalbertstr,stubistro-schellingstr,mensa-leopoldstr}

positional arguments:
  {fmi-bistro,ipp-bistro,mensa-garching,stucafe-karlstr,mensa-pasing,mensa-arcisstr,
  stucafe-boltzmannstr,stubistro-arcisstr,stucafe-garching,mensa-martinsried,
  mensa-weihenstephan,stubistro-grosshadern,stucafe-akademie-weihenstephan,mensa-lothstr,
  stubistro-goethestr,stubistro-großhadern,mensa-arcisstrasse,stucafe-pasing,
  stubistro-rosenheim,stucafe-adalbertstr,stubistro-schellingstr,mensa-leopoldstr}
                        the location you want to eat at

optional arguments:
  -h, --help            show this help message and exit
  -d DATE, --date DATE  date (DD.MM.YYYY) of the day of which you want to get
                        the menu
  -j PATH, --jsonify PATH
                        directory for JSON output (date parameter will be
                        ignored if this argument is used)
  -c, --combine         creates a "combined.json" file containing all dishes
                        for the location specified
  --openmensa PATH      directory for OpenMensa XML output (date parameter
                        will be ignored if this argument is used)

It is mandatory to specify the canteen (e.g. mensa-garching). Furthermore, you can specify a date, for which you would like to get the menu. If no date is provided, all the dishes for the current week will be printed to the command line. the --jsonify option is used for the API and produces some JSON files containing the menu data.

Example

Here are some sample calls:

# Get the menus for the whole current week at mensa-garching
$ python src/main.py mensa-garching

# Get the menu for April 2 at mensa-arcisstrasse
$ python src/main.py mensa-arcisstrasse -d 02.04.2017

Projects using eat-api

Contributing

  1. Fork and clone this repository
  2. Install the python dependencies (Python 3.6+ required):
  • sudo apt install libxml2 libxml2-dev libxslt1-dev
  • pip3 install -r requirements.txt
  1. Run tests:
  • All the tests: PYTHONPATH=src/ pytest
  • A specific test class: PYTHONPATH=src/ pytest src/test/test_menu_parser.py::MenuParserTest

eat-api's People

Contributors

com8 avatar jpbernius avatar kordianbruck avatar raabf avatar srehwald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eat-api's Issues

[Feature] Command for all available canteens

A command that returns all available canteens in a Json array would be great to automate the process of requesting all menus for all canteens.

Examle output:

[
{
"name":"Mensa Arcisstraße",
"address":"Arcisstr. 17, München",
"latitude":"48.147312",
"longitude":"11.567229"
},
{
"name":"Mensa Garching",
"address":"Lichtenbergstr. 2, Garching",
"latitude":"48.267509",
"longitude":"11.671278"
},
[...]
]

Parsing fmi-bistro fails

If I try to parse the dishes for the FMI, it fails:
$ python3 main.py fmi-bistro

Traceback (most recent call last):
  File "main.py", line 94, in <module>
    main()
  File "main.py", line 58, in main
    menus = parser.parse(location)
  File "/home/fabian/test/eat-api/src/menu_parser.py", line 173, in parse
    week_number = int(pdf_name.split("_")[2].replace("KW","").lstrip("0"))
ValueError: invalid literal for int() with base 10: ''

incorrect menu for fmi-bistro

I've noticed that the API returns the wrong dishes for fmi-bistro. The PDFs published here show the current menu.

For instance today (it's Friday 11.01.2019) the API returns:

Minestrone | 1.00€
Grieß-Kokosmilch mit warmen Himbeeren | 3.20€
Schwäbischer Ofenschlüfer | 3.20€
Fischfilet in Kartoffelpanade dazu Kartoffel-Fenchelgemüse | 4.60€

But the actual menu is as follows:

Menu Friday 11.01.2019

[Feature] Support for side/action/... dishes

Currently the parser shows only dishes of the day.
It would be great if it would show all types of dishes.

They could get represented like:

 "dishes": [
    {
      "name": "Bio-Tortelloni all'arrabiata",
      "type": "Tagesgericht",
      "price": 1.9
    },
    {
      "name": "Nudeln",
      "type": "Beilagen",
      "price": 0.6
    },
    {
      "name": "Reis",
      "type": "Beilagen",
      "price": 1
    },
    {
      "name": "Bio-Spaghetti bolognese",
      "type": "Aktion",
      "price": 3
    }
  ]

[website] specify canteen via url parameter

pretty much the title. i think being able to specify the canteen you're interested in via a query parameter would be really useful, and a lot faster than having to go through the dropdown menu, especially on mobile

FMI Title Garching-Speiseplan → Garching_Speiseplan

Since new year FMI Bistro changed the title (snippet from bistro homepage):

  <a href="http://www.wilhelm-gastronomie.de/wp-content/uploads/2017/12/Garching_Speiseplan_KW02_2018.pdf">Garching_Speiseplan_KW02_2018</a>

xpath_query = tree.xpath("//a[contains(text(), 'Garching-Speiseplan')]/@href")

So just change Garching-Speiseplan → Garching_Speiseplan and it works (I spare a MR just for one line). Let’s hope this change is persistent.

Fetch prices during parsing

Prices for dishes are currently hard coded. In order to always have the most up-to-date prices, they need to be parsed from the STWM homepage.

Parsing ipp-bistro fails

If I try to parse the dishes for the IPP, it fails:

$ python3 main.py ipp-bistro

Traceback (most recent call last):
  File "main.py", line 112, in <module>
    main()
  File "main.py", line 76, in main
    menus = parser.parse(location)
  File "/home/fabian/eat-api/menu_parser.py", line 287, in parse
    call(["pdftotext", "-l", "1", "-layout", temp_pdf.name, temp_txt.name])
  File "/usr/lib/python3.5/subprocess.py", line 247, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'pdftotext'

It seems like it misses the pdftotext file.

IPP bistro parsing crashes

The IPP parser for the current week crashes, because there are no dishes on Wednesday available.
Link to the PDF.

The parser fails here

        positions = [(a.start(), a.end()) for a in list(re.finditer('Tagessuppe siehe Aushang', lines[0]))]
        if len(positions) != 5:
            # TODO handle special cases (e.g. that bistro is closed)
            return None

-> It returns None

How to reproduce:

$ python3 main.py ipp-bistro

Btw. I'm using #18 to fix the KW parsing crash.

Current state

I'm creating this issue to request clarification about the current state of the eat-api.

@srehwald are you still planing to actively maintain this project?

If YES:

  • When can we expect our changes being review and merged?
  • Will it always take so long until changes are being reviewed and merged?

If NO:

  • What do you think about adding other people as Collaborators ?
  • Should somebody create a fork where we will create all future PRs?

Ping: @raabf , @kordianbruck , @moredatapls , @jpbernius

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.