This is a simple weather application written in C++. It retrieves current weather data using the OpenWeatherMap API and displays information such as temperature, weather description, and humidity for a given city.
- The application prompts the user to enter the name of a city for which they want to retrieve weather data.
- It sends an HTTP request to the OpenWeatherMap API with the provided city name and the API key.
- The API responds with weather data in JSON format.
- The application parses the JSON response to extract the relevant weather information.
- The extracted weather information (e.g., temperature, weather description, humidity) is displayed to the user.
Input
Enter the city name (or type 'q' to quit): London
Output
Weather for city London:
Temperature: 25.6°C
Weather description: Sunny
Humidity: 70%
- libcurl: A library for making HTTP requests and retrieving data from APIs.
- JsonCpp: JsonCpp is a C++ library that allows manipulating JSON values, including serialization and deserialization to and from strings.
Make sure to have these libraries installed on your system before compiling the application.
To get started with this project, follow these steps:
-
Clone this repository using the following command:
git clone https://github.com/Arkadiusz4/weather_tracker.git
-
Install the necessary dependencies, including the
libcurl
andJsonCpp
libraries. -
Create your own OpenWeatherMap API key by signing up for a free account on the OpenWeatherMap website. Copy the generated API key.
-
Open the
apikey.h
file in the project and replace the existing placeholder API key with your own key. Save the file. -
Compile the code using a C++ compiler with the necessary libraries linked.
-
Run the compiled executable.
-
Enter the name of the city for which you want to retrieve weather data.
-
The application will display the current weather information for the provided city.
To create your own API key for OpenWeatherMap, follow these steps:
- Visit the OpenWeatherMap website and sign up for a free account.
- After signing in, go to your account dashboard and navigate to the API Keys section.
- Generate a new API key or use an existing one.
- Copy the generated API key.
- Open the
apikey.h
file in the project and replace the existing placeholder API key with your own key. - Save the file.
Make sure to keep your API key secure and do not share it publicly.
Create a file called apikey.h
in the project directory Place it in the include
folder.
Open the apikey.h
file and paste the following code:
#ifndef WEATHER_TRACKER_APIKEY_H
#define WEATHER_TRACKER_APIKEY_H
#include <string>
std::string getApiKey() {
return "YOUR_API_KEY";
}
#endif //WEATHER_TRACKER_APIKEY_H
Replace "YOUR_API_KEY" with your actual API key. Save the file.
This project is licensed under the MIT License.