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
travel-assistant-bot
/
services
RSK World
travel-assistant-bot
Travel Assistant Bot - Python + Flask + OpenAI API + Travel Bot + Flight Search + Hotel Booking + Weather
services
  • __pycache__
  • __init__.py169 B
  • cache.py560 B
  • flight_service.py1.1 KB
  • hotel_service.py971 B
  • openai_service.py1.5 KB
  • recommendation_service.py776 B
  • weather_service.py1.4 KB
weather_service.py
services/weather_service.py
Raw Download
Find: Go to:
# RSK World - Free Programming Resources & Source Code
# Founder: Molla Samser | Designer & Tester: Rima Khatun
# Website: https://rskworld.in/contact.php | Year: 2026
import os
from typing import Dict, Optional
import requests
from .cache import get as cache_get, set as cache_set


def get_weather(location: Optional[str]) -> Dict:
    if not location:
        return {"error": "location required"}
    key = f"weather:{location.lower()}"
    cached = cache_get(key)
    if cached:
        return cached
    api_key = os.getenv("OPENWEATHER_API_KEY")
    if not api_key:
        return {
            "location": location,
            "note": "Provide OPENWEATHER_API_KEY to fetch live weather.",
        }
    try:
        r = requests.get(
            "https://api.openweathermap.org/data/2.5/weather",
            params={"q": location, "appid": api_key, "units": "metric"},
            timeout=10,
        )
        data = r.json()
        main = data.get("main", {})
        weather = (data.get("weather") or [{}])[0]
        result = {
            "location": location,
            "temp_c": main.get("temp"),
            "description": weather.get("description"),
            "humidity": main.get("humidity"),
        }
        cache_set(key, result, ttl=300)
        return result
    except Exception:
        return {"location": location, "error": "failed to fetch weather"}
42 lines•1.4 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