This is my final project for the Code First Girls Python & Apps Kickstarter course, built in collaboration with my teammate Nicolette Bell.
Team Duck! 🦆🦆🦆
- Accept a city name as input from the user
- Allow user to specify a country if there are multiple cities with the same name
- Sanitize user input
- Convert user input string into latitude and longitude
- Make a request to the API with the requested location's latitude and longitude as part of the search query
- Get the returned values from the API response
- Display the weather from the inputted location
- Covert weather code into real weather value as a string
- Be a reusable function so it can be re-run to get multiple locations without ending and restarting
- Handle user inputs that are not a real city/country or are gibberish
- Handle inputs to the Y/N questions that aren't Y or N
- Allow the user to specify a country if they enter a city name which is present in more than one country
- Have a web-based visual interface for input and to display the weather data
- Allow a 'random' request to pull any city
- Have ducks? 🦆
A simple weather app that could take user input for a city, and then grab the requested location's weather data from an API and show it to the user.
We completed the original plan, and then added several additional features. These include:
- being a reusable function so the code can be re-run to get multiple locations without ending and restarting
- handling user inputs that are not a real city/country or are gibberish
- allowing the user to specify a country if they enter a city name which is present in more than one country
- handling inputs to the Y/N questions that aren't Y or N
- having a 'random' request that pulls a random city
- added duck emojis
When trying to work out how to handle user input that wasn't a real city name, we decided to add in try/except blocks (which weren't covered in the course).
try:
print(f"You've asked to see the weather in {location.address}.")
except AttributeError:
print("I don't think that's a real place, please try again!")
returnThis code tries to run the intended output, but if the API returns an AttributeError it will exit the reusable part of the function and ask if you want to see another location, starting the whole flow again.
Our biggest takeaway from this project was learning how to use APIs. Figuring out what data we wanted from the returned JSON files and how to access those particular bits, especially when data we wanted was in nested dictionaries, was a great learning experience. We also built in a lot of redundancies and error handling to try to keep the user in the flow of the code, whether their input was expected or unexpected.
Adding in the option to generate a random city was unexpectedly difficult. First we had to find another API from which to get a list of city names to randomly pull from. Once we had that generating a random city, we realized that we needed to swap around loads of different code snippets to alter the control flow to get it to work as intended. Far more complex than we'd anticipated!
We'd really like to connect it to a web frontend and create a full-on web-based weather app in the near future! With ducks, of course. 🦆
