Upload weather_server.py with huggingface_hub
Browse files- weather_server.py +65 -0
weather_server.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
import random
|
| 3 |
+
|
| 4 |
+
mcp = FastMCP("WeatherAgent")
|
| 5 |
+
|
| 6 |
+
@mcp.tool()
|
| 7 |
+
def get_forecast(city: str, dates: str) -> str:
|
| 8 |
+
"""Get the weather forecast for a city during specific dates."""
|
| 9 |
+
conditions = [
|
| 10 |
+
("Sunny", "☀️", "Perfect for outdoor activities!"),
|
| 11 |
+
("Partly Cloudy", "⛅", "Great weather overall"),
|
| 12 |
+
("Cloudy", "☁️", "Mild and comfortable"),
|
| 13 |
+
("Light Rain", "🌧️", "Bring an umbrella"),
|
| 14 |
+
("Rainy", "🌧️", "Pack rain gear"),
|
| 15 |
+
("Windy", "💨", "Layer up!")
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
results = []
|
| 19 |
+
results.append(f"🌤️ **Weather Forecast for {city}**")
|
| 20 |
+
results.append(f"📅 {dates}")
|
| 21 |
+
results.append("---")
|
| 22 |
+
|
| 23 |
+
for i in range(5):
|
| 24 |
+
cond, emoji, tip = random.choice(conditions)
|
| 25 |
+
temp_high = random.randint(20, 32)
|
| 26 |
+
temp_low = temp_high - random.randint(5, 10)
|
| 27 |
+
humidity = random.randint(40, 80)
|
| 28 |
+
|
| 29 |
+
results.append(f"")
|
| 30 |
+
results.append(f"**Day {i+1}:** {emoji} {cond}")
|
| 31 |
+
results.append(f" 🌡️ High: {temp_high}°C / Low: {temp_low}°C")
|
| 32 |
+
results.append(f" 💧 Humidity: {humidity}%")
|
| 33 |
+
results.append(f" 💡 {tip}")
|
| 34 |
+
|
| 35 |
+
results.append("")
|
| 36 |
+
results.append("---")
|
| 37 |
+
results.append("🧳 **Packing Tip:** Light layers, comfortable walking shoes, and don't forget sunscreen!")
|
| 38 |
+
|
| 39 |
+
return "\n".join(results)
|
| 40 |
+
|
| 41 |
+
@mcp.tool()
|
| 42 |
+
def get_packing_list(weather_conditions: str, activity_types: str) -> str:
|
| 43 |
+
"""Generate a packing list based on weather and activities."""
|
| 44 |
+
items = ["💳 Passport & ID", "🔌 Phone Charger", "🧼 Toiletries"]
|
| 45 |
+
|
| 46 |
+
# Weather based
|
| 47 |
+
if "Rain" in weather_conditions:
|
| 48 |
+
items.extend(["☔ Umbrella", "🧥 Raincoat", "🥾 Waterproof shoes"])
|
| 49 |
+
if "Sunny" in weather_conditions:
|
| 50 |
+
items.extend(["🕶️ Sunglasses", "🧴 Sunscreen SPF50", "🧢 Hat"])
|
| 51 |
+
if "Cold" in weather_conditions or "Windy" in weather_conditions:
|
| 52 |
+
items.extend(["🧥 Warm Jacket", "🧣 Scarf"])
|
| 53 |
+
|
| 54 |
+
# Activity based
|
| 55 |
+
if "Swimming" in activity_types or "Beach" in activity_types:
|
| 56 |
+
items.extend(["🩲 Swimsuit", "🏖️ Beach Towel", "🩴 Flip flops"])
|
| 57 |
+
if "Hiking" in activity_types or "Walking" in activity_types:
|
| 58 |
+
items.extend(["🥾 Hiking Shoes", "🎒 Backpack", "🧺 Water Bottle"])
|
| 59 |
+
if "Dinner" in activity_types or "Nightlife" in activity_types:
|
| 60 |
+
items.extend(["👔 Smart Casual Outfit", "👞 Dress Shoes"])
|
| 61 |
+
|
| 62 |
+
return "🧳 **Recommended Packing List:**\n\n" + "\n".join(f"• {item}" for item in items)
|
| 63 |
+
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
mcp.run()
|