How ybg0416/slack-lunchtogether works
Project Type and Purpose
• This project is essentially an automation tool that, on weekdays at 11 AM, uses web automation and image processing to download a profile/menu image from a Kakao channel. It then crops the image using PIL, performs Optical Character Recognition (OCR) with PaddleOCR (ppOCR), and finally sends the parsed result to a designated Slack channel.
• The purpose is to automate the lunch menu workflow by verifying the menu image and communicating outcomes to Slack.
Analyzing the File Structure
• Top-Level Files and Directories:
• Dockerfile, .dockerignore, and related configuration files indicate that the project supports containerized deployment.
• The run.py file appears to be the entry point for executing the script.
• The cron directory suggests there is a scheduling mode (cron-based execution, likely to run periodically in a Docker container).
• Directories like fonts, input, output, and result_image indicate that the project manages assets and processed images, with separate folders for results (both 'ok' and 'fail' cases).
• Other files like util.py and slack.json likely contain helper functions and Slack configurations.
• Architectural Implications:
• The project is structured as a straightforward automated script rather than a full-stack or distributed system.
• The use of Docker and a cron directory indicates an option for containerized, scheduled automation.
• The separation between configuration (.env.example), image handling (result_image, fonts, input/output), and core logic (run.py, util.py) shows a clean separation of concerns.
Architectural Components
a. Main Components:
• Scheduler/Trigger:
• Cron-based scheduler (or Docker container’s timer) that initiates the job at the set time.
• Image Fetcher:
• Uses Playwright to download the profile/menu image from the Kakao channel.
• Image Processor:
• Library integration using PIL to crop and modify the downloaded image into a target for OCR.
• OCR Engine:
• PaddleOCR (ppOCR) that parses the processed image to extract the textual menu.
• Decision Logic:
• A component (likely embedded inside run.py/util.py) that checks if the image is valid (menu vs. non-menu) and decides whether to process further or exit.
• Slack Integration:
• Responsible for sending the final parsing result (or any error result) to Slack via a webhook (configured in the .env and referenced in slack.json).
• File Management:
• Directories for fonts, input, output, and result_image to store and manage resources and logs.
• Configuration & Environment:
• .env configuration for keys and endpoints (like SLACK_WEBHOOK_URL), and Docker-related files for container deployment.
b. Relationships and Data Flow:
• The scheduler triggers run.py that coordinates the entire pipeline.
• The Image Fetcher contacts the external Kakao server to get the profile image.
• The image then passes into the Image Processor (with PIL) which prepares it for OCR.
• The processed image is fed to the OCR Engine (using PaddleOCR) to extract text.
• The Decision Logic then checks the OCR results: if the text is as expected (i.e., valid menu), the process continues; otherwise, it might flag a failure.
• Finally, results are sent to Slack, and optionally files are updated in the result_image directories.
• Use of Docker allows all of the above to run in a controlled environment, ensuring dependencies as defined in requirements.txt and setups from Dockerfile.
c. Architectural Patterns & Design Principles:
• Separation of Concerns: Each component (fetching, processing, OCR, and integration) has its role.
• Modular Design: The use of separate modules and folders indicates that each functionality (image manipulation, Slack integration, etc.) can be maintained and potentially extended independently.
• Containerization: Docker encapsulates the environment, ensuring consistent deployment across different platforms.
• Environment Configuration: Use of .env files for sensitive configurations evidences good security and maintainability practices.
d. Relevant Technologies and Frameworks:
• Playwright for automated web interaction
• Python Imaging Library (PIL/Pillow) for image processing
• PaddleOCR/ppOCR for text recognition via OCR
• Slack API (via incoming webhook) for notifications
• Docker for containerized deployments
• Standard Python scripts with a virtual environment setup