-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.py
49 lines (43 loc) · 1.62 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from google.oauth2 import service_account
from googleapiclient.discovery import build
from datetime import datetime, timedelta
import openai
import pytz
# replace with your own credentials and calendar ID
SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = 'path/to/your/credentials.json'
CALENDAR_ID = 'your.calendar.id@domain.com'
# authenticate with OpenAI
openai.api_key = 'your_openai_api_key'
def create_event(start_time, end_time, summary):
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('calendar', 'v3', credentials=credentials)
event = {
'summary': summary,
'start': {
'dateTime': start_time.isoformat(),
'timeZone': 'America/New_York',
},
'end': {
'dateTime': end_time.isoformat(),
'timeZone': 'America/New_York',
},
}
event = service.events().insert(calendarId=CALENDAR_ID, body=event).execute()
print('Event created: %s' % (event.get('htmlLink')))
prompt = "Get my calendar events for the week starting on Wednesday Apr 12 at 3pm."
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
events = response.choices[0].text.split('\n')
start_time = datetime(2023, 4, 12, 15, 0, 0)
start_time = pytz.timezone('America/New_York').localize(start_time)
for i, summary in enumerate(events):
end_time = start_time + timedelta(hours=1)
create_event(start_time, end_time, summary.strip())
start_time = start_time + timedelta(days=1)