help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
weather-chatbot
/
templates
/
errors
RSK World
weather-chatbot
Weather Chatbot - Python + Flask + OpenWeatherMap + OpenAI + Weather Forecast + Weather Alerts + Natural Language Processing
errors
  • 404.html2.5 KB
  • 500.html3.6 KB
API.mdrun.py
API.md
Raw Download

API.md

# Weather Chatbot API Documentation
## =================================

**Author:** RSK World (https://rskworld.in)
**Founded by:** Molla Samser
**Designer & Tester:** Rima Khatun
**Contact:** +91 93305 39277, hello@rskworld.in, support@rskworld.in
**Location:** Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
**Year:** 2026

---

## Base URL

```
http://localhost:5000
```

Production: `https://your-domain.com`

---

## Authentication

Currently, the API is open. For production use, implement API key authentication:

```
X-API-Key: your_api_key_here
```

---

## Endpoints

### 1. Health Check

Check if the API is running.

**Endpoint:** `GET /health`

**Response:**
```json
{
"status": "healthy",
"timestamp": "2026-01-15T10:30:00",
"version": "1.0.0",
"app": "Weather Chatbot"
}
```

**Status Codes:**
- `200 OK` - Service is healthy

---

### 2. Chat Interface

Send a natural language query and get weather information.

**Endpoint:** `POST /chat`

**Headers:**
```
Content-Type: application/x-www-form-urlencoded
```

**Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| message | string | Yes | Natural language weather query |

**Request Example:**
```bash
curl -X POST http://localhost:5000/chat \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "message=What is the weather in London?"
```

**Response Example (Current Weather):**
```json
{
"city": "London",
"country": "GB",
"temperature": 15.5,
"feels_like": 14.2,
"humidity": 65,
"pressure": 1013,
"description": "clear sky",
"icon": "01d",
"wind_speed": 3.5,
"visibility": 10,
"timestamp": "2026-01-15 10:30:00"
}
```

**Response Example (Forecast):**
```json
{
"city": "London",
"country": "GB",
"forecasts": [
{
"datetime": "2026-01-15 12:00:00",
"temperature": 16,
"feels_like": 15,
"humidity": 60,
"description": "clear sky",
"icon": "01d",
"wind_speed": 3.2,
"rain": 0,
"snow": 0
}
]
}
```

**Response Example (Error):**
```json
{
"error": "Failed to fetch weather data: City not found"
}
```

**Status Codes:**
- `200 OK` - Request successful
- `400 Bad Request` - Invalid request
- `500 Internal Server Error` - Server error

---

### 3. Get Current Weather

Get current weather for a specific city.

**Endpoint:** `GET /weather/<city>`

**Path Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| city | string | Yes | City name |

**Request Example:**
```bash
curl http://localhost:5000/weather/London
```

**Response:**
Same as Chat Interface current weather response.

**Status Codes:**
- `200 OK` - Request successful
- `404 Not Found` - City not found
- `500 Internal Server Error` - Server error

---

### 4. Get Weather Forecast

Get 5-day weather forecast for a specific city.

**Endpoint:** `GET /forecast/<city>`

**Path Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| city | string | Yes | City name |

**Query Parameters:**
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| days | integer | No | 5 | Number of forecast days (max 5) |

**Request Example:**
```bash
curl http://localhost:5000/forecast/London?days=3
```

**Response:**
Same as Chat Interface forecast response.

**Status Codes:**
- `200 OK` - Request successful
- `404 Not Found` - City not found
- `500 Internal Server Error` - Server error

---

### 5. Get Weather Alerts

Get weather alerts and warnings for a specific city.

**Endpoint:** `GET /alerts/<city>`

**Path Parameters:**
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| city | string | Yes | City name |

**Request Example:**
```bash
curl http://localhost:5000/alerts/London
```

**Response Example:**
```json
{
"city": "London",
"alerts": [
{
"event": "Heat Warning",
"start": "2026-01-15 12:00:00",
"end": "2026-01-15 18:00:00",
"description": "Extreme heat expected. Stay hydrated.",
"severity": "high"
}
],
"has_alerts": true
}
```

**Response Example (No Alerts):**
```json
{
"city": "London",
"alerts": [],
"has_alerts": false
}
```

**Status Codes:**
- `200 OK` - Request successful
- `404 Not Found` - City not found
- `500 Internal Server Error` - Server error

---

## Error Responses

All endpoints may return error responses in the following format:

```json
{
"error": "Error message description",
"status": 400
}
```

### Common Error Codes

| Status Code | Description |
|-------------|-------------|
| 400 | Bad Request - Invalid parameters |
| 404 | Not Found - Resource not found |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error - Server error |
| 503 | Service Unavailable - Service temporarily unavailable |

---

## Rate Limiting

The API implements rate limiting to prevent abuse:

- **30 requests per minute** per IP address
- **1000 requests per hour** per IP address
- **10000 requests per day** per IP address

When rate limit is exceeded, the API returns:
```json
{
"error": "Rate limit exceeded",
"status": 429,
"retry_after": 60,
"message": "Too many requests. Please try again later."
}
```

---

## Response Format

All successful responses are in JSON format with the following structure:

### Current Weather Response
```json
{
"city": "string",
"country": "string",
"temperature": float,
"feels_like": float,
"humidity": integer,
"pressure": float,
"description": "string",
"icon": "string",
"wind_speed": float,
"visibility": float,
"timestamp": "string (ISO format)"
}
```

### Forecast Response
```json
{
"city": "string",
"country": "string",
"forecasts": [
{
"datetime": "string",
"temperature": float,
"feels_like": float,
"humidity": integer,
"description": "string",
"icon": "string",
"wind_speed": float,
"rain": float,
"snow": float
}
]
}
```

---

## Examples

### Python Example

```python
import requests

# Chat interface
response = requests.post(
'http://localhost:5000/chat',
data={'message': 'What is the weather in London?'}
)
data = response.json()
print(data)

# Get current weather
response = requests.get('http://localhost:5000/weather/London')
data = response.json()
print(f"Temperature: {data['temperature']}°C")

# Get forecast
response = requests.get('http://localhost:5000/forecast/London?days=3')
data = response.json()
print(f"Forecasts: {len(data['forecasts'])} periods")
```

### JavaScript Example

```javascript
// Chat interface
fetch('http://localhost:5000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'message=What is the weather in London?'
})
.then(response => response.json())
.then(data => console.log(data));

// Get current weather
fetch('http://localhost:5000/weather/London')
.then(response => response.json())
.then(data => console.log(data));
```

### cURL Example

```bash
# Health check
curl http://localhost:5000/health

# Chat
curl -X POST http://localhost:5000/chat \
-d "message=What is the weather in London?"

# Current weather
curl http://localhost:5000/weather/London

# Forecast
curl http://localhost:5000/forecast/London?days=3

# Alerts
curl http://localhost:5000/alerts/London
```

---

## Support

For API support and inquiries:

- **Email:** hello@rskworld.in, support@rskworld.in
- **Phone:** +91 93305 39277
- **Website:** https://rskworld.in

---

**Ā© 2026 RSK World. All rights reserved.**
run.py
Raw Download
Find: Go to:
#!/usr/bin/env python3
"""
Weather Chatbot Runner
======================

Author: RSK World (https://rskworld.in)
Founded by: Molla Samser
Designer & Tester: Rima Khatun
Contact: +91 93305 39277, hello@rskworld.in, support@rskworld.in
Location: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
Year: 2026

Description: Entry point for the Weather Chatbot application
"""

import os
import sys
from app import app

def main():
    """Main entry point for the Weather Chatbot application"""
    
    # Print startup banner
    print("=" * 60)
    print("šŸŒ¤ļø  Weather Chatbot - RSK World")
    print("=" * 60)
    print("Author: RSK World (https://rskworld.in)")
    print("Founded by: Molla Samser")
    print("Designer & Tester: Rima Khatun")
    print("Contact: +91 93305 39277")
    print("Email: hello@rskworld.in, support@rskworld.in")
    print("Location: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India")
    print("Year: 2026")
    print("=" * 60)
    print("Features:")
    print("• Real-time weather data")
    print("• Weather forecasts")
    print("• Weather alerts")
    print("• Natural language processing")
    print("• Web interface")
    print("=" * 60)
    
    # Check environment variables
    openweather_key = os.getenv('OPENWEATHER_API_KEY')
    openai_key = os.getenv('OPENAI_API_KEY')
    
    if not openweather_key:
        print("āš ļø  Warning: OPENWEATHER_API_KEY not found in environment variables")
        print("   Get your free API key from: https://openweathermap.org/api")
        print("   Set it in your .env file or environment variables")
    else:
        print("āœ… OpenWeatherMap API key configured")
    
    if not openai_key:
        print("āš ļø  Warning: OPENAI_API_KEY not found (optional)")
        print("   Chatbot will work with keyword matching")
        print("   For enhanced NLP, get API key from: https://platform.openai.com/api-keys")
    else:
        print("āœ… OpenAI API key configured")
    
    print("=" * 60)
    
    # Get configuration
    host = os.getenv('HOST', '0.0.0.0')
    port = int(os.getenv('PORT', 5000))
    debug = os.getenv('FLASK_DEBUG', 'True').lower() == 'true'
    
    print(f"šŸš€ Starting Weather Chatbot on http://{host}:{port}")
    print("šŸ“± Web Interface: http://localhost:5000")
    print("šŸ”— API Endpoints:")
    print("   • GET  /health - Health check")
    print("   • POST /chat   - Chat interface")
    print("   • GET  /weather/<city> - Current weather")
    print("   • GET  /forecast/<city> - Weather forecast")
    print("   • GET  /alerts/<city> - Weather alerts")
    print("=" * 60)
    print("Press Ctrl+C to stop the server")
    print("=" * 60)
    
    try:
        # Start the Flask application
        app.run(host=host, port=port, debug=debug)
    except KeyboardInterrupt:
        print("\nšŸ‘‹ Weather Chatbot stopped by user")
        print("Ā© 2026 RSK World. All rights reserved.")
        sys.exit(0)
    except Exception as e:
        print(f"āŒ Error starting server: {e}")
        sys.exit(1)

if __name__ == '__main__':
    main()
93 lines•3.1 KB
python
šŸš€ Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ā¤ļø

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer