Skip to content

vitlabuda/icanteen-menu-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iCanteen Menu Extractor

iCanteen Menu Extractor is a Java library for extracting food menus from iCanteen, a Czech food ordering web application used by many canteens and school cafeterias in the Czech Republic.

Since the web app seems not to offer a public API, the library extracts food menus straight from the HTML code of the app's login page. Since the food menus are publicly available without login, it is not necessary to have credentials to the app.

Disclaimer

This project is not affiliated with iCanteen or its author, Z-WARE s.r.o. in any way. This library is a non-profit, open-source software programmed by an independent developer.

Usage

In most cases, the only thing you will want to do is to simply fetch and parse a food menu without customizing this library's functionality using various constructor parameters.

To fetch the HTML of iCanteen's login page, you may use the HTTPFetcher class, although it is certainly not necessary – you may fetch the HTML using any other method or even acquire it from a file, database, cache etc.

To extract the food menu from the somehow acquired HTML (in a string), use the extractMenuFromHtml(String htmlString) method of the MenuExtractorCoordinator class. If everything goes well, a Menu instance containing the desired food menu will be returned.

Documentation

This library's public API and exceptions are documented using Doc comments in the source code.

Example

import cz.vitlabuda.icanteen_menu_extractor.containers.Day;
import cz.vitlabuda.icanteen_menu_extractor.containers.Dish;
import cz.vitlabuda.icanteen_menu_extractor.containers.Menu;
import cz.vitlabuda.icanteen_menu_extractor.extractor_coordinator.MenuExtractorCoordinator;
import cz.vitlabuda.icanteen_menu_extractor.extractor_coordinator.exc.AllExtractorsFailedException;
import cz.vitlabuda.icanteen_menu_extractor.extractor_coordinator.exc.NoMenuPublishedSaysExtractorException;
import cz.vitlabuda.icanteen_menu_extractor.utils.HTTPFetcher;
import cz.vitlabuda.icanteen_menu_extractor.utils.exc.HTTPFetcherException;

public class Example {
    private static final String ICANTEEN_LOGIN_PAGE_URL = "https://strav.nasejidelna.cz/demo/login";

    public static void main(String[] args) {
        // Fetch the login page
        HTTPFetcher fetcher = new HTTPFetcher();
        String html;
        try {
            html = fetcher.fetch(ICANTEEN_LOGIN_PAGE_URL);
        } catch (HTTPFetcherException e) {
            System.err.println(e.toString());
            return;
        }

        // Extract the food menu from the login page
        MenuExtractorCoordinator extractorCoordinator = new MenuExtractorCoordinator();
        Menu menu;
        try {
            menu = extractorCoordinator.extractMenuFromHtml(html);
        } catch (AllExtractorsFailedException | NoMenuPublishedSaysExtractorException e) {
            System.err.println(e.toString());
            return;
        }

        // Display the extracted food menu
        for(Day day : menu.getDays()) {
            System.out.printf("----- %s -----\n", day.getDate().toString());

            for(Dish dish : day.getDishes())
                System.out.printf("%s: %s\n", dish.getDishTitleString(), dish.getDishString());

            System.out.println();
        }
    }
}

Licensing

This project is licensed under the 3-clause BSD license – see the LICENSE file.

In addition, this project uses some third-party open-source components – see the THIRD-PARTY-LICENSES file.

Programmed by Vít Labuda.

About

A Java library for extracting food menus from iCanteen, a Czech food ordering web application

Resources

License

Stars

Watchers

Forks

Languages