krrishk22 commited on
Commit
ac7979e
·
verified ·
1 Parent(s): 5091df2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -6
app.py CHANGED
@@ -148,16 +148,49 @@ def get_date_panchang(date: str = None, data_language: str = "EN") -> str:
148
 
149
 
150
  @tool
151
- def get_holidays(year: int = None, date: str = None) -> str:
152
- """Fetches government and popular holidays for a given date or year.
 
153
  Does not include Panchang events like Ekadashi.
 
154
  Args:
155
  year: Year (e.g., 2025). Optional — defaults to current year.
156
- date: Date in any format (optional)
157
  """
158
- if not date and not year:
159
- year = datetime.now().year
160
- return f"Holidays for {date or year}: [Sample list of holidays]"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  @tool
163
  def get_panchang_field(field: str, date: str = None) -> str:
 
148
 
149
 
150
  @tool
151
+ def get_holidays(year: int = None) -> str:
152
+ """
153
+ Fetches government and popular holidays for a given year from ExaWeb API.
154
  Does not include Panchang events like Ekadashi.
155
+
156
  Args:
157
  year: Year (e.g., 2025). Optional — defaults to current year.
 
158
  """
159
+ if not year:
160
+ year = datetime.datetime.now().year
161
+
162
+ params = {
163
+ "app_language": "EN",
164
+ "data_language": "HI",
165
+ "year": year
166
+ }
167
+
168
+ try:
169
+ response = requests.get("https://api.exaweb.in:3004/api/panchang/holiday", params=params)
170
+ response.raise_for_status()
171
+ data = response.json()
172
+
173
+ holidays = []
174
+
175
+ hindu_holidays = data.get("Hindu", [])
176
+
177
+ # The response structure has nested lists, so we flatten and collect
178
+ for month_list in hindu_holidays:
179
+ for holiday in month_list:
180
+ title = holiday.get("title", "")
181
+ date = holiday.get("date", "")
182
+ holidays.append(f"{date}: {title}")
183
+
184
+ if not holidays:
185
+ return f"No holiday data found for year {year}."
186
+
187
+ formatted_holidays = "\n".join(holidays)
188
+ return f"Holidays for {year}:\n{formatted_holidays}"
189
+
190
+ except requests.RequestException as e:
191
+ return f"Error fetching holidays: {e}"
192
+
193
+
194
 
195
  @tool
196
  def get_panchang_field(field: str, date: str = None) -> str: