File size: 5,543 Bytes
54d6e38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import datetime
import json
import requests
import pytz
from dateutil import parser
from typing import Optional, Literal
from langchain.tools import tool


@tool
def get_horoscope(sign: str, date: str = None, language: str = "EN") -> str:
    """

    Fetches the horoscope for a given zodiac sign and date from the ExaWeb API.

    Defaults to today if no date is provided.



    Args:

        sign: Zodiac sign (e.g., Aries, Taurus, Gemini).

        date: Date in any recognizable format (optional).

        language: Language code (e.g., 'EN' for English, 'HI' for Hindi).

    """
    try:
        if date:
            date_obj = parser.parse(date)
        else:
            date_obj = datetime.datetime.now()
        
        formatted_date = date_obj.strftime("%d-%m-%Y")
        
        params = {
            "rashi": sign.upper(),
            "language": language,
            "day": formatted_date
        }
        url = "https://api.exaweb.in:3004/api/rashi"

        response = requests.get(url, params=params)
        response.raise_for_status()  # Raise an exception for HTTP errors
        
        data = response.json()
        sign_data = data.get(sign.upper())

        if sign_data:
            return json.dumps(sign_data)
        
        return f"INFO: No horoscope found for sign: {sign}"

    except requests.exceptions.RequestException as e:
        return f"ERROR: [get_horoscope]: Network error while fetching horoscope: {e}"
    except Exception as e:
        return f"ERROR: [get_horoscope]: An unexpected error occurred: {str(e)}"



@tool
def get_date_panchang(date: str = None, data_language: str = "EN") -> str:
    """

    Fetches the Panchang data for a given date.

    If the user does not provide a date, use today's real date.



    Args:

        date: Date in any format (optional).

        data_language: Language of the Panchang data (e.g., 'EN' for English, 'HI' for Hindi).

    """
    try:
        if not date:
            now = datetime.datetime.now()
        else:
            now = parser.parse(date)
        
        api_date = now.strftime("%d/%m/%y")
        
        url = (
            f"https://api.exaweb.in:3004/api/panchang/daily?"
            f"date={api_date}&app_language=EN&data_language={data_language}"
        )
        headers = {"api_key": "anvl_bharat_cal123"}
        
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()

        if not isinstance(data, dict) or not data:
            return "ERROR: [get_date_panchang]: Received empty or invalid data from API."

        # Simplified formatting for clarity
        return json.dumps(data)

    except requests.exceptions.RequestException as e:
        return f"ERROR: [get_date_panchang]: Network error while fetching Panchang: {e}"
    except Exception as e:
        return f"ERROR: [get_date_panchang]: An unexpected error occurred: {str(e)}"



@tool
def get_holidays(year: int = None, data_language: str = "EN") -> str:
    """

    Fetches holidays from all categories for a given year from ExaWeb API.



    Args:

        year: Year (e.g., 2025). Optional — defaults to current year.

        data_language: Data language for holidays (default: "EN").

    """
    if not year:
        year = datetime.datetime.now().year
        
    params = {"data_language": data_language, "year": year}
    headers = {"api_key": "anvl_bharat_cal123"}

    try:
        response = requests.get(
            "https://api.exaweb.in:3004/api/panchang/holiday",
            params=params,
            headers=headers
        )
        response.raise_for_status()
        data = response.json()
        return json.dumps(data)

    except requests.exceptions.RequestException as e:
        return f"ERROR: [get_holidays]: Network error fetching holidays: {e}"
    except Exception as e:
        return f"ERROR: [get_holidays]: An unexpected error occurred: {str(e)}"



@tool
def get_monthly_festivals(year: Optional[int] = None, month: Optional[str] = None, data_language: str = "EN") -> str:
    """

    Fetches festival data for a specific month and year from the ExaWeb API.

    

    Args:

        year: The year to fetch (e.g., 2025). Defaults to current year.

        month: The full month name to fetch (e.g., "june"). Defaults to current month.

        data_language: The language for the festival names (default: "EN").

    """
    if not year:
        year = datetime.datetime.now().year
    if not month:
        month = datetime.datetime.now().strftime("%B").lower()
    else:
        month = month.lower()

    api_url = "https://api.exaweb.in:3004/api/panchang/festival"
    params = {"year": year, "month": month, "data_language": data_language}
    headers = {"api_key": "anvl_bharat_cal123"}

    try:
        response = requests.get(api_url, params=params, headers=headers)
        response.raise_for_status()
        data = response.json()
        return json.dumps(data)

    except requests.exceptions.RequestException as e:
        return f"ERROR: [get_monthly_festivals]: Network error while fetching data: {e}"
    except Exception as e:
        return f"ERROR: [get_monthly_festivals]: An unexpected error occurred: {str(e)}"


# List of all tools available in the module

all_tools = [
    get_horoscope, 
    get_date_panchang, 
    get_holidays, 
    get_monthly_festivals
]