skr1125 commited on
Commit
cf8ad12
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -5
app.py CHANGED
@@ -3,20 +3,62 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ from datetime import datetime
7
+ import json
8
  from tools.final_answer import FinalAnswerTool
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def get_new_moon_dates(year:str)-> str: #it's import to specify the return type
15
  #Keep this format for the description / args / args description but feel free to modify the tool
16
+ """Retrieves the dates of new moons for a given year using the USNO API.
17
  Args:
18
+ year:int year as int between 1800 and 2100
19
+ Returns:
20
+ A single string containing the new moon dates separated by tabs, or
21
+ None if there's an error or no data.
22
  """
23
+ url = f"https://aa.usno.navy.mil/api/moon/phases/year?year={year}"
24
+
25
+ try:
26
+ response = requests.get(url)
27
+ response.raise_for_status()
28
+ data = response.json()
29
+
30
+ if data.get('error'):
31
+ print(f"Error from USNO API: {data['error']}")
32
+ return None
33
+
34
+ new_moon_dates = []
35
+ for phase_data in data.get('data', []):
36
+ if phase_data['phase'] == "New Moon":
37
+ date_str = phase_data['date']
38
+ try:
39
+ date_obj = datetime.strptime(date_str, "%Y-%m-%d")
40
+ new_moon_dates.append(date_obj)
41
+ except ValueError as e:
42
+ print(f"Error parsing date: {date_str} - {e}")
43
+ return None
44
+
45
+ new_moon_dates.sort()
46
+
47
+ formatted_dates = [date.strftime("%Y-%m-%d") for date in new_moon_dates]
48
+
49
+ return "\t".join(formatted_dates) # Join with tabs
50
+
51
+ except requests.exceptions.RequestException as e:
52
+ print(f"Error during API request: {e}")
53
+ return None
54
+ except json.JSONDecodeError as e:
55
+ print(f"Error decoding JSON response: {e}")
56
+ return None
57
+ except Exception as e:
58
+ print(f"An unexpected error occurred: {e}")
59
+ return None
60
+
61
+ #return "What magic will you build ?"
62
 
63
  @tool
64
  def get_current_time_in_timezone(timezone: str) -> str: