A command-line interface (CLI) application that allows users to register, log in, fetch weather information from OpenWeatherMap API, and view their search history.
- Source Code Style
- Setup Instructions
- API Usage
- Database Schema
- Design Decisions
- Additional Features and Their Integration
/weather_app_cli
│
├── /models
│ ├── __init__.py # Makes models a package
│ ├── user_model.py # User registration and login
│ ├── search_history.py # Search history operations
│
├── /services
│ ├── __init__.py # Makes services a package
│ ├── weather_service.py # Fetching weather data
│
├── /db
│ ├── __init__.py # Makes db a package
│ └── db_connection.py # Database connection
│
├── app.py # Main application logic
├── requirements.txt # Python dependencies
└── config.py # Configuration for API keys, etc.
└── schema.sql # SQL schema for database
-
Clone the repository:
git clone <repository-url> cd weather_cli_app
-
Install dependencies:
Ensure you have Python 3.6 or higher installed. Create a virtual environment and install the required packages.
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
-
Set up the database:
Import the provided SQL schema into your MySQL database. Replace the database credentials in
main.py
with your own.mysql -u <username> -p < database_name < schema.sql
-
Obtain an API Key:
Sign up at OpenWeatherMap to get your API key. Replace
"your_openweathermap_api_key"
inconfig.py
with your actual API key. -
Run the application:
python main.py
The application interacts with the OpenWeatherMap API to fetch weather data. The endpoint used is:
- GET
http://api.openweathermap.org/data/2.5/weather?q={location}&appid={api_key}&units=metric
Parameters:
q
: Location (city name)appid
: Your OpenWeatherMap API keyunits
: Metric for temperature in Celsius
The application uses two tables: users
and search_history
.
users
Table:
Column | Type | Description |
---|---|---|
id |
INT | Primary Key, auto-incremented ID |
username |
VARCHAR | Unique username for login |
password |
VARBINARY | Hashed password |
search_history
Table:
Column | Type | Description |
---|---|---|
id |
INT | Primary Key, auto-incremented ID |
user_id |
INT | Foreign Key to users table |
location |
VARCHAR | Location searched by the user |
weather_data |
TEXT | JSON-encoded weather data |
timestamp |
TIMESTAMP | Time of the search |
-
Security:
- Passwords are hashed using bcrypt for secure storage.
- API keys and sensitive information are not hard-coded; replace placeholders with your actual credentials.
-
Error Handling:
- Basic error handling is implemented for database operations and API requests.
-
User Experience:
- The CLI interface allows users to register, log in, and interact with weather data intuitively.
-
Scalability:
- The application is designed to be simple but can be expanded with additional features such as user profile management or more detailed weather analytics.
-
Database:
- MySQL is used for persistent storage due to its reliability and ease of use.
- Allow users to delete their search history or update specific records.
- Let users retrieve weather data for previously searched locations.
- Enable users to update their username and password.
- Fetch additional data from OpenWeatherMap, such as forecast data for multiple days, sunrise/sunset times, and air quality.