Skip to main content

Asynchronously access the menu of the cafeterias at KAIST.

Project description

Kafeteria

Supported Python Versions PyPi CI

Kafeteria is a Python package to asynchronously access the menu of the cafeterias at KAIST.

KAIST 학식 메뉴를 asyncio를 사용하여 불러올 수 있는 Python 패키지입니다.

Installation

Install the package using pip:

pip install kafeteria

If you want optional Slack integration, install with the slack extra:

pip install kafeteria[slack]

Usage

Use the get_menu function to get the menu for a specific cafeteria, or the get_menus function to get the menus for multiple cafeterias at once.

Valid cafeteria codes are:

  • fclt : 카이마루
  • west : 서측식당
  • east1 : 동측 학생식당
  • east2 : 동측 교직원식당
  • emp : 교수회관
  • icc : 문지캠퍼스
  • hawam : 화암 기숙사식당
  • seoul : 서울캠퍼스 구내식당

Here's an example:

import asyncio
import datetime
import kafeteria


async def main():
    # Get the menu for a specific cafeteria
    menu = await kafeteria.get_menu("fclt")
    print(menu)

    # Get the menu for a specific date
    menu = await kafeteria.get_menu("fclt", datetime.date(2025, 1, 3))
    print(menu)

    # Get the menus for multiple cafeterias at once
    menus = await kafeteria.get_menus(["fclt", "east1", "east2"])
    print(menus)


asyncio.run(main())

Slack Integration

You can also publish today's menu to a Slack channel using the kafeteria.slack.publish function.

First, you need to set up a Slack app with the chat:write permission. Once you have a bot set up with the necessary permissions, set the following environment variables:

  • KAFETERIA_SLACK_BOT_TOKEN (required): The bot token for the Slack app.

  • KAFETERIA_SLACK_CHANNEL (required): The channel ID to post the message to.

    This can be found by right-clicking on the channel in the Slack app and selecting "Copy link". The channel ID is the last part of the URL.

    For more information, see the slack api documentation.

  • KAFETERIA_MENU_TIME (optional): The menu to send.

    This can be one of 0, 1, 2, or 3. The behavior is as follows:

    • 1: breakfast

    • 2: lunch

    • 3: dinner

    • 0: default, automatically selects the menu based on the current time:

      • breakfast: 19:30 - 09:00
      • lunch: 09:00 - 14:00
      • dinner: 14:00 - 19:30
  • KAFETERIA_LIST (optional): The list of cafeterias to send the menu for.

    This should be a comma-separated list of cafeteria codes. By default, fclt,west,east1,east2 is used.

Then, you can publish the menu to a channel using kafeteria.slack.publish():

import asyncio
import kafeteria.slack

asyncio.run(kafeteria.slack.publish())

A shortcut function kafeteria.slack.run_publish() is provided for running in non-async environments.

kafeteria.slack.publish() and kafeteria.slack.run_publish() takes an optional keyword-only parameter, skip_holiday, which, if set to True, skips publishing the menu when the current day is a holiday in Korea.

Automation

Slack integration can be automated to publish the menu at a specific time every weekday using a scheduler. An example using apscheduler is provided in the kafeteria.scheduler module, which can be started by running the following command:

python -m kafeteria.scheduler

If you want to handle the automation in CI/CD, here is an example GitHub Actions workflow. Note that scheduled workflows may be delayed depending on the GitHub Actions server load.

name: Publish Menu

on:
  schedule:
    # Every weekday at 11:30 AM GMT+9 (2:30 AM UTC)
    - cron: "30 2 * * 1-5"

env:
  KAFETERIA_SLACK_BOT_TOKEN: ${{ secrets.KAFETERIA_SLACK_BOT_TOKEN }} # Set in repository secrets
  KAFETERIA_SLACK_CHANNEL: "C0123456789" # Replace with your channel ID
  KAFETERIA_MENU_TIME: "0" # Automatically select the menu based on workflow run time
  KAFETERIA_LIST: "fclt,west,east1,east2"

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"

      - name: Install dependencies
        run: pip install kafeteria[slack]

      - name: Publish menu
        run: python -c 'import kafeteria.slack; kafeteria.slack.run_publish(skip_holiday=True)'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kafeteria-0.3.0.tar.gz (86.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kafeteria-0.3.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file kafeteria-0.3.0.tar.gz.

File metadata

  • Download URL: kafeteria-0.3.0.tar.gz
  • Upload date:
  • Size: 86.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.4

File hashes

Hashes for kafeteria-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b4f7446b2fcee70763699d21a92e77c704798a74c836e018ff629ca30d4b9f4e
MD5 1d6f9e505fbc2e11c80d25ee9c39d99d
BLAKE2b-256 8539e365551f503f2fd74ae7bcd841b3b13e589659e448db0d1bb9b29d033354

See more details on using hashes here.

File details

Details for the file kafeteria-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kafeteria-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.4

File hashes

Hashes for kafeteria-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbbd6954dc97f593e690fd1d81f426f0c2a56ba5e4473a8b76ed7f8566126a29
MD5 72cceeca5aac625e53de26b00d62e591
BLAKE2b-256 eb07da096d930736af7059afd9bff394448c3fb43b8fa6a28d365ed8170a49f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page