Weather Forecast App
This Dart script fetches weather forecast data from the WeatherAPI and displays it for a specified city.
Installation
- Clone the repository or download the
weather.dartfile. - Make sure you have Dart installed on your system. If not, you can download and install it from the Dart website.
- Install dependencies by running
pub getin your terminal within the directory containing theweather.dartfile. - Create a
.envfile in the same directory asweather.dartand add your WeatherAPI.com key as follows:
API_KEY=your_weather_api_key
Usage
Run the script using the Dart VM with the following command:
dart weather.dart <city> <unit> [days]
Replace <city> with the name of the city for which you want to fetch the weather forecast.
Replace <unit> with either 'c' for Celsius or 'f' for Fahrenheit to specify the temperature unit.
[days] is an optional argument representing the number of days for which you want to retrieve the forecast. If not provided, the default is 1.
Example:
dart weather.dart "New York" c 3
This will fetch the weather forecast for New York in Celsius for the next 3 days.
Dependencies
http: A package for making HTTP requests.dotenv: A package for loading environment variables from a.envfile.
License
This project is licensed under the MIT License