krrishk22 commited on
Commit
ec6b054
·
verified ·
1 Parent(s): 2e03e9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -44,32 +44,40 @@ def get_current_time_in_timezone(timezone: str) -> str:
44
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
45
 
46
  @tool
47
- def get_horoscope(sign: str, date: str = None, language: str = None) -> str:
48
  """Fetches the horoscope for a given zodiac sign and date.
49
- If the user does not provide a date, use today's real date.
 
50
  Args:
51
  sign: Zodiac sign (e.g., Aries, Taurus, Gemini)
52
  date: Date in any format (optional)
 
53
  """
54
- date = parse_date(date)
55
- # Placeholder logic
56
- if not date:
57
- date = datetime.now().strftime("%Y-%m-%d")
58
-
59
- url = "https://api.exaweb.in:3004/api/rashi"
60
  try:
61
- response = requests.get(url, params={"language": language, "rashi": sign.upper(), "date": date})
 
 
 
 
 
 
 
 
 
62
  response.raise_for_status()
63
  data = response.json()
64
 
65
- # Extract the horoscope
66
- horoscope = data.get("rashiData", {}).get("prediction") or "No prediction found."
67
- today = datetime.now().strftime("%Y-%m-%d")
 
 
 
68
 
69
- return f"Horoscope for {sign.capitalize()} on {today}:\n{horoscope}"
70
 
71
  except Exception as e:
72
- return f"Failed to fetch horoscope for {sign}: {str(e)}"
73
 
74
  @tool
75
  def get_date_panchang(date: str = None) -> str:
 
44
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
45
 
46
  @tool
47
+ def get_horoscope(sign: str, date: str = None, language: str = "EN") -> str:
48
  """Fetches the horoscope for a given zodiac sign and date.
49
+ Uses the ExaWeb API. Defaults to today if no date is provided.
50
+
51
  Args:
52
  sign: Zodiac sign (e.g., Aries, Taurus, Gemini)
53
  date: Date in any format (optional)
54
+ language: Language code ('EN' or 'HI')
55
  """
 
 
 
 
 
 
56
  try:
57
+ # Parse or use today's date
58
+ if date:
59
+ date_obj = parse_date(date)
60
+ else:
61
+ date_obj = datetime.now()
62
+ formatted_date = date_obj.strftime("%d-%m-%Y")
63
+
64
+ # API call
65
+ url = "https://api.exaweb.in:3004/api/rashi/getForAllLangs"
66
+ response = requests.get(url, params={"day": formatted_date, "language": language})
67
  response.raise_for_status()
68
  data = response.json()
69
 
70
+ # Find horoscope for the given sign
71
+ sign_upper = sign.upper()
72
+ for item in data.get("data", []):
73
+ if item.get("sign", "").upper() == sign_upper:
74
+ prediction = item.get("prediction", "No prediction found.")
75
+ return f"Horoscope for {sign.capitalize()} on {formatted_date}:\n{prediction}"
76
 
77
+ return f"No horoscope found for sign: {sign}"
78
 
79
  except Exception as e:
80
+ return f"Error fetching horoscope: {str(e)}"
81
 
82
  @tool
83
  def get_date_panchang(date: str = None) -> str: