main.cpython-311.pyc•3.87 kB
�
1F�g� � �` � d dl mZ d dlmZ d dlZd dlZ e� � ed� � ZdZdZdZ e�
� � defd �� � Ze�
� � d
e
fd�� � Ze�
� � d
e
fd�� � Zed
k re� d�� � dS dS )� )�FastMCP)�load_dotenvN�implementationzThttps://api.tomorrow.io/v4/weather/realtime?location={city}&apikey={weather_api_key}zZhttps://api.tomorrow.io/v4/weather/history/recent?location={city}&apikey={weather_api_key}z.https://api.postalpincode.in/pincode/{pincode}�pincodec � � t | � � } t j t � | �� � � � }|� � � S # t j j $ r}dt |� � icY d}~S d}~ww xY w)z�
Gets the place name for the given pincode.
Args:
pincode (str): The pincode to get the place name for.
Returns:
dict: The place data.
)r �errorN)�str�requests�get�pin_to_place_url�format�json�
exceptions�RequestException)r �response�es �5/Users/vasstavkumarchava/modelcontextprotocol/main.py�
pintoplacer s� � � �'�l�l�G�!��<� 0� 7� 7�� 7� H� H�I�I���}�}�������/� !� !� !���Q��� � � � � � � �����!���s �A A �B�&A<�6B�<B�cityc � � ddd�} t j t � | t j d� � �� � |�� � }|� � � S # t j j $ r}dt |� � icY d}~S d}~ww xY w) z�
Get the realtime weather forecasts for the location.
Args:
city (str): The city to get the weather for.
Returns:
dict: The weather data.
�application/json�deflate, gzip, br��acceptzaccept-encoding�weather_api_key�r r ��headersr N)
r
r �realtime_weather_urlr
�os�getenvr r r r �r r r r s r �realtime_weatherr# # s� � � %�.�� �G�
!��<� 4� ;� ;��WY�W`�ar�Ws�Ws� ;� t� t� F� G� G� G���}�}�������/� !� !� !���Q��� � � � � � � �����!���� �AA �B�1B�B�Bc � � ddd�} t j t � | t j d� � �� � |�� � }|� � � S # t j j $ r}dt |� � icY d}~S d}~ww xY w) a
Get the historical weather forecasts for the location, including hourly history for the last 24 hours, and daily history for the last day.
Args:
city (str): The city to get the weather for.
Returns:
dict: The weather data.
r r r r r r r N)
r
r �hourly_weather_urlr
r r! r r r r r"