How notchkxge/weatherapi works
Project type and purpose
• This is a standalone command-line interface (CLI) tool written in Lua.
• Purpose: fetch and display current weather data for a user-specified city by calling the OpenWeatherMap API.
File structure
• Top-level files only:
• weather.lua (the entire application)
• README.md (project description)
• LICENSE
• No separate frontend/backend folders, no database directories—this is a single-script CLI utility.
README for additional insights
• Key features: user input validation, environment-based API key handling, HTTP integration, JSON parsing, temperature conversion, error handling.
Main components & interactions
a. Components:
1. CLI Parser & Input Validator
2. Configuration Loader (reads API key from env vars)
3. HTTP Client Module (performs HTTPS GET request)
4. JSON Parser Module (parses API response)
5. Data Processor Module (extracts fields and converts Kelvin→Celsius)
6. Output Formatter (pretty‐prints results to console)
7. External Service: OpenWeatherMap API
b. Relationships & data flow:
• User runs “lua weather.lua <city>” → CLI Parser validates city name → passes to HTTP Client.
• HTTP Client attaches API key from Config Loader → sends request to OpenWeatherMap.
• API responds with JSON → JSON Parser extracts raw data.
• JSON data flows to Data Processor → applies temperature conversions, error checks.
• Processed data flows to Output Formatter → console output.
• Errors at any stage bubble back to user via standardized error messages.
c. Architectural patterns/design principles:
• Modular “pipeline” design: each responsibility (I/O, networking, parsing, processing, formatting) lives in its own conceptual module.
• Single-responsibility principle: each component has one clear purpose.
• Clear separation between internal logic and external dependency (OpenWeatherMap).
d. Key technologies/libraries:
• Lua standard libraries (io, os, string)
• HTTP library (e.g., LuaSocket or similar)
• JSON parsing library (e.g., cjson or dkjson)
• Environment variable access via os.getenv