diff --git a/universities-building-program/columbia.py b/universities-building-program/columbia.py index 6a64a448..26f30a0b 100644 --- a/universities-building-program/columbia.py +++ b/universities-building-program/columbia.py @@ -1,43 +1,34 @@ -# ============================================================ -# Columbia University Challenge: Implement the "weather" command. -# -# When a user sends a message like "weather London", -# your agent should fetch live weather data for the given city. -# -# Hints: -# 1. Use the 'requests' library for HTTP GET requests. -# 2. Consider using the OpenWeatherMap API: https://openweathermap.org/api. -# (You will need to sign up for a free API key.) -# 3. Parse the input to extract the city name. -# 4. Construct the API URL using the city name and your API key. -# 5. Check if the response is successful, then parse the JSON to extract temperature and weather conditions. -# -# Useful resources: -# - Requests documentation: https://docs.python-requests.org/en/latest/ -# - OpenWeatherMap API: https://openweathermap.org/api -# ============================================================ - import requests def handle_message(message: str) -> str: message = message.lower() if "hello" in message: return "Hello, welcome to NEAR AI!" - elif message.startswith("weather"): - # TODO: Implement the weather command. - # Steps: - # 1. Split the message to extract the city name. - # 2. Verify that a city name was provided. - # 3. Build the API URL using the city name and your OpenWeatherMap API key. - # (Replace 'YOUR_API_KEY' with your actual key.) - # 4. Make a GET request to the weather API. - # 5. If the response is successful, parse the JSON to extract temperature and condition details. - # 6. Return a formatted string with the weather information. - pass + elif message.startswith("bitcoin"): + url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest" + headers = { + 'Accepts': 'application/json', + 'X-CMC_PRO_API_KEY': 'enter CoinMarketCapAPI Key' + } + params = { + 'start': '1', + 'limit': '10', + 'convert': 'USD' + } + + response = requests.get(url, headers=headers, params=params) + + if response.status_code == 200: + data = response.json() + for coin in data['data']: + if coin['symbol'] == 'BTC': + price = coin['quote']['USD']['price'] + return f"BTC price: ${price:,.2f}" + return "BTC not found in the response." else: - return "I'm sorry, I didn't understand your message." + return f"Error: {response.status_code} - {response.text}" + -# Optional testing block: -# if __name__ == "__main__": -# user_input = input("Enter a message for the agent: ") -# print(handle_message(user_input)) +if __name__ == "__main__": + user_input = input("Search real-time price of : ") + print(handle_message(user_input))