Document
Document
Database credentials (host, user, password) are hardcoded, which is a security risk.
Queries use string formatting (.format()), making the application vulnerable to SQL injection attacks.
Inputs are taken directly without validation (e.g., name, city, type).
Queries like DELETE and SELECT are case-sensitive for name and city. This can lead to inconsistent
behavior.
5. No Error Handling:
Missing error handling for SQL execution, database connection issues, or invalid user input.
The display_places_by_season function is hardcoded to filter only from October to February, limiting
flexibility.
Messages like "No places found" are generic and do not guide users to correct their input.
9. No Logging Mechanism:
Outputs like print(i) display data in tuple format, which is not user-friendly.
The setup_database function doesn't handle existing tables gracefully, potentially causing errors.
---
Improvements
cursor.execute("DELETE FROM tourism WHERE name = %s AND city = %s", (name, city))
3. Validate User Input:
Add validation to ensure inputs meet expected formats (e.g., non-empty strings, valid season
names).
Use try-except blocks to handle database connection and query errors gracefully.
6. Connection Pooling:
Use connection pooling to reduce overhead when repeatedly connecting to the database.
Allow users to specify the start and end months dynamically instead of hardcoding them.
8. User-Friendly Output:
9. Add Logging:
Use Python’s logging module to log errors, warnings, and user actions.
cursor.execute("""
Name VARCHAR(100),
City VARCHAR(100),
Type VARCHAR(50),
SeasonStart VARCHAR(50),
SeasonEnd VARCHAR(50),
HowToReach VARCHAR(50)
)
""")
Consider creating a web-based interface using frameworks like Flask or Django for a better user
experience.