def state_3(user_fb_id, user_msg, states): print("state three executing") #Check for reset command if user_msg == "reset" or user_msg == "Reset": new_state = 0 msg = "Reset Selected - Please enter the city you live in" temp = [user_fb_id, 0, 0, 0, 0, 0, False] update_user(temp) return new_state, msg #This should be main menu! #for now just output what they are #user id, current state, city, address, week type, pickup day,reminder setting user = pull_user(user_fb_id) #Check for tricky stuff #if holiday is not true garbage_date, holiday_flag = guelph_garbage_api.next_pickup_date( datetime.date.today(), user[5]) garbage_day = garbage_date.strftime("%A") garbage_type = guelph_garbage_api.garbage_type(user[4], garbage_date) #if holiday = true some message, not working yet new_state = 3 msg = "Your upcoming garbage day is " + garbage_day.upper() + " and you should put out ORGANICS and " + \ garbage_type.upper() + ". Message anything whenever you want an update and type reset to change any settings" return new_state, msg
def state_3(user_fb_id, user_msg, states): #print("state three executing") #Check for reset command if user_msg == "reset" or user_msg == "Reset": new_state = 0 msg = "Reset Selected - Please enter the city you live in" temp = [user_fb_id, 0, 0, 0, 0, 0, False] update_user(temp) return new_state, msg #This should be main menu! #for now just output what they are #user id, current state, city, address, week type, pickup day,reminder setting user = pull_user(user_fb_id) #Check for tricky stuff #if holiday is not true garbage_date, holiday_flag = guelph_garbage_api.next_pickup_date( datetime.date.today(), user[5]) garbage_day = garbage_date.strftime("%A") garbage_type = guelph_garbage_api.garbage_type(user[4], garbage_date) #if holiday = true some message, not working yet #if today modify garbage_day if datetime.date.today().strftime("%A").lower() == garbage_day.lower(): msg = "Your Garbage day is TODAY, you should, or should have :), put out your ORGANICS and " + \ garbage_type.upper() + " this morning." else: msg = "Your upcoming garbage day is " + garbage_day.upper() + " and you should put out ORGANICS and " + \ garbage_type.upper() + "." new_state = 3 return new_state, msg
def state_1(user_fb_id, user_msg, states): #print("state one executing") #Check for reset command if user_msg == "reset" or user_msg == "Reset": new_state = 0 msg = "Reset Selected - Please enter the city you live in" temp = [user_fb_id, 0, 0, 0, 0, 0, True] update_user(temp) return new_state, msg #Some address check, if invalid send to state_1_error parsed = re.split(r'(?<=\d)(?:-\d+)?\s+', user_msg) #Check that address has two parts and that the first part is a string if len(parsed) != 2 or type(parsed[0]) == int: return 1, "Sorry I don't think this is a valid address! Try re-entering it." user = pull_user(user_fb_id) user[3] = user_msg #Pull the relevant garbage day info out! #assuming just for guelph for now pickup_info = guelph_garbage_api.guelph_garbage(parsed[0], parsed[1]) #If error flag is passed through guelph_garbage function then prompt for re-entry if pickup_info[0] == "error": msg = "Sorry I can't find the address you entered, please re-enter your address or type reset to change the city you live in." return 1, msg user[4] = pickup_info[0] user[5] = pickup_info[1] #user id, current state, city, address, week type, pickup day,reminder setting update_user(user) #Get tailored info garbage_date, holiday_flag = guelph_garbage_api.next_pickup_date( datetime.date.today(), user[5]) garbage_day = garbage_date.strftime("%A") garbage_type = guelph_garbage_api.garbage_type(user[4], garbage_date) if datetime.date.today().strftime("%A").lower() == garbage_day.lower(): msg = "Great this means that your pickup day is "+pickup_info[1]+ " and you are on the " + pickup_info[0] + \ " schedule. So this morning you should, or should have :), put out your ORGANICS and " + garbage_type.upper() + \ ". Do you want to setup a reminder for the evening before?" else: msg = "Great this means that your pickup day is "+pickup_info[1]+ " and you are on the " + pickup_info[0] + \ " schedule. So this upcoming " + pickup_info[1] + " you should put out your ORGANICS and " + garbage_type.upper() + \ ". Do you want to setup a reminder for the evening before?" #send to new state new_state = 2 return new_state, msg
def pickup_day(message, user): '''pickup day routine, this controls flow through the pickup day routine''' #user id, current state, city, address, week type, pickup day, reminder setting, confusion, thread, lvl if user.address != 'first' and int(user.lvl) != 2: #reply_msg = 'Your address is set to: ' + user.address + ' which means your garbage day is ' + user.pickup_day.upper() + ' and you are on the ' + user.week_type.upper() + ' schedule.' #***************************************************** garbage_date, holiday_flag = guelph_garbage_api.next_pickup_date( datetime.date.today(), user.pickup_day) garbage_day = garbage_date.strftime("%A") garbage_type = guelph_garbage_api.garbage_type(user.week_type, garbage_date) #if holiday = true some message, not working yet #if today modify garbage_day if datetime.date.today().strftime("%A").lower() == garbage_day.lower(): reply_msg = "Your Garbage day is TODAY, you should, or should have :), put out your ORGANICS and " + \ garbage_type.upper() + " this morning." else: reply_msg = "Your upcoming garbage day is " + garbage_day.upper() + " and you should put out ORGANICS and " + \ garbage_type.upper() + "." #***************************************************** user.thread = '?' user.lvl = '0' elif int(user.lvl) == 0: reply_msg = 'To help you I need your STREET ADDRESS, please enter it now.' user.lvl = 1 elif int(user.lvl) == 1: #test for valid address parsed = re.split(r'(?<=\d)(?:-\d+)?\s+', message) #Check that address has two parts and that the first part is a string if len(parsed) != 2 or type(parsed[0]) == int: #Check for previous confusion and exit if they are confused again if int(user.confusion) == 1: reply_msg = 'Alright there seems to be some confusion, I let my supervisor know and ' + \ 'they will be getting back to you. In the mean time is there anything else I can do for you?' notify_human(message, user) user.confusion = 0 user.thread = '?' user.lvl = 0 else: reply_msg = 'Sorry I don\'t think this is a valid address! Try re-entering it.' user.confusion = 1 else: #Check address in Guelph Database pickup_info = guelph_garbage_api.guelph_garbage( parsed[0], parsed[1]) #If error flag is passed through guelph_garbage function then prompt for re-entry if pickup_info[0] == "error": reply_msg = "Sorry I can't find your address in my database, I let my supervisor know and they will be getting back to you." notify_human(message, user) user.confusion = 0 user.thread = '?' user.lvl = 0 else: #This mean the information received back from the garbage day lookup is good so it can be stored user.week_type = pickup_info[0] user.pickup_day = pickup_info[1] user.address = message #reply_msg = 'Great that means your garbage day is ' + user.pickup_day.upper() + '. Would you like to set a reminder?' #Get tailored info ****************************************************************** garbage_date, holiday_flag = guelph_garbage_api.next_pickup_date( datetime.date.today(), user.pickup_day) garbage_day = garbage_date.strftime("%A") garbage_type = guelph_garbage_api.garbage_type( user.week_type, garbage_date) if datetime.date.today().strftime( "%A").lower() == garbage_day.lower(): reply_msg = "Great this means that your pickup day is "+pickup_info[1]+ " and you are on the " + pickup_info[0] + \ " schedule. So this morning you should, or should have :), put out your ORGANICS and " + garbage_type.upper() + \ ". Do you want to setup a REMINDER?" else: reply_msg = "Great this means that your pickup day is "+pickup_info[1]+ " and you are on the " + pickup_info[0] + \ " schedule. So this upcoming " + pickup_info[1] + " you should put out your ORGANICS and " + garbage_type.upper() + \ ". Do you want to setup a REMINDER?" #***************************************************************************************** user.lvl = 2 #Move to next step elif int(user.lvl) == 2: #this should be converted to natural language processing lower_msg = message.lower() if lower_msg == "yes" or lower_msg == "sure" or lower_msg == "yeah" or lower_msg == "okay" or lower_msg == "yes please" or lower_msg == "thanks" or lower_msg == "thank you" or lower_msg == "thanks!": #If reminder requested pass directly to change_reminder routine #this should work if the user requests a reminder with or without a time user.thread = 'start_reminder' user.lvl = 0 user.confusion = 0 reply_msg, user = change_reminder(message, user) #this should be replaced with language processing elif lower_msg == "no" or lower_msg == "nah" or lower_msg == "no thanks" or lower_msg == "nope": reminder = False reply_msg = "Understood, anything else I can do for you?" user.reminder = reminder user.thread = '?' user.lvl = 0 user.confusion = 0 else: #Check for confusion if int(user.confusion) == 1: reply_msg = 'Sorry I still don\'t understand if you want a reminder or not, no problem I sent our conversation to my supervisor for clarification. ' + \ 'They will get back to you on this, in the mean time please let me know if there is anything else I can help you with!' user.thread = '?' user.lvl = 0 user.confusion = 0 else: reply_msg = 'Sorry I didn\'t understand that, can you try re-entering' user.confusion = '1' return reply_msg, user