Skip to content

Commit 718ead8

Browse files
authored
Merge branch 'main' into main
2 parents f0dfe8b + 17c0872 commit 718ead8

File tree

10 files changed

+443
-455
lines changed

10 files changed

+443
-455
lines changed

interpreter/core/computer/calendar/calendar.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
from ..utils.run_applescript import run_applescript, run_applescript_capture
66

77

8+
makeDateFunction = """
9+
on makeDate(yr, mon, day, hour, min, sec)
10+
set theDate to current date
11+
tell theDate
12+
set its year to yr
13+
set its month to mon
14+
set its day to day
15+
set its hours to hour
16+
set its minutes to min
17+
set its seconds to sec
18+
end tell
19+
return theDate
20+
end makeDate
21+
"""
22+
823
class Calendar:
924
def __init__(self, computer):
1025
self.computer = computer
@@ -18,23 +33,13 @@ def get_events(self, start_date=datetime.date.today(), end_date=None):
1833
if platform.system() != "Darwin":
1934
return "This method is only supported on MacOS"
2035

21-
# Format dates for AppleScript
22-
applescript_start_date = (
23-
start_date.strftime("%A, %B %d, %Y") + " at 12:00:00 AM"
24-
)
25-
if end_date:
26-
applescript_end_date = (
27-
end_date.strftime("%A, %B %d, %Y") + " at 11:59:59 PM"
28-
)
29-
else:
30-
applescript_end_date = (
31-
start_date.strftime("%A, %B %d, %Y") + " at 11:59:59 PM"
32-
)
33-
36+
if not end_date:
37+
end_date = start_date
3438
# AppleScript command
3539
script = f"""
36-
set theDate to date "{applescript_start_date}"
37-
set endDate to date "{applescript_end_date}"
40+
{makeDateFunction}
41+
set theDate to makeDate({start_date.strftime("%Y, %m, %d, 0, 0, 0")})
42+
set endDate to makeDate({end_date.strftime("%Y, %m, %d, 23, 59, 59")})
3843
tell application "System Events"
3944
set calendarIsRunning to (name of processes) contains "{self.calendar_app}"
4045
if calendarIsRunning then
@@ -179,6 +184,9 @@ def create_event(
179184
return "Can't find a default calendar. Please try again and specify a calendar name."
180185

181186
script = f"""
187+
{makeDateFunction}
188+
set startDate to makeDate({start_date.strftime("%Y, %m, %d, %H, %M, %S")})
189+
set endDate to makeDate({end_date.strftime("%Y, %m, %d, %H, %M, %S")})
182190
-- Open and activate calendar first
183191
tell application "System Events"
184192
set calendarIsRunning to (name of processes) contains "{self.calendar_app}"
@@ -192,8 +200,6 @@ def create_event(
192200
end tell
193201
tell application "{self.calendar_app}"
194202
tell calendar "{calendar}"
195-
set startDate to date "{applescript_start_date}"
196-
set endDate to date "{applescript_end_date}"
197203
make new event at end with properties {{summary:"{title}", start date:startDate, end date:endDate, location:"{location}", description:"{notes}"}}
198204
end tell
199205
-- tell the Calendar app to refresh if it's running, so the new event shows up immediately
@@ -223,9 +229,9 @@ def delete_event(
223229
if not calendar:
224230
return "Can't find a default calendar. Please try again and specify a calendar name."
225231

226-
# Format datetime for AppleScript
227-
applescript_start_date = start_date.strftime("%B %d, %Y %I:%M:%S %p")
228232
script = f"""
233+
{makeDateFunction}
234+
set eventStartDate to makeDate({start_date.strftime("%Y, %m, %d, %H, %M, %S")})
229235
-- Open and activate calendar first
230236
tell application "System Events"
231237
set calendarIsRunning to (name of processes) contains "{self.calendar_app}"
@@ -242,7 +248,6 @@ def delete_event(
242248
set myCalendar to calendar "{calendar}"
243249
244250
-- Define the exact start date and name of the event to find and delete
245-
set eventStartDate to date "{applescript_start_date}"
246251
set eventSummary to "{event_title}"
247252
248253
-- Find the event by start date and summary

interpreter/core/computer/display/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import requests
1313
from ...utils.lazy_import import lazy_import
1414
from ..utils.recipient_utils import format_to_recipient
15-
import cv2
1615
from screeninfo import get_monitors # for getting info about connected monitors
1716

1817

1918
# Still experimenting with this
2019
# from utils.get_active_window import get_active_window
2120

2221
# Lazy import of optional packages
22+
cv2 = lazy_import("cv2")
2323
pyautogui = lazy_import("pyautogui")
2424
np = lazy_import("numpy")
2525
plt = lazy_import("matplotlib.pyplot")

interpreter/core/default_system_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
```python
1919
computer.browser.search(query) # Google search results will be returned from this function as a string
2020
computer.files.edit(path_to_file, original_text, replacement_text) # Edit a file
21-
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
21+
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
2222
computer.calendar.get_events(start_date=datetime.date.today(), end_date=None) # Get events between dates. If end_date is None, only gets events for start_date
2323
computer.calendar.delete_event(event_title="Meeting", start_date=datetime.datetime) # Delete a specific event with a matching title and start date, you may need to get use get_events() to find the specific event object first
2424
computer.contacts.get_phone_number("John Doe")

interpreter/core/render_message.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import re
2-
import time
32

43

54
def render_message(interpreter, message):
@@ -13,31 +12,19 @@ def render_message(interpreter, message):
1312
# Split the message into parts by {{ and }}, including multi-line strings
1413
parts = re.split(r"({{.*?}})", message, flags=re.DOTALL)
1514

16-
for i in range(len(parts)):
17-
part = parts[i]
15+
for i, part in enumerate(parts):
1816
# If the part is enclosed in {{ and }}
1917
if part.startswith("{{") and part.endswith("}}"):
2018
# Run the code inside the brackets
2119
output = interpreter.computer.run(
2220
"python", part[2:-2].strip(), display=interpreter.verbose
2321
)
2422

25-
# Turn it into just a simple string
26-
outputs = []
27-
for line in output:
28-
if interpreter.debug:
29-
print(line)
30-
if line.get("format") == "output":
31-
if "IGNORE_ALL_ABOVE_THIS_LINE" in line["content"]:
32-
outputs.append(
33-
line["content"].split("IGNORE_ALL_ABOVE_THIS_LINE")[1]
34-
)
35-
else:
36-
outputs.append(line["content"])
37-
output = "\n".join(outputs)
23+
# Extract the output content
24+
outputs = (line["content"] for line in output if line.get("format") == "output" and "IGNORE_ALL_ABOVE_THIS_LINE" not in line["content"])
3825

3926
# Replace the part with the output
40-
parts[i] = output
27+
parts[i] = "\n".join(outputs)
4128

4229
# Join the parts back into the message
4330
rendered_message = "".join(parts).strip()

interpreter/terminal_interface/profiles/defaults/01.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
```python
7070
result_string = computer.browser.search(query) # Google search results will be returned from this function as a string
7171
computer.files.edit(path_to_file, original_text, replacement_text) # Edit a file
72-
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
72+
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
7373
events_string = computer.calendar.get_events(start_date=datetime.date.today(), end_date=None) # Get events between dates. If end_date is None, only gets events for start_date
7474
computer.calendar.delete_event(event_title="Meeting", start_date=datetime.datetime) # Delete a specific event with a matching title and start date, you may need to get use get_events() to find the specific event object first
7575
phone_string = computer.contacts.get_phone_number("John Doe")
@@ -216,7 +216,7 @@ def get_function_info(file_path):
216216
print("Attempting to start OS control anyway...\n\n")
217217

218218
for pip_name in ["pip", "pip3"]:
219-
command = f"{pip_name} install 'open-interpreter[os]'"
219+
command = f"{pip_name} install open-interpreter[os]"
220220

221221
interpreter.computer.run("shell", command, display=True)
222222

interpreter/terminal_interface/profiles/defaults/os.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
print('''
6363
computer.browser.search(query) # Google search results will be returned from this function as a string
6464
computer.files.edit(path_to_file, original_text, replacement_text) # Edit a file
65-
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
65+
computer.calendar.create_event(title="Meeting", start_date=datetime.datetime.now(), end_date=datetime.datetime.now() + datetime.timedelta(hours=1), notes="Note", location="") # Creates a calendar event
6666
computer.calendar.get_events(start_date=datetime.date.today(), end_date=None) # Get events between dates. If end_date is None, only gets events for start_date
6767
computer.calendar.delete_event(event_title="Meeting", start_date=datetime.datetime) # Delete a specific event with a matching title and start date, you may need to get use get_events() to find the specific event object first
6868
computer.contacts.get_phone_number("John Doe")
@@ -170,7 +170,7 @@
170170
print("Attempting to start OS control anyway...\n\n")
171171

172172
for pip_name in ["pip", "pip3"]:
173-
command = f"{pip_name} install 'open-interpreter[os]'"
173+
command = f"{pip_name} install open-interpreter[os]"
174174

175175
interpreter.computer.run("shell", command, display=True)
176176

interpreter/terminal_interface/terminal_interface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def terminal_interface(interpreter, message):
8888
# This is for the terminal interface being used as a CLI — messages are strings.
8989
# This won't fire if they're in the python package, display=True, and they passed in an array of messages (for example).
9090

91+
if message == "":
92+
# Ignore empty messages when user presses enter without typing anything
93+
continue
94+
9195
if message.startswith("%") and interactive:
9296
handle_magic_command(interpreter, message)
9397
continue

0 commit comments

Comments
 (0)