def submit( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]: userid = tracker.current_state()["sender_id"] place = str(tracker.get_slot("place")) time = ast.literal_eval(str(tracker.get_slot("time"))) time_start = iso8601.parse_date(str(time['from'])) time_end = iso8601.parse_date(str(time['to'])) planner = ph.restore(self.__storage_path, userid) planner.set_home(place) planner.set_planning_times( globals.to_minutes(time_start.hour, time_start.minute), globals.to_minutes(time_end.hour, time_end.minute)) ph.store(self.__storage_path, userid, planner) dispatcher.utter_message("Thank you! I have set your home location to " + place + " and will plan your day between " + time_start.strftime("%I:%M %p") + " and " + time_end.strftime("%I:%M %p") + ".") return []
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: userid = tracker.current_state()["sender_id"] #print(str(tracker.current_state())) try: #print("place slot: " + str(tracker.get_slot('place'))) old_place = tracker.get_slot('place') #print("old_place: " + str(old_place)) place = self.__querent.get_place_address(str(old_place)) except Exception: dispatcher.utter_message( "Uh oh, I probably made at mistake processing the location you entered, but you may try again :)" ) return [] duration = int( ast.literal_eval(tracker.get_slot('duration'))['additional_info'] ['normalized']['value'] / 60) #event_name = tracker.latest_message['text'] event_name = tracker.get_slot('event_name') if place: planner = ph.restore(self.__storage_path, userid) planner.add_event( Event(event_name, Event.EventType.UNSPECIFIC, duration=duration, place=place)) ph.store(self.__storage_path, userid, planner) (hours, minutes) = globals.to_hours(duration) if hours == 0: duration = str(minutes) + " minutes" elif minutes > 0: if hours > 1: duration = str(hours) + " hours and " + str( minutes) + " minutes" else: duration = str(hours) + " hour and " + str( minutes) + " minutes" else: if hours > 1: duration = str(hours) + " hours" else: duration = str(hours) + " hour" response = ("Alright. I'm planning the event " + event_name + " at " + place + " which will take " + str(duration) + ".") dispatcher.utter_message(response) else: dispatcher.utter_message("I'm sorry but I couldn't find \"" + old_place + "\" entered :(") return []
def save_specific_event(self, dispatcher: CollectingDispatcher, tracker: Tracker, userid, place, event_name, time): time = ast.literal_eval(time) time_start = iso8601.parse_date(str(time["from"])) time_end = iso8601.parse_date(str(time["to"])) planner = ph.restore(self.__storage_path, userid) try: planner.add_event( Event(event_name, Event.EventType.SPECIFIC, start=globals.to_minutes(time_start.hour, time_start.minute), end=globals.to_minutes(time_end.hour, time_end.minute), place=place), [time_start.day, time_start.month, time_start.year]) except Exception: dispatcher.utter_message( "It seems like you already planned an event at this time.") return [] ph.store(self.__storage_path, userid, planner) response = ("Alright. I'm planning the event " + event_name + " at " + place + " on " + time_start.strftime("%A") + ", " + time_start.strftime("%d.%m.%y") + " from " + time_start.strftime("%I:%M %p") + " to " + time_end.strftime("%I:%M %p") + ".") dispatcher.utter_message(response)
def save_unspecific_event(self, dispatcher: CollectingDispatcher, tracker: Tracker, userid, place, event_name, duration): duration = int(duration) planner = ph.restore(self.__storage_path, userid) planner.add_event( Event(event_name, Event.EventType.UNSPECIFIC, duration=duration, place=place)) ph.store(self.__storage_path, userid, planner) (hours, minutes) = globals.to_hours(duration) if hours == 0: duration = str(minutes) + " minutes" elif minutes > 0: if hours > 1: duration = str(hours) + " hours and " + str( minutes) + " minutes" else: duration = str(hours) + " hour and " + str( minutes) + " minutes" else: if hours > 1: duration = str(hours) + " hours" else: duration = str(hours) + " hour" response = ("Alright. I'm planning the event " + event_name + " at " + place + " which will take " + str(duration) + ".") dispatcher.utter_message(response)
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: userid = str(tracker.current_state()["sender_id"]) planner = ph.restore(self.__storage_path, userid) planner.replan(self.__querent) ph.store(self.__storage_path, userid, planner) path = globals.fix_file_path("../storage/schedule_images/", True) PlannerToImage(planner, dt.today()).draw_image(path + str(userid) + '.png') dispatcher.utter_message("/show_plan") return []
def submit( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]: place = str(tracker.get_slot("place")) userid = str(tracker.current_state()["sender_id"]) planner = ph.restore(self.__storage_path, userid) planner.set_home(place) ph.store(self.__storage_path, userid, planner) dispatcher.utter_message("Home set to " + place) return []
globals.debug('sending plan image to user') os.system( "cp storage/schedule_images/" + str(userid) + ".png storage/schedule_images/my_schedule.png") tel_man.send_file( userid, "storage/schedule_images/my_schedule.png") continue if "/remove_event" in resp_text: _, time_stamp = resp_text.split("/remove_event", 1) time_stamp = iso8601.parse_date(time_stamp) globals.debug('user wants to delete an event on day ' + str(time_stamp)) planner = ph.restore("storage/schedules/", userid) event_names = planner.get_day_event_names( time_stamp.day, time_stamp.month, time_stamp.year) if event_names: tel_man.send_message( userid, 'Which event do you want me to delete?', event_names + ["Cancel"]) remove_event_for_user_on_day[userid] = ( time_stamp, len(event_names)) else: tel_man.send_message( userid, 'Nothing is planned on ' + time_stamp.strftime("%A") + ', ' + time_stamp.strftime("%d.%m.%y") + '.')
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: userid = str(tracker.current_state()["sender_id"]) try: old_place = place place = self.__querent.get_place_address(tracker.get_slot('place')) except Exception: dispatcher.utter_message( "Uh oh, I probably made at mistake processing the location you entered, but you may try again :)" ) return [] try: time = json.loads(tracker.get_slot('time').replace("'", '"')) if time['additional_info']['type'] == 'interval': time_start = dt.strptime( str(time['additional_info']['from']['value']), '%Y-%m-%dT%H:%M:%S.000+02:00') time_end = dt.strptime( str(time['additional_info']['to']['value']), '%Y-%m-%dT%H:%M:%S.000+02:00') - datetime.timedelta( hours=1) else: dispatcher.utter_message( "For planning events using an exact time frame I need a start and an end time." ) except Exception: dispatcher.utter_message( "Uh oh, I probably made at mistake processing the time you entered, but you may try again :)" ) return [] #event_name = tracker.latest_message['text'] event_name = tracker.get_slot('event_name') if place: planner = ph.restore(self.__storage_path, userid) try: planner.add_event( Event(event_name, Event.EventType.SPECIFIC, start=globals.to_minutes(time_start.hour, time_start.minute), end=globals.to_minutes(time_end.hour, time_end.minute), place=place), [time_start.day, time_start.month, time_start.year]) except Exception: dispatcher.utter_message( "It seems like you already planned an event at this time.") return [] ph.store(self.__storage_path, userid, planner) response = ("Alright. I'm planning the event " + event_name + " at " + place + " on " + time_start.strftime("%A") + ", " + time_start.strftime("%d.%m.%y") + " from " + time_start.strftime("%I:%M %p") + " to " + time_end.strftime("%I:%M %p") + ".") dispatcher.utter_message(response) else: dispatcher.utter_message("I'm sorry but I couldn't find \"" + old_place + "\" :(") return []