How dandon01/feargreed works
Main Components
• Hardware Interface: This includes the Raspberry Pi, the Display HAT Mini (ST7735 LCD), physical buttons for UI interaction, and optional LED indicators.
• Application Core: The main executable (“feargreeddisplay.py”) which orchestrates the display updates, API calls, and user input handling.
• API/Data Integration: The components responsible for fetching data from external services such as the Alternative.me API (for the Fear & Greed Index) and CoinGecko for price info. This includes the API cache system and error handling logic.
• GIF Processing Module: “gif_processor.py” is dedicated to monitoring incoming GIFs, splitting them into frames, and saving them in the proper directories.
• Configuration/Settings: “config.json” (and any config settings embedded in code) that define display time, brightness, enabled modes, and performance thresholds such as memory limits.
• Testing and CI/CD: The tests directory with multiple test scripts (unit tests, display capability tests) and the GitHub Actions workflow for continuous integration.
• Auxiliary Scripts and Resources: Setup scripts (setup.sh), resource folders (gifs with subfolders for animations and specific modes), and extra files (PiHatMiniPinout.txt, LICENSE).
Relationships and Interactions
• The main display script (feargreeddisplay.py) acts as the central controller:
• It initializes the hardware, reads configuration settings from config.json, and sets up the environment.
• It fetches the current data from external APIs, consulting a locally maintained API cache (with a 5-minute update interval) and manages error states.
• It selects and renders the appropriate animated GIFs (from directories like gifs/feargreed, gifs/money_flow, and gifs/animations) based on the current market sentiment.
• It handles user input through physical buttons to switch between display modes and settings in the config menu.
• The GIF processing module (gif_processor.py) runs, possibly as a separate process, listening for new GIF files in an “incoming” folder (as outlined in the README). It decomposes GIFs into individual frames and organizes them in an animations folder, which the main display script then accesses.
• The API integration component also contains mechanisms for error handling: if data fetching fails or the API returns an error (e.g., for network issues or rate limits), an “error.gif” is displayed and cached data is used as fallback.
• The tests and CI/CD pipelines (GitHub Actions and pytest configurations) ensure that changes to the source code, including hardware interfacing, maintain expected behavior.
Architectural Patterns & Design Principles
• Modular Design: Separate individual responsibilities into different scripts (for display logic, configuration, GIF processing) makes the system easier to maintain.
• Event-Driven Interaction: Hardware button inputs and network events (API responses) trigger changes in display mode and data refreshing.
• Caching Mechanism: Implements a basic API cache system to reduce latency and handle temporary outages.
• Resource Management: With dedicated modules for memory management (like limiting frames per GIF and monitoring RAM usage), the system adapts to low-memory scenarios.
• Continuous Integration: Automated testing and deployment pipelines (via GitHub Actions) ensure stable operation on the target hardware.
Key Technologies and Frameworks
• Python 3.7+ – Primary programming language.
• Libraries: psutil (for memory monitoring), requests (for HTTP API calls), Pillow (image processing for GIF frames), watchdog (for monitoring file system changes), and ST7735 for display handling.
• Hardware: Raspberry Pi (Zero 2W), Display HAT Mini (ST7735 LCD), and optionally GPIO libraries for button and LED control.
Elements
• Clear Labels: Name each component (e.g., “Display Controller”, “API Cache Manager”, “GIF Processing Worker”, “Hardware Interface”).
• Annotations: Include brief notes next to components outlining key responsibilities like “Handles error states and retries” or “Processes incoming GIFs and caches frames.”
Happy diagramming!