This Java application allows users to fetch and display the current weather information for a specified city and country. It uses the OpenWeatherMap API to retrieve weather data and displays it in a user-friendly format.
- Fetches real-time weather data from the OpenWeatherMap API.
- Displays weather information such as temperature, humidity, pressure, wind speed, and a description of the weather.
- Provides an interactive console interface for user input.
- Java 11 or higher
- Gson library
- OkHttp library
- An API key from OpenWeatherMap
-
Clone the repository:
git clone https://github.com/gabrielalmir/weather-cli.git cd weather-service
-
Add the required libraries to your project. If you are using Maven, add the following dependencies to your
pom.xml
:<dependencies> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.9.3</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.8</version> </dependency> </dependencies>
-
Set up your OpenWeatherMap API key as an environment variable:
export OPENWEATHER_API_KEY=your_api_key_here
-
Compile the application:
javac -cp .:path_to_gson.jar:path_to_okhttp.jar br/com/gabrielalmir/*.java
-
Run the application:
java -cp .:path_to_gson.jar:path_to_okhttp.jar br.com.gabrielalmir.Main
-
Follow the on-screen prompts to enter a city and country code to get the weather information.
Please enter your city:
London
Please enter your country code: (e.g. US, UK, IN, BR)
UK
Looking for weather of London - UK
Weather{name='London', description='clear sky', temperature=15.0, humidity=72, pressure=1012, wind=3.6}
Do you want to check another city? (y/n)
n
Goodbye! 😊