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 []
if callback_queries: for callback_query in callback_queries: callback_query_id = callback_query[0] callback_answer = int(callback_query[1]) tel_man.answer_callback_query(callback_query_id, "Checked!") time_stamp = remove_event_for_user_on_day[userid][0] cancel_bt = remove_event_for_user_on_day[userid][1] if callback_answer < cancel_bt: planner = ph.restore("storage/schedules/", userid) event_name = planner.remove_event_from_day( time_stamp.day, time_stamp.month, time_stamp.year, int(callback_answer)) ph.store("storage/schedules/", userid, planner) tel_man.send_message( userid, "Alright, I removed " + event_name + " from " + time_stamp.strftime("%A") + ', ' + time_stamp.strftime("%d.%m.%y") + '.') else: tel_man.send_message(userid, "No problem :)") if files: for file in files: tel_man.send_message(userid, 'Saving your file...') globals.debug('Processing file "' + file[1] + '" with file_id "' + file[0] + '"') if tel_man.get_file( file[0],
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 []