Okay, so today I’m gonna walk you through this little side project I’ve been messing around with called “wetherbys.” Don’t ask me where the name came from, it just kinda popped into my head one day.
First things first, I wanted to build something that could pull weather data from an API and display it in a simple, clean way. I was tired of those bloated weather apps with a million ads and unnecessary features. I just wanted the basics: temperature, conditions, maybe a forecast.
So, I started by hitting up Google and searching for free weather APIs. Found a few options, but I ended up going with OpenWeatherMap. They’ve got a pretty generous free tier, and the data they provide is solid. I signed up for an API key – that’s the first step, gotta get that key!
Next up, I needed to pick a language. I’m most comfortable with Python, so that was a no-brainer. I fired up my trusty VS Code and started a new project. I installed the requests library – it’s essential for making HTTP requests to the API. Here’s the basic code I used to grab the weather data:
import requests
API_KEY = "YOUR_API_KEY" # Replace with your actual API key
Yeah, replace "YOUR_API_KEY" with your actual key, and change the CITY to whatever location you’re interested in. Running that code spits out a whole bunch of JSON data. That’s the raw weather info from OpenWeatherMap.
Now, I needed to parse that JSON and extract the bits I actually cared about. I wanted the temperature, the weather description (like “clear sky” or “light rain”), and maybe the humidity. Here’s how I did that:
temperature = data["main"]["temp"]
description = data["weather"][0]["description"]
humidity = data["main"]["humidity"]
print(f"Temperature: {temperature}°C")
print(f"Description: {description}")
print(f"Humidity: {humidity}%")
That gets the job done, but it’s kinda ugly. I wanted to display this information in a more user-friendly way. So, I decided to build a simple command-line interface (CLI). I used the argparse module to handle command-line arguments – that way, users can specify the city they want to get the weather for.
import argparse
parser = *(description="Get the current weather for a city.")
*_argument("city", help="The city to get the weather for.")
args = *_args()
CITY = *
#... (rest of the code to fetch and display weather)
That lets you run the script like this: python my_* London, and it’ll fetch the weather for London.
To make the output a bit nicer, I used some ANSI escape codes to add color. Nothing fancy, just a little bit of green for clear skies and blue for rain. It makes the output a bit easier to read at a glance.
After all that, I had a basic CLI weather tool. It’s not gonna win any design awards, but it does exactly what I want it to do: gives me the current weather for a city quickly and easily. I might add some more features later, like a forecast or maybe even a GUI, but for now, I’m happy with it.
Key takeaways from this project:
Using APIs is easier than you think. Just get your API key and start experimenting.
Python and the requests library are your friends.
Don’t be afraid to build simple tools for yourself. They can be surprisingly useful.
Next steps?
Well, I’m thinking of deploying this as a serverless function on AWS Lambda. That way, I could access it from anywhere with a simple HTTP request. I’d also like to improve the error handling – right now, it just crashes if the API request fails. And maybe, just maybe, I’ll add a proper GUI using something like Tkinter or PyQt. But that’s for another day!