def start_drop_off():
    if system_vars.destination_reached is False:
        import SlackBot.slack_functions as slack_functions
        import MotorControl.motor_functions as motor_functions
        import LED.led_functions as led_functions
        led_functions.set_led('green')

        import RestAPI.api_main as api
        api.send_last_barcode_update_call()

        system_vars.destination_reached = True
        motor_functions.stop_both()

        orders = get_destination_all_orders(get_current_destination())
        vars.ready_order_list = orders
        vars.drop_off_running = True

        wait_time = calc_order_wait_time()
        mins, secs = divmod(wait_time, 60)
        timeformat = '{:02d}:{:02d}'.format(mins, secs)
        vars.order_countdown = timeformat

        if settings.touchscreen_enabled:
            import UI.ui_functions as ui_functions
            ui_functions.start_drop_off()

        i = 0
        import SlackBot.responses as responses
        while i < len(orders):
            if 'type' in orders[i]:
                if orders[i]['type'] == 'slack':
                    slack_functions.send_dm(
                        orders[i]['user'],
                        responses.order_ready % vars.order_countdown)
                else:
                    user_id = slack_functions.get_id_by_email(
                        orders[i]['user'])
                    if user_id is not None:
                        slack_functions.send_dm(
                            orders[i]['user'],
                            responses.order_ready % vars.order_countdown)
                    else:
                        import mail_system
                        mail_system.send_mail(
                            responses.order_ready % vars.order_countdown,
                            responses.order_ready % vars.order_countdown,
                            orders[i]['user'])
            i = i + 1

        order_countdown(wait_time)
        end_drop_off()
def check_user_already_placed_order(identifier, type):
    import SlackBot.slack_functions as slack_functions
    if type == 'email':
        email = identifier
        id = slack_functions.get_id_by_email(email)
    else:
        id = identifier
        email = slack_functions.get_email_by_id(id)

    index = check_user_order(id, email)
    if index >= 0:
        return vars.order_que[index]
    else:
        return None
Exemple #3
0
def confirm_delivery():
    body = request.body.read()
    body = json.loads(body)
    if 'user' and 'verify_key' and 'timestamp' in body:
        email = body['user']
        verify_key = body['verify_key']
        timestamp = body['timestamp']
    else:
        return {'status': 'error', 'code': 117, 'message': "parameter missing"}
    id = slack_functions.get_id_by_email(email)
    index = order_functions.check_user_order(id, email)
    if verify_call(verify_key, timestamp, email, vars.secret_keys['confirm_order']):
        if index >= 0:
            return {'status': 'success', 'code': 100, 'message': "order marked as delivered"}
        else:
            return {'status': 'error', 'code': 101, 'message': "no open order"}
    else:
        return {'status': 'error', 'code': 116, 'message': 'Authorisation failed'}
def confirm_order(user_or_index, type=None):
    import SlackBot.slack_functions as slack_functions
    if type == "slack":
        email = slack_functions.get_email_by_id(user_or_index)
        if vars.drop_off_running:
            index = check_user_ready_order(user_or_index, email)
            if index > -1:
                vars.ready_order_list[index]['open'] = False
                return True
        index = check_user_order(user_or_index, email)
        if index > -1:
            delete_oder(index, "index")
            import UI.ui_functions as ui_functions
            ui_functions.force_order_update()
            import RestAPI.api_main as api
            api.send_order_update_call()
            return True
        else:
            return False
    elif type == "interface":
        user_id = slack_functions.get_id_by_email(user_or_index)
        if vars.drop_off_running:
            index = check_user_ready_order(user_or_index, user_id)
            if index > -1:
                vars.ready_order_list[index]['open'] = False
                return True
        index = check_user_order(user_or_index, user_id)
        if index > -1:
            delete_oder(index, "index")
            import UI.ui_functions as ui_functions
            ui_functions.force_order_update()
            import RestAPI.api_main as api
            api.send_order_update_call()
            return True
        else:
            return False
    elif type is None:
        vars.ready_order_list[user_or_index]['open'] = False
def delete_oder(identifier, type):
    import SlackBot.slack_functions as slack_functions
    if type == "index":
        index = identifier
    else:
        if type == 'email':
            email = identifier
            id = slack_functions.get_id_by_email(email)
        else:
            id = identifier
            email = slack_functions.get_email_by_id(id)
        index = check_user_order(id, email)

    if index >= 0:
        vars.order_que.pop(index)
        import UI.ui_functions as ui_functions
        ui_functions.force_order_update()
        import RestAPI.api_main as api
        api.send_order_update_call()
        #database_functions.set_canceled(identifier)
        return True
    else:
        return False