https://github.com/philippdormann/mensamax-api
unofficial MensaMax-API
https://github.com/philippdormann/mensamax-api
api mensamax mensamax-api nodejs vercel
Last synced: 12 months ago
JSON representation
unofficial MensaMax-API
- Host: GitHub
- URL: https://github.com/philippdormann/mensamax-api
- Owner: philippdormann
- License: agpl-3.0
- Created: 2018-05-28T10:41:46.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-03-16T22:56:54.000Z (over 2 years ago)
- Last Synced: 2025-05-20T15:17:37.074Z (about 1 year ago)
- Topics: api, mensamax, mensamax-api, nodejs, vercel
- Language: HTML
- Homepage: https://mensa.vercel.app
- Size: 1.04 MB
- Stars: 4
- Watchers: 3
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# MensaMax-API
### Scraper for MensaMax products (like `mensadigital.de`/ `mensamax.de`/ `mensapoint.de`)
🍲🥘🥡🍛🍜🦐🥔
🍴🍽️ this is just a fancy way of getting some food 🍽️🍴
🍲🥘🥡🍛🍜🦐🥔
[](https://mensa.vercel.app) [](https://paypal.me/philippdormann) [](https://buymeacoffee.com/philippdormann) [](https://ko-fi.com/V7V4I6I8) [](https://www.npmjs.com/package/@philippdormann/mensamax-api)
## 🧐 Usage
> General Note: Please use your own caching strategy, MensaMax servers might be quite slow
### API usage
see for API URLs
### npm package usage
#### Install package
```bash
pnpm i @philippdormann/mensamax-api
```
#### ts/ module imports
```ts
import { fetchHTML, parser } from '@philippdormann/mensamax-api';
const html = await fetchHTML({ p: 'FO111', e: 'herz', kw: 15 });
const parsed = await parser(html);
console.log(parsed);
```
#### CommonJS imports
```js
const { fetchHTML, parser } = require('@philippdormann/mensamax-api');
(async function () {
try {
const html = await fetchHTML({ p: 'FO111', e: 'herz', kw: 15 });
const parsed = await parser(html);
console.log(parsed);
} catch (e) {
console.log(e);
}
})();
```
## 🚀 Deployment
This project is deployed as a serverless function on the url with [Vercel](https://vercel.com/) ☁️
## 🐳 Docker Deployment
This project can be deployed as a docker container.
To do so, just run this code:
```
docker-compose up -d --build
```
## 💻 Local Development
Either develop on your machine directly or use the provided devcontainer for VSCode
```
pnpm i
pnpm dev
```
## 💡 How this works
1. Fetch data from url ([fetcher.js](./api/fetcher.js))
- fetch `VIEWSTATE` + `VIEWSTATEGENERATOR` from .NET with axios
- hit login endpoint with a GET request
- request method: POST
- enable followAllRedirects
- set login headers
- setup request (these settings are important)
- enable cookies
- request method: POST
- enable followAllRedirects
- set login headers
2. Parsing the data ([parser.js](./api/parser.js))
- get relevant elements with cheerio
- timePeriod
- categories
- day cards with food items
- minify html
- Regex
- Replace unreadable markup such as internal MensaMax IDs
- Build JSON from custom markup
3. Serve via rayo http/ Vercel Serverless Function
## 🏫 Known/ tested institutions
- For a nice GUI version, see
- For the raw data, see [institutions.json](./institutions.json)
- Please feel free to suggest new institutions by opening a PR/ Issue
## 🧠 General Knowledge
- For some reason, MensaMax IT department decided to have **many URLs**
- you can find a list of all known MensaMax URLS @[mensamax-urls.txt](./mensa-urls.txt)
- These **URLs are not interchangeable** and seem to be different MensaMax versions (as of 13.04.2023)
- There is a private/ internal GraphQL API for MensaMax which needs authentication
## 👍💰 Support this project
You like this project and would like to give something back?
Thanks! [Have a look at my profile](https://github.com/philippdormann) for more information & options.