This is a simple weather application built with Flask. It allows users to enter a city name and get the current weather information for that city, with support for both Celsius and Kelvin temperature displays.
SkyScope now supports switching between Celsius (°C) and Kelvin (K) temperature displays with a convenient toggle switch. Users can seamlessly switch between temperature units and their preference is saved for the session.
- Enter a city name and get weather information
- Use the temperature unit toggle switch located near the temperature display
- Choose between °C (Celsius) and K (Kelvin) units
- Your preference is automatically saved for the session
- All temperature values (current, feels-like, etc.) update instantly
- Interactive Toggle: Modern slider switch with smooth animations
- Session Persistence: Your temperature unit preference is remembered during your session
- Instant Updates: All temperature values convert immediately when switching units
- Consistent Display: All temperature-related metrics use the same unit
- Accessibility: Full keyboard navigation and screen reader support
- Clone the repository:
git clone https://github.com/msanzdelrio-demo-resources/SkyScope.git- Navigate to the project directory:
cd SkyScope- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install the required Python packages:
pip install -r requirements.txt- Set up your OpenWeatherMap API key:
- Create a
.envfile in the project root - Add your API key:
OPENWEATHERMAP_API_KEY=your_api_key_here
- Create a
- GET/POST
/- Main weather display page- POST Body:
{"city": "London"} - Response: HTML page with weather data
- POST Body:
- POST
/set-temperature-unit- Update temperature unit preference- Content-Type:
application/json - Request Body:
{"unit": "celsius" | "kelvin"} - Response:
{"success": true, "unit": "celsius"} - Error Response:
{"success": false, "error": "Invalid unit"}
- Content-Type:
To run the application, execute the following command in the project directory:
source venv/bin/activate # Activate virtual environment
python run.pyThen, open your web browser and navigate to http://localhost:5001.
- Get Weather Data: Enter a city name and click "Get Weather"
- Switch Units: Use the toggle switch near the temperature display
- Left position (°C): Shows temperatures in Celsius
- Right position (K): Shows temperatures in Kelvin
- Automatic Updates: All temperature values update instantly
- Session Memory: Your preference is saved until you close the browser
- app/views.py: Contains the Flask routes and the main logic of the application
- app/utils.py: Temperature conversion utilities and weather data processing
- app/templates/index.html: The HTML template for the main page with temperature toggle
- app/static/css/style.css: The CSS styles including toggle switch styling
- app/static/js/main.js: JavaScript for form submission and temperature unit toggle
- tests/unit/test_temperature_conversion.py: Comprehensive unit tests for temperature features
- tests/test_views.py: Integration tests for the application routes
To run the tests, execute the following command in the project directory:
source venv/bin/activate
python -m pytest tests/ -v- Temperature Conversion: 15 comprehensive unit tests with >95% coverage
- API Endpoints: Integration tests for weather and temperature unit routes
- Frontend Functionality: Manual testing for toggle interactions
- Security: CSRF protection and input validation testing
# Temperature conversion tests only
python -m pytest tests/unit/test_temperature_conversion.py -v
# All unit tests
python -m unittest discover testsContributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
MIT (https://choosealicense.com/licenses/mit/)
- Clone the repository:
git clone https://github.com/msanzdelrio-demo-resources/SkyScope.git- Navigate to the project directory:
cd SkyScope- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate- Install the required Python packages:
pip install -r requirements.txt- Set up environment variables:
# Create .env file with your OpenWeatherMap API key
echo "OPENWEATHERMAP_API_KEY=your_api_key_here" > .env- Run the application:
python run.py- Open your web browser and navigate to http://localhost:5001
- Test Weather Functionality:
- Enter a city name in the input field and click "Get Weather"
- Verify that weather information displays correctly
- Test Temperature Toggle:
- Use the toggle switch to switch between °C and K
- Verify all temperature values update immediately
- Refresh the page and confirm your unit preference is maintained
Create a .env file in the project root with:
OPENWEATHERMAP_API_KEY=your_api_key_here
FLASK_ENV=development
SECRET_KEY=your_secret_key_for_sessions- Real-time Weather Data: Current weather conditions from OpenWeatherMap API
- Temperature Unit Toggle: Switch between Celsius (°C) and Kelvin (K) instantly
- Session Persistence: Temperature unit preference saved during browser session
- Responsive Design: Works seamlessly on desktop and mobile devices
- Security Features: CSRF protection, input validation, and secure session management
- Comprehensive Testing: >95% test coverage with unit and integration tests
- Accessibility: Screen reader support and keyboard navigation
SkyScope includes enterprise-grade security features:
- CSRF Protection: Prevents cross-site request forgery attacks
- Input Validation: Comprehensive sanitization of user inputs
- Secure Sessions: Encrypted session management for user preferences
- Security Headers: X-Frame-Options, X-Content-Type-Options, and more
- Environment Variables: Secure API key and configuration management
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/temperature-enhancement) - Make your changes and add tests
- Ensure all tests pass (
python -m pytest tests/ -v) - Commit your changes (
git commit -am 'Add temperature enhancement') - Push to the branch (
git push origin feature/temperature-enhancement) - Create a Pull Request