A simple command-line tool to fetch and display weather forecasts using WeatherAPI and automatic location data from ipinfo.io.
Type forecast into your linux terminal and get a 6-day forecast to your current location.
I'm Barbara Calderon, a software developer.
- Current Weather: Displays real-time conditions including temperature, feels-like temperature, humidity, chance of rain, and weather description
- 6-Day Forecast: Shows detailed daily forecasts with:
- Average, minimum, and maximum temperatures
- Precipitation chance
- Weather conditions
- Sunrise and sunset times
- Automatic Location: Detects your location using your IP address (via ipinfo.io)
- Custom Locations: Get weather for any city worldwide
forecast --location "City Name" - Flexible API Keys: The default API key is read from the
.envfile but you can temporarily override itforecast --apiKey "your_api_key_here" - Easy Configuration: Stores API keys and settings in a .env file for secure and flexible usage, automatic config directory creation, clear error messages for missing configurations,
launch.jsonfile added for VSCode debugging tool.
What's the story behind this? Well, there actually is one.
One early Sunday morning, I woke up and jumped on the computer because I wanted to play around with some coding. I usually do this in the dark, with all the windows and doors closed shut and music pumping through my headphones. As you can see, I get very distracted.
About two hours in, I remembered I had to wash my laundry and hang the clothes out to dry in the sun in my backyard. Great! I got the laundry basket, detergent, fabric softener, and everything ready. Just as I was about to walk out the building door, I realized it had been raining hard.
How could I have missed this simple feature of nature?
Oh, right... I hadnβt opened the window to my room because I was too distracted coding away on the computer.
This is meant to change that. It comes in handy for me since maybe Iβm too lazy to open a web browser, search for a weather site, type in my location, and scan for the useful data I want. Every. Single. Time.
So, considering that the first webcam ever invented was designed to monitor a coffee pot so developers would know when to grab coffee instead of checking it when it wasnβt ready, I thought to myself... hey, why not?
Thatβs how Forecast CLI was created.
I hope you find it as useful as I do.
- Go 1.21 or higher installed on your system
- API keys for WeatherAPI
- Clone the Repository:
git clone https://github.com/barbaracalderon/forecast-cli.git cd forecast-cli - Set up the Configuration:
- Create the config directory
mkdir -p ~/.config/forecast-cli- Move the
.envfile to the config directory
mv /path/to/forecast-cli/.env ~/.config/forecast-cli/- Edit the
.envFile:
- Open the
.envfile and add your API Keys from weatherapi.com, this way you have them stored and does not need to send it through the--apiKeysflag
WEATHERAPI_API_KEY=your_weatherapi_key_here- Build:
go build -o forecast- Install the Binary:
- Move the binary to a directory in your
PATH(e.g.,/usr/local/bin):
sudo mv forecast /usr/local/bin/forecastforecast --location "Rio de Janeiro"forecast --apiKey "your_api_key_here"forecast --location "FlorianΓ³polis" --apiKey "your_api_key_here"ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Location: FlorianΓ³polis, Santa Catarina, BR
β π
Date: 23/03 | Sunday
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π‘οΈ Current: partly cloudy, 24Β°C (Feels like 36Β°C)
β π½ Min: 21Β°C | πΌ Max: 28Β°C
β π§ Humidity: 70%
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π
6-Day Forecast:
βββββββββββββ¬ββββββββββββ¬ββββββββββββββ¬βββββββββββββββββββββββ¬βββββββββββ¬βββββββββββ
β Date β Temp (Β°C) β Rain Chance β Condition β Sunrise β Sunset β
βββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββββββββββββΌβββββββββββΌβββββββββββ€
β 23/03 Sun β 24 β 1% β patchy rain nearby β 06:19 AM β 06:21 PM β
β 24/03 Mon β 24 β 9% β moderate rain β 06:20 AM β 06:20 PM β
β 25/03 Tue β 22 β 1% β patchy rain nearby β 06:20 AM β 06:19 PM β
β 26/03 Wed β 22 β 5% β moderate rain β 06:21 AM β 06:18 PM β
β 27/03 Thu β 22 β 5% β patchy rain nearby β 06:21 AM β 06:17 PM β
β 28/03 Fri β 22 β 3% β patchy rain nearby β 06:22 AM β 06:16 PM β
β 29/03 Sat β 24 β 0% β partly cloudy β 06:22 AM β 06:15 PM β
βββββββββββββ΄ββββββββββββ΄ββββββββββββββ΄βββββββββββββββββββββββ΄βββββββββββ΄βββββββββββThe project uses the following services and libraries:
- WeatherAPI: For fetching weather data
- IpInfo.io: For detecting the user's location based on their IP Address
- Godotenv: For loading environment variables from the
.envfile
Contributions are welcome. If you'd like to contribute, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix
- Submit a pull request with a detailed description of your changes
This project is under the GNU General Public Licence v3.0
| Version | Date | Description |
|---|---|---|
| 1.1.0 | 26th March 2025 | Added --location and --apiKey flags. |
| 1.0.0 | 23rd March 2025 | Initial realease with basic forecast functionality. |
