A Python application that displays current weather information for cities around the world using the WeatherAPI.com API.
This application demonstrates:
-
Display message on screen (a):
- Formatted welcome banners
- Status messages and loading indicators
- Error messages with custom styling
- Formatted weather data output
-
Design classes for given problem (e):
WeatherDataclass to encapsulate weather informationWeatherAppclass for console application functionalityWeatherAppGUIclass for graphical interface functionality
-
Handle exceptions (f):
- Network connection errors
- HTTP response errors
- JSON parsing errors
- Data structure errors
- Generic exception handling
-
Clone or download this repository
-
Install the required packages:
pip install -r requirements.txtIf you encounter issues with the above command, try:
python -m pip install -r requirements.txtOr install packages individually:
pip install requests==2.28.1 pip install pillow==9.2.0 pip install python-dotenv==1.0.0 -
Create a
.envfile in the project root with your API key:WEATHER_API_KEY=your_api_key_here -
Run the application:
python weather_app.py
- Enter the name of a city when prompted
- View the current weather information
- Type 'history' to see recent searches
- Enter another city or type 'quit' to exit
- Run the GUI application:
python weather_app_gui.py - Enter the name of a city in the input field
- Click the "Search" button
- View the current weather information displayed in the GUI
- Click the "History" button to see recent searches
- The
.envfile containing your API key is listed in.gitignoreand will not be pushed to Git - Never commit sensitive information like API keys directly in your code
- Each developer needs to create their own
.envfile locally with their API key
- Current temperature (in Celsius)
- "Feels like" temperature
- Weather conditions description
- Humidity percentage
- Wind speed
- Current date and time of the weather data
- Weather icons (GUI version)
- Recent searches history
- Secure API key management using environment variables
-
Package Installation Issues
If
pip install -r requirements.txtfails, try these alternatives:-
Use the full path to requirements.txt:
pip install -r "/path/to/requirements.txt" -
Check pip version:
pip --version -
Update pip:
python -m pip install --upgrade pip -
Install packages one by one:
pip install requests pip install pillow pip install python-dotenv
-
-
Missing Modules
If you see an error like
ModuleNotFoundError: No module named 'requests'orNo module named 'dotenv', it means the required packages are not installed. Run:pip install -r requirements.txt -
API Key Issues
Error:
API key not found. Please set WEATHER_API_KEY in .env file.Solution: Create or edit the
.envfile in the project root directory and add:WEATHER_API_KEY=your_api_key_here -
Connection Errors
Error:
Failed to connect to the weather service.Solution:
- Check your internet connection
- Verify that the API service is running by visiting weatherapi.com
- Ensure your API key is valid and has sufficient credits
-
City Not Found
Error:
City '{name}' not found.Solution:
- Check the spelling of the city name
- Try adding a country code (e.g., "London,UK" instead of just "London")
- Use a more specific location name
-
Display Issues in GUI
If elements are cut off or not visible in the GUI:
- Resize the window to make it larger
- Use the scrollbar to view all content
- Try a lower screen resolution if available
-
Python Version Compatibility
This app is tested with Python 3.7+. If you have errors related to syntax or incompatible features, check your Python version with:
python --version -
Image Loading Issues
If weather icons don't appear in the GUI:
- Check your internet connection
- The app will continue to function without icons and will display text descriptions instead
For additional help, please submit an issue on the project's GitHub page or contact the developer.