Weather CLI Project
Introduction
This project involves the development of a console-based weather application that uses the Weatherstack API to fetch and display real-time weather data. The primary goal is to enable users to input a city location and receive detailed weather information, including UV index, temperature, humidity, wind speed, and more. Designed with accessibility and ease of use in mind, this project offers an efficient tool for users to check weather conditions for any specified location.
Note: This project was part of a school assignment for my Systems Programming class.
Objectives
The main objectives for this project are:
Data Accessibility: Offer real-time weather information based on a location’s identifiable information with an easy-to-use user interface.
Error Management: Implement robust error handling to manage invalid inputs and unsuccessful API calls, enhancing reliability and providing user feedback.
API Integration: Use the Weatherstack API along with the libcurl and jsmn libraries for API communication and JSON parsing.
Program Architecture
The program code is structured modularly, making it manageable and allowing each component to serve as a building block for the entire program. The main components are:
- Input Block: This block will prompt and collect user input (e.g. city name) and include necessary code for validating the user’s input.
- API Block: This block of code will establish the connection with the Weatherstack API by sending an HTTP request and handling the response with the help of the libcurl library.
- Data Processing: This block will contain the code for parsing the API response which will be in a JSON format. This code will utilize the jsmn library, or similar, to organize the relevant data into a C data structure.
- Output/Display Block: This block will take the data structure and will display the parsed data to the user in a console friendly format.
Additionally, the code will be compiled with the gcc compiler.
Program Flow
The program will first welcome the user and introduce the weather functionality (e.g. offer an example input). Then the user will provide an input. The program will validate the input and if valid will make an API call to retrieve the weather data for that location. The response to the call will then be parsed and presented to the user. If input is invalid or if the call fails, the program will provide error handling and prompt the user to retry.
Procedure
Create WeatherStack Account
- Navigate to https://weatherstack.com/ and create an account. Once the account is made you will be presented with your API key
Install libcurl
bashsudo apt-get install libcurl4-openssl-dev
Download jsmn.h (Used for JSON parsing)
- Download the jsmn.h file from https://github.com/zserge/jsmn/blob/master/jsmn.h
Compile code
bashsudo gcc -o weather_cli main.c -lcurl
Future Improvements
Graphical User Interface:
- Enhance accessibility by introducing a GUI with visual weather elements like icons.
Historical and Forecast Data:
- Include features to display historical data and multi-day forecasts.
Error Handling:
- Improve handling of API request failures, invalid inputs, and network issues.
C Source Code
View Code
|
|