Skip to content
This repository has been archived by the owner on Oct 14, 2019. It is now read-only.

Commit

Permalink
Add assistantdb.process_schedule (try 'what is my schedule?'), and ot…
Browse files Browse the repository at this point in the history
…her small fixes.
  • Loading branch information
Xyaneon committed Dec 4, 2015
1 parent 37ba002 commit bbbc20c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
26 changes: 26 additions & 0 deletions assistantdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,33 @@ def process_add_cal_event(event_str, verbose):
speech.speak('Sorry, I am unable to help you schedule this right now.', verbose)

def process_weather(verbose):
'''Tells the user what the current weather conditions are.'''
degrees, status = web.GetWeatherInfo()
speech.speak("It is " + degrees + " degrees and " + status.lower() + ".", verbose)

def process_schedule(verbose):
'''Tells the user what events are planned for today from the calendar DB.'''
event_list = calendardb.get_todays_events()
if len(event_list) < 1:
output_str = 'There are no events currently scheduled.'
elif len(event_list) == 1:
output_str = ' '.join(['You only have', event_list[0].event_str, 'at',
event_list[0].start_time_str]) + '.'
elif len(event_list) == 2:
output_str = ' '.join(['You have', event_list[0].event_str, 'at',
event_list[0].start_time_str, 'and',
event_list[1].event_str, 'at',
event_list[1].start_time_str]) + '.'
else:
# 3 or more events
output_str = 'You have '
for event in event_list[:-1]:
output_str += ' '.join([event.event_str, 'at',
event.start_time_str]) + ', '
output_str += ' '.join(['and', event_list[-1].event_str, 'at',
event_list[-1].start_time_str]) + '.'
speech.speak(output_str, verbose)

def parse(verb, verb_object, alternate_verb, alternate_noun, verbose=False):
'''Parse the command and take an action. Returns True if the command is
understood, and False otherwise.'''
Expand Down Expand Up @@ -138,6 +162,8 @@ def parse(verb, verb_object, alternate_verb, alternate_noun, verbose=False):
elif verb == "what is":
if verb_object == "weather":
process_weather(verbose)
if verb_object == "schedule":
process_schedule(verbose)
else:
speech.speak('Sorry, I don\'t understand what you want.', verbose)
return False
Expand Down
10 changes: 5 additions & 5 deletions calendardb.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def next_weekday(weekday, d=datetime.datetime.now()):
return d + datetime.timedelta(days_ahead)

def convert_str_to_date(date_str):
'''Converts a string object to a datetime object.'''
'''Converts a string object to a date object.'''
if date_str.lower() == 'tomorrow':
return datetime.date.today() + datetime.timedelta(days=1)
elif date_str.lower() == 'today':
Expand All @@ -46,7 +46,7 @@ def convert_str_to_date(date_str):
part_list = date_str.split()
day = part_list[1].replace('th', '').replace('rd', '').replace('st', '')
processed_date_str = ' '.join([part_list[0], day, part_list[2]])
return datetime.datetime.strptime(processed_date_str, DATE_STR_FMT)
return datetime.datetime.strptime(processed_date_str, DATE_STR_FMT).date()

class CalendarEvent():
'''Class for storing calendar event information.'''
Expand All @@ -72,7 +72,7 @@ def __str__(self):
def read_events():
'''Returns a list of CalendarEvents from the calendar DB CSV file.'''
event_list = []
with open(calendar_csv_path, 'rb') as calendar_csv:
with open(calendar_csv_path, 'r') as calendar_csv:
calreader = csv.reader(calendar_csv, delimiter=',', quotechar='"')
for row in calreader:
print(', '.join(row))
Expand All @@ -82,13 +82,13 @@ def read_events():
def get_todays_events():
'''Returns a list of CalendarEvents scheduled for today.'''
event_list = read_events()
todays_date = datetime.today.date()
todays_date = datetime.datetime.today().date()
return [event for event in event_list if event.date == todays_date]

def add_event(ce):
'''Adds a new event in list form to the calendar DB CSV file.
Takes a CalendarEvent object.'''
with open(calendar_csv_path, 'wb') as calendar_csv:
with open(calendar_csv_path, 'a') as calendar_csv:
calwriter = csv.writer(calendar_csv, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
cal_row = [ce.event_str,
ce.date.strftime('%B %d %Y'),
Expand Down

0 comments on commit bbbc20c

Please sign in to comment.