krrishk22 commited on
Commit
f0d0d00
·
verified ·
1 Parent(s): 33d720e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -150,13 +150,7 @@ def get_date_panchang(date: str = None, data_language: str = "EN") -> str:
150
  @tool
151
  def get_holidays(year: int = None, app_language: str = "EN", data_language: str = "HI") -> 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
- app_language: App language for API (default: "EN").
159
- data_language: Data language for holidays (default: "HI").
160
  """
161
  if not year:
162
  year = datetime.datetime.now().year
@@ -171,32 +165,34 @@ def get_holidays(year: int = None, app_language: str = "EN", data_language: str
171
  }
172
 
173
  try:
174
- response = requests.get("https://api.exaweb.in:3004/api/panchang/holiday", params=params, headers=headers)
 
 
 
 
175
  response.raise_for_status()
176
  data = response.json()
177
 
178
- holidays = []
179
-
180
- hindu_holidays = data.get("Hindu", [])
181
-
182
- # The response structure has nested lists, so we flatten and collect
183
- for month_list in hindu_holidays:
184
- for holiday in month_list:
185
- title = holiday.get("title", "")
186
- date = holiday.get("date", "")
187
- holidays.append(f"{date}: {title}")
188
 
189
- if not holidays:
190
- return f"No holiday data found for year {year}."
191
 
192
- formatted_holidays = "\n".join(holidays)
193
- return f"Holidays for {year}:\n{formatted_holidays}"
 
 
 
 
 
194
 
195
  except requests.RequestException as e:
196
  return f"Error fetching holidays: {e}"
197
 
198
 
199
-
200
  @tool
201
  def get_panchang_field(field: str, date: str = None) -> str:
202
  """Fetches specific Panchang field like Tithi, Nakshatra, Yoga, etc.
 
150
  @tool
151
  def get_holidays(year: int = None, app_language: str = "EN", data_language: str = "HI") -> str:
152
  """
153
+ Fetches holidays from all categories (Hindu, Islamic, Christian) for a given year from ExaWeb API.
 
 
 
 
 
 
154
  """
155
  if not year:
156
  year = datetime.datetime.now().year
 
165
  }
166
 
167
  try:
168
+ response = requests.get(
169
+ "https://api.exaweb.in:3004/api/panchang/holiday",
170
+ params=params,
171
+ headers=headers
172
+ )
173
  response.raise_for_status()
174
  data = response.json()
175
 
176
+ formatted = []
177
+
178
+ for category, groups in data.items():
179
+ if category in ["year", "app_language", "data_language"]:
180
+ continue # Skip non-holiday keys
 
 
 
 
 
181
 
182
+ formatted.append(f"\n=== {category} Holidays ===")
 
183
 
184
+ for group in groups:
185
+ for holiday in group:
186
+ title = holiday.get("title", "")
187
+ date = holiday.get("date", "")
188
+ formatted.append(f"{date}: {title}")
189
+
190
+ return "\n".join(formatted) if formatted else f"No holidays found for {year}."
191
 
192
  except requests.RequestException as e:
193
  return f"Error fetching holidays: {e}"
194
 
195
 
 
196
  @tool
197
  def get_panchang_field(field: str, date: str = None) -> str:
198
  """Fetches specific Panchang field like Tithi, Nakshatra, Yoga, etc.