Spaces:
Runtime error
Runtime error
| import requests | |
| import json | |
| import sys | |
| # Replace YOUR_API_KEY_HERE with your actual API key from OpenWeatherMap | |
| api_key = "1aafc3163909c1493596da9340e00aee" | |
| # Check if a city name was provided as a command line argument | |
| if len(sys.argv) < 2: | |
| print("Please provide a city name as a command line argument.") | |
| sys.exit(1) | |
| # Get the city name from the command line arguments | |
| city_name = sys.argv[1] | |
| # Make the API call to get the current weather details | |
| url = f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&appid={api_key}" | |
| response = requests.get(url) | |
| # Extract the relevant information from the response | |
| if response.status_code == 200: | |
| data = json.loads(response.content) | |
| temperature = data['main']['temp'] | |
| description = data['weather'][0]['description'] | |
| wind_speed = data['wind']['speed'] | |
| print(f"Temperature: {temperature - 273.15:.1f} °C") | |
| print(f"Weather Description: {description.title()}") | |
| print(f"Wind Speed: {wind_speed} m/s") | |
| else: | |
| print(response.json()['message']) |