コード例 #1
0
def setting(sms_to, sms_from, sms_list):

    # Add analytics record
    instance_name, a = config_services.identify_service(sms_to)
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create().add_analytics_record("Count", "Command-SETTING", instance_name)

    # Make sure that there are enough values in the message to actually change a setting
    # You need three - 1. SET, 2. SETTING (e.g. EMAIL), 3. VALUE (e.g. ON)
    if len(sms_list) >= 3:

        # Firstly check to see which setting the user wishes to update
        if sms_list[1].upper() == "EMAIL":
            logger.debug("User changing email settings")
            email_settings(sms_to, sms_from, sms_list)
        elif sms_list[1].upper() == "CONTACT":
            logger.debug("User changing contact settings")
            contact_settings(sms_to, sms_from, sms_list)
        else:
            return

        return

    else:
        bb_sms_handler.send_sms_notification(sms_to, sms_from,
                                             "Please ensure you provide all the necessary parameters to change settings. ")
        return
コード例 #2
0
def unregister(smsrequest):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-UNREGISTER",
                           smsrequest.instancename)

    if len(smsrequest.requestcommandlist) < 2:
        return notEnoughDeRegistrationDetails(smsrequest.servicenumber,
                                              smsrequest.requestormobile)

    if len(smsrequest.requestcommandlist) > 2:
        message = "You have provided too many details in your text. Unregister text should be 'UNREGISTER AB125DF'."
        bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                             smsrequest.requestormobile,
                                             message)
        return "<Response></Response>"

    try:
        smsrequest.requestorreg = smsrequest.requestcommandlist[1].upper()

        if bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).remove_registration(smsrequest.requestorreg,
                              smsrequest.requestormobile) == 1:
            message = "Car " + smsrequest.requestorreg + " has been unregistered from BlockBuster."
            logger.debug(message)
            bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                                 smsrequest.requestormobile,
                                                 message)

        elif bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).remove_registration(smsrequest.requestorreg,
                              smsrequest.requestormobile) == 0:
            message = "Car is not registered to this mobile number."
            logger.debug(message)
            bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                                 smsrequest.requestormobile,
                                                 message)

        elif bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).remove_registration(smsrequest.requestorreg,
                              smsrequest.requestormobile) == -1:
            message = "Unable to unregister car " + smsrequest.requestorreg + " - please report the issue."
            logger.error("Unable to unregister car " +
                         smsrequest.requestorreg + ".")
            bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                                 smsrequest.requestormobile,
                                                 message)

        else:
            raise Exception("Unable to unregister this car at this time.")
            logger.error("Unable to unregister car at this time.")

    except Exception, e:
        bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
        message = "Unable to unregister car " + smsrequest.requestorreg + " - please report the issue."
        logger.error("Unable to unregister car " + smsrequest.requestorreg +
                     ".")
        bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                             smsrequest.requestormobile,
                                             message)
コード例 #3
0
def whois(SMSTo, SMSFrom, SMSList):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-WHOIS", instancename)

    if len(SMSList) > 1:
        upper_case_reg = SMSList[1].upper()
        logger.debug("Using Registration Plate: " + upper_case_reg)
        response = cardetails(upper_case_reg)

    else:
        response = respond_noregistrationspecified(SMSTo, SMSFrom)

    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, response)
コード例 #4
0
def current_status(smsrequest):

    # Get the current status for the requesting user
    status = blockbuster.bb_command_processor.current_status(smsrequest)

    active_blocks_as_blockee = status['blockedBy']
    active_blocks_as_blocker = status['blocking']

    # Check the list of people you are blocking in
    if len(active_blocks_as_blockee) > 0:
        text_list_of_blocks_as_blockee = "Currently being blocked by:\n\n"
        for b in active_blocks_as_blockee:

            blocker_name = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
                .create().get_name_from_mobile(b['blocker'])

            text_list_of_blocks_as_blockee = text_list_of_blocks_as_blockee + blocker_name + "\n"
    else:
        text_list_of_blocks_as_blockee = "Not currently blocked in.\n"

    # Check the list of people blocking you in
    if len(active_blocks_as_blocker) > 0:
        text_list_of_blocks_as_blocker = "Currently blocking:\n\n"
        for b in active_blocks_as_blocker:

            blocked_reg = b['blocked_reg']

            blocked_name = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
                .create().get_name_from_mobile(b['blockee'])

            text_list_of_blocks_as_blocker = text_list_of_blocks_as_blocker + blocked_name + " (" + blocked_reg + ")\n"
    else:
        text_list_of_blocks_as_blocker = "Not currently blocking anyone in."

    status_message = text_list_of_blocks_as_blockee + "\n" + text_list_of_blocks_as_blocker

    # Send the current status back to the user via SMS
    bb_sms_handler.send_sms_notification(smsrequest.servicenumber,
                                         smsrequest.requestormobile,
                                         status_message)

    # Also send them their current status via email
    email_subject = "Current BlockBuster Status"
    email_message = status_message
    bb_notification_handler.send_notifications(smsrequest.requestormobile,
                                               email_subject, email_message)

    return
コード例 #5
0
    def send_unblock_blockee_messages(service_number, unblocker_number,
                                      blockee_number, blocked_reg,
                                      blocker_name, blockee_name):
        messageblockee = blocker_name + " is no longer blocking your car (" + blocked_reg + ") in."

        bb_sms_handler.send_sms_notification(service_number, blockee_number,
                                             messageblockee)

        #Send a push notification if the user wants it
        subject = "You've been unblocked"
        send_push_notification_if_appropriate(service_number, blockee_number,
                                              subject, messageblockee)

        # Ask the notification handler to send out the appropriate notifications
        bb_notification_handler.send_notifications(blockee_number, subject,
                                                   messageblockee)
コード例 #6
0
def push(SMSTo, SMSFrom, SMSList):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-PUSH", instancename)

    if len(SMSList) > 1:
        if SMSList[1].upper() == "OFF":
            logger.debug("User requested that push notifications are disabled")
            message = bb_dbconnector_factory.DBConnectorInterfaceFactory(
            ).create().turn_push_notifications_off(SMSFrom)
            bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
            return
        elif SMSList[1].upper() == "ON":
            logger.debug("User requested that push notifications are enabled")
            message = bb_dbconnector_factory.DBConnectorInterfaceFactory(
            ).create().turn_push_notifications_on(SMSFrom)
            bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
            return
        else:
            pushover_token = SMSList[1]
            logger.debug("Using Pushover token " + pushover_token)
            logger.debug("Setting Pushover token for user")
            message = bb_dbconnector_factory.DBConnectorInterfaceFactory(
            ).create().add_pushover_token_for_user(SMSFrom, pushover_token)
            bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    else:
        return
コード例 #7
0
def register(SMSTo, SMSFrom, SMSList, location):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-REGISTER", instancename)

    if len(SMSList) < 4:
        return notEnoughRegistrationDetails(SMSTo, SMSFrom)

    registration = SMSList[1].upper()
    firstname = SMSList[2]
    surname = SMSList[3]
    mobile = SMSFrom
    location = location

    message = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
        .create()\
        .register_new_car(registration,
                          firstname,
                          surname,
                          mobile,
                          location)

    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    return
コード例 #8
0
def acknowledge_move_request(SMSTo, SMSFrom, SMSList):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-ACKNOWLEDGE", instancename)
    open_move_requests = bb_dbconnector_factory.DBConnectorInterfaceFactory(
    ).create().get_open_move_requests(SMSFrom)
    blocker_name = bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).get_name_from_mobile(SMSFrom)

    if len(open_move_requests) < 1:
        bb_sms_handler.send_sms_notification(
            SMSTo, SMSFrom,
            "BlockBuster doesn't know of anyone waiting for you to move at this time."
        )
        return

    for move_request in open_move_requests:
        message = blocker_name + " has acknowledged your move request."
        bb_sms_handler.send_sms_notification(SMSTo,
                                             move_request['blockee_mobile'],
                                             message)
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).remove_move_request(SMSFrom, move_request['blockee_mobile'])

    return
コード例 #9
0
def email_settings(sms_to, sms_from, sms_list):
    if sms_list[2].upper() == "OFF":
        logger.debug("User requested that email notifications are disabled")
        result = bb_dbconnector_factory.DBConnectorInterfaceFactory().create().disable_email_notifications(sms_from)
        bb_sms_handler.send_sms_notification(sms_to, sms_from, result)
        return

    elif sms_list[2].upper() == "ON":
        logger.debug("User requested that email notifications are enabled")
        result = bb_dbconnector_factory.DBConnectorInterfaceFactory().create().enable_email_notifications(sms_from)
        bb_sms_handler.send_sms_notification(sms_to, sms_from, result)
        notify.send_notifications(sms_from, "Test Notification", "Email notifications have now been turned on. "
                                                                 "You should add [email protected] "
                                                                 "to your contacts.")
        return

    else:
        email_address = sms_list[2]
        logger.debug("Updating with email address " + email_address)
        result = bb_dbconnector_factory.DBConnectorInterfaceFactory().create().update_email_address(sms_from, email_address)
        bb_sms_handler.send_sms_notification(sms_to, sms_from, result)
        notify.send_notifications(sms_from, "Test Notification", "Notifications are now enabled for this email address.")
        return
コード例 #10
0
def notEnoughDeRegistrationDetails(SMSTo, SMSFrom):
    logger.debug("Returning: Not Enough Details Provided")
    message = "You have not provided enough details. Please use format: \n \n'UNREGISTER FD05RYT'"
    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    return "<Response></Response>"
コード例 #11
0
 def send_move_blockee_message(service_number2, requester_number2,
                               names_list):
     messageblocker = "I've asked these people to move: \n\n" + names_list
     bb_sms_handler.send_sms_notification(service_number2,
                                          requester_number2, messageblocker)
コード例 #12
0
    def request_single_car_move(reg):

        # Search the database for the registration plate provided
        if checkifregexists(reg):

            # Try and retrieve details from the database for both the blockEE and blockER
            try:
                dict_blocker = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_reg(blocking_reg)
                print(dict_blocker)

                dict_blockee = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_mobile(requester_number)
                print(dict_blockee)

            except Exception, e:
                bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
                pass

            # If the blocker has a Mobile number (and therefore is registered with BlockBuster) then do this
            if dict_blocker['Mobile'] != "" and dict_blocker['Mobile'] != None:

                # If the blockee is registered with BlockBuster then do this
                if dict_blockee:
                    message = dict_blockee['FirstName'] + " " + dict_blockee['Surname'] + \
                        " needs you to move your car, please.\n\n" \
                        "Text 'OK' to confirm that you have received this."

                    subject = "Please move your car"

                    bb_sms_handler.send_sms_notification(
                        service_number, dict_blocker['Mobile'], message)

                    # Send a push notification if that user wants them
                    send_push_notification_if_appropriate(
                        service_number, dict_blocker['Mobile'], subject,
                        message)

                    # Ask the notification handler to send out the appropriate notifications
                    bb_notification_handler.send_notifications(
                        dict_blocker['Mobile'], subject, message)

                    # Open a move request for that blocker / blockee combination
                    add_move_request(dict_blocker['Mobile'], requester_number)

                    landline_string = get_landline_number_string(blocking_reg)
                    logger.debug(landline_string)

                    blocker_name = dict_blocker[
                        'FirstName'] + " " + dict_blocker['Surname']
                    blocker_mobile = dict_blocker['Mobile']
                    blocker_reg = reg

                    list_of_names = blocker_name + " (" + \
                                    blocker_reg + ")\n" + \
                                    include_mobile_number(blocker_mobile) + \
                                    get_landline_number_string(blocker_reg) + "\n"

                    send_move_blockee_message(service_number, requester_number,
                                              list_of_names)

                # The blockee is not registered with BlockBuster
                # so advise them to register with the service before trying to use it
                else:
                    bb_sms_handler.send_sms_notification(
                        service_number, requester_number,
                        "Sorry - please register this mobile number to use "
                        "this BlockBuster service. \n \n Text '?' for help.")

            # The blockER is not registered with BlockBuster
            # so provide them the name of the car owner
            else:
                bb_sms_handler.send_sms_notification(
                    service_number, requester_number,
                    "Sorry - this car belongs to " +
                    dict_blocker['FirstName'] + " " + dict_blocker['Surname'] +
                    " but they do not have a mobile "
                    "number registered.")
コード例 #13
0
def contact_settings(bb_service_number, user_mobile, sms_list):

    # If the user sends a command of "SET CONTACT MOBILE OFF", mobile number sharing for them will be disabled.
    if len(sms_list) > 3 and sms_list[2].upper() == "MOBILE" and sms_list[3].upper() == "OFF":
        # Log that the user has chosen to disable sharing of their mobile number
        logger.debug("Updating user setting Share_Mobile to OFF")

        # Attempt to disable mobile number sharing for this user - will return a success code of 0 (success) or 1 (fail)
        success_code = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
            .create().disable_mobile_number_sharing(user_mobile)

        if success_code == 0:
            result = "Share Mobile Number is now OFF."
            logger.info("User Setting Updated: Share Mobile OFF")

        elif success_code == 1:
            result = "There was an issue enabling this setting - please contact BlockBuster support."
            logger.error("Error disabling Share Mobile setting for user.")

        bb_sms_handler.send_sms_notification(bb_service_number, user_mobile, result)

        return

    # If the user sends any other command beginning with "SET CONTACT MOBILE"
    # then mobile number sharing will be enabled for them.
    elif sms_list[2].upper() == "MOBILE":
        # Log that the user has chosen to enable sharing of their mobile number
        logger.debug("Updating user setting Share_Mobile to ON")

        # Attempt to enable mobile number sharing for this user - will return a success code of 0 (success) or 1 (fail)
        success_code = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
            .create().enable_mobile_number_sharing(user_mobile)

        if success_code == 0:
            result = "Share Mobile Number is now ON."
            logger.info("User Setting Updated: Share Mobile ON")

        elif success_code == 1:
            result = "There was an issue enabling this setting - please contact BlockBuster support."
            logger.error("Error enabling Share Mobile setting for user.")

        bb_sms_handler.send_sms_notification(bb_service_number, user_mobile, result)

        return

    # If the user sends a "SET CONTACT CLEAR" command
    # erase any alternative contact text that they have set and enable mobile sharing
    elif sms_list[2].upper() == "CLEAR":
        # Log that the user has chosen to enable sharing of their mobile number
        logger.debug("Clearing alternative contact text and enabling mobile sharing")
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit('app',
                                                                'SETTING-CONTACT-CLEAR',
                                                                "Mobile:" + user_mobile)

        # Attempt to enable mobile number sharing for this user - will return a success code of 0 (success) or 1 (fail)
        success_clear = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
            .create().remove_alternative_contact_text(user_mobile)
        success_code = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
            .create().enable_mobile_number_sharing(user_mobile)

        if success_code == 0 and success_clear == 0:
            result = "Your additional contact information has been cleared and mobile number sharing is enabled."
            logger.info("User Setting Updated: Share Mobile ON and Alternative Contact Info CLEARED.")

        elif success_code == 1 or success_clear == 1:
            result = "There was an issue clearing your contact information - please report this issue."
            # TODO: Create a new logError method on the BBAuditLogger and then convert the below
            # BBAuditLogger.BBAuditLoggerFactory().create().logException('app',
            #                                                            'SETTING-CONTACT-CLEAR',
            #                                                            "Mobile:" + user_mobile)

        bb_sms_handler.send_sms_notification(bb_service_number, user_mobile, result)

        return

    else:
        # Assign the alternative text provided by the user to a variable
        alt_text_last_index = (len(sms_list))
        alternative_text = sms_list[2]
        i = 3
        while i < alt_text_last_index:
            alternative_text = alternative_text + " " + sms_list[i]
            i += 1

        # Log that the user has chosen to update their alternative contact information
        logger.info("Updating user setting with alternative contact information.")
        logger.debug("New contact information: " + alternative_text)

        # Call the method in the DAL to update the alternative contact information for that user.
        # Assign the result to a variable.
        success_code = bb_dbconnector_factory.DBConnectorInterfaceFactory()\
            .create()\
            .update_alternative_contact_text(user_mobile, alternative_text)

        if success_code == 0:
            result = "Alternative contact info has been set to:\n\n \"" + alternative_text + "\""

        elif success_code == 1:
            result = "There was an issue setting the alternative contact info - please contact BlockBuster support."

        # Send an SMS to the user confirming that their details have been updated.
        bb_sms_handler.send_sms_notification(bb_service_number, user_mobile, result)

        return
コード例 #14
0
            # The blockER is not registered with BlockBuster
            # so provide them the name of the car owner
            else:
                bb_sms_handler.send_sms_notification(
                    service_number, requester_number,
                    "Sorry - this car belongs to " +
                    dict_blocker['FirstName'] + " " + dict_blocker['Surname'] +
                    " but they do not have a mobile "
                    "number registered.")

        else:
            # If the MOVE command was sent on its own (therefore searching for existing blocks)
            if len(SMSList) < 2:
                bb_sms_handler.send_sms_notification(
                    service_number, requester_number,
                    "Sorry - cannot find any current blocks for you.")

            # In which case it must have been sent with a registration plate as a parameter
            else:
                bb_sms_handler.send_sms_notification(
                    service_number, requester_number,
                    "Sorry - vehicle not registered with BlockBuster.")

        return "<Response></Response>"

    # Method to send MOVE response to blockee where there is a list of blockers who have been informed.
    def send_move_blockee_message(service_number2, requester_number2,
                                  names_list):
        messageblocker = "I've asked these people to move: \n\n" + names_list
        bb_sms_handler.send_sms_notification(service_number2,
コード例 #15
0
def process_twilio_request(request):

    logger.debug(
        '################################ NEW SMS ###############################################'
    )

    if not within_operational_period():
        logger.info("Time restriction mode enabled - ignoring request")
        return "<Response></Response>"

    # Create an instance of an smsrequest object
    smsrequest = bb_types.SMSRequestFactory().create()

    # Extract some information from the http requests
    SMSFrom = str(request.form['From'])
    SMSTo = str(request.form['To'])

    # Strip whitespace from the beginning and end of the body of the message
    SMSBody = str(request.form['Body']).rstrip().lstrip()

    # Populate the smsrequest instance with details of the received request
    smsrequest.requestormobile = str(request.form['From'])
    smsrequest.servicenumber = str(request.form['To'])
    smsrequest.requestbody = str(request.form['Body']).rstrip().lstrip()

    global instancename
    global location
    instancename, location = config_services.identify_service(SMSTo)
    smsrequest.instancename = instancename

    SMSList = combinesplitregistrations(SMSBody, location)
    smsrequest.requestcommandlist = SMSList

    # Set the SMS Service Name to 'Twilio'
    smsservice = "Twilio"
    smsrequest.requestsmsservice = smsservice

    # Add an analytics record for the received request
    bb_dbconnector_factory.DBConnectorInterfaceFactory()\
        .create()\
        .add_analytics_record("Count", "SMS-Receive", instancename)

    # Construct a dictionary containing details for creating a message log entry
    logentry = {
        "Direction":
        "I <----",
        "SMSService":
        smsservice,
        "Command":
        "",
        "Originator":
        SMSFrom,
        "OriginatorName":
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create().
        get_name_from_mobile(SMSFrom),
        "Destination":
        SMSTo,
        "RecipientName":
        instancename,
        "Details":
        SMSBody
    }

    # Construct a dictionary containing details for creating an audit log entry
    audit_entry = "Originator:" + SMSFrom + \
                  ";Receipient:" + SMSTo + \
                  ";Body:" + SMSBody

    # Check the incoming message to see which function has been requested
    commandelement = smsrequest.get_command_element()

    # Define lists of aliases for some of the commands
    start_command_list = ['START']
    help_command_list = ['?']
    move_command_list = ['MOVE', 'M']
    block_command_list = ['BLOCK', 'B']
    unblock_command_list = ['UNBLOCK', 'U']
    unregister_command_list = ['UNREGISTER', 'UR']

    # First, check if the command is one of the following public commands - if so, process the registration.
    if commandelement == "REGISTER":
        logentry['Command'] = "REGISTER"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-REGISTER', audit_entry)
        logger.debug("REGISTER Command Received")
        register(SMSTo, SMSFrom, SMSList, location)
        return "<Response></Response>"

    if commandelement in start_command_list:
        logentry['Command'] = "START"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-START', audit_entry)
        workflow.command_start.go(smsrequest)
        return "<Response></Response>"

    if commandelement in help_command_list:
        logentry['Command'] = "HELP"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-HELP', audit_entry)
        workflow.command_help.go(smsrequest)
        return "<Response></Response>"

    # If not a registration, proceed to check that the requesting user is registered with the service.
    logger.debug("Checking that user is registered...")

    # If the user is not registered, respond asking them to register and write log entries
    if not bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
            .number_is_registered(smsrequest.requestormobile):

        logger.debug("User is not registered to use this service")
        send_not_registered_SMS(SMSTo, SMSFrom)
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'NOT-REGISTERED', audit_entry)

        return "<Response></Response>"

    if commandelement in unregister_command_list:
        logger.debug("UNREGISTER Command Received")
        logentry['Command'] = "UNREGISTER"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-UNREGISTER', audit_entry)
        return unregister(smsrequest)

    elif commandelement == "WHOIS":
        logger.debug("WHOIS Command Received")
        logentry['Command'] = "WHOIS"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-WHOIS', audit_entry)
        whois(SMSTo, SMSFrom, SMSList)
        return "<Response></Response>"

    elif commandelement in move_command_list:
        logger.debug("MOVE Command Received")
        logentry['Command'] = "MOVE"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-MOVE', audit_entry)
        return move(SMSTo, SMSFrom, SMSList)

    elif commandelement in block_command_list:
        logger.debug("BLOCK Command Received")
        logentry['Command'] = "BLOCK"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-BLOCK', audit_entry)
        return block(SMSTo, SMSFrom, SMSList)

    elif commandelement in unblock_command_list:
        logger.debug("UNBLOCK Command Received")
        logentry['Command'] = "UNBLOCK"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-UNBLOCK', audit_entry)
        return unblock(SMSTo, SMSFrom, SMSList)

    elif commandelement == "OK":
        logger.debug("MOVE Request Acknowledged")
        logentry['Command'] = "OK"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-ACK', audit_entry)
        acknowledge_move_request(SMSTo, SMSFrom, SMSList)
        return "<Response></Response>"

    elif commandelement == ".":
        logger.debug("STATUS Command Received")
        logentry['Command'] = "STATUS"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-STATUS', audit_entry)
        current_status(smsrequest)
        return "<Response></Response>"

    elif commandelement == "PUSH":
        logger.debug("PUSH Command Received")
        logentry['Command'] = "ADD_PUSHOVER_TOKEN"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-SETTING', audit_entry)
        push(SMSTo, SMSFrom, SMSList)
        return "<Response></Response>"

    elif commandelement == "SET":
        logger.debug("SET Command Received")
        logentry['Command'] = "SETTING"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-SETTING', audit_entry)
        user_settings.setting(SMSTo, SMSFrom, SMSList)
        return "<Response></Response>"

    else:
        logger.debug("Command Not Recognised - Assuming WHOIS")
        logentry['Command'] = "WHOIS"
        bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
        ).add_transaction_record(logentry)
        bb_auditlogger.BBAuditLoggerFactory().create().logAudit(
            'app', 'RCVCMD-WHOIS', audit_entry)

        # Format the registration number so that it is all capitals
        uppercasereg = SMSBody.upper().replace(" ", "")
        logger.debug("Using Registration Plate: " + uppercasereg)
        bb_sms_handler.send_sms_notification(SMSTo, SMSFrom,
                                             cardetails(uppercasereg))
        return "<Response></Response>"
コード例 #16
0
def respond_noregistrationspecified(ServiceNumber, RecipientNumber):
    logger.debug("Returning: No Registration Specified")
    message = "You didn't provide a registration. \n \n Text '?' for help."
    bb_sms_handler.send_sms_notification(ServiceNumber, RecipientNumber,
                                         message)
    return "<Response></Response>"
コード例 #17
0
def block(SMSTo, SMSFrom, SMSList):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-BLOCK", instancename)

    # Loop through the registrations provided and add them all to an array
    reg_list = []
    total_elements = len(SMSList)
    # Start at element[1} as we have already established that element[0] contains the command by the face we're here.
    e = 1
    while e < total_elements:
        # Skip elements which have come from multiple spaces between registrations in the message.
        if SMSList[e] == "":
            pass
        else:
            reg_list.append(SMSList[e])
        e += 1

    logger.debug("Number of registrations in list is " + str(len(reg_list)))

    # Check that a registration was actually provided. If not, respond to the user.
    if len(reg_list) < 1:
        return respond_noregistrationspecified(SMSTo, SMSFrom)

    # Now work through each of the registrations in the list, working out what the status is, and triggering a
    # notification message if appropriate. Also build up a list of the statuses so that they can be fed back to
    # the user.
    list_of_blockees = ""

    for registration in reg_list:

        logger.debug("Currently processing " + registration)
        blocked_reg = registration.upper()

        # TODO: Refactor the registered check out of this as this is now done at first receipt of the web request
        try:
            dict_blocker = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_mobile(SMSFrom)
            logger.debug("Surname of Blocker is " + dict_blocker['Surname'])

        except Exception, e:
            bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
            message = "Sorry - please register this mobile number to use this BlockBuster service. \n \n " \
                "Text '?' for help."

            # Send message to the blocker to advise them to register in order to use the service.
            bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
            return "<Response></Response>"

        # Search the database for the registration number provided
        if checkifregexists(registration.upper()):
            try:
                dict_blockee = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_reg(registration.upper())

                logger.debug("Surname of blockee is " +
                             dict_blockee['Surname'])

            except Exception, e:
                bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
                pass

            # If the blockee does not have a mobile number registered, tell the blocker that they can't be notified,
            # and then continue with the next iteration of the loop.
            if dict_blockee['Mobile'] == '' or dict_blockee['Mobile'] is None:

                list_of_blockees = list_of_blockees + registration.upper() + ": " + "Not Registered (" + dict_blockee['FirstName'] + " " \
                    + dict_blockee['Surname'] + ")\n\n"
                continue

            # Create the message to be sent to the person being blocked in.
            messageblockee = dict_blocker['FirstName'] + " " + dict_blocker['Surname'] + " has blocked in your car " \
                + blocked_reg + ". \n\nText MOVE to ask them to move their car."

            # Send the message to the blockee.
            bb_sms_handler.send_sms_notification(SMSTo, dict_blockee['Mobile'],
                                                 messageblockee)

            #Send a push notification if the user wants it
            subject = "You've been blocked in"
            send_push_notification_if_appropriate(SMSTo,
                                                  dict_blockee['Mobile'],
                                                  subject, messageblockee)

            # Ask the notification handler to send out the appropriate notifications
            bb_notification_handler.send_notifications(dict_blockee['Mobile'],
                                                       subject, messageblockee)

            # Construct the list of blockees
            list_of_blockees = list_of_blockees + registration.upper() + ": " + "Notified (" + dict_blockee['FirstName'] + " " \
                + dict_blockee['Surname'] + ")\n\n"

            # Construct a block record
            block_parameters = {
                "BlockedReg": blocked_reg,
                "BlockeeMobile": dict_blockee['Mobile'],
                "BlockerMobile": SMSFrom
            }

            # Add the block record to the DB
            bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
            ).add_block_record(block_parameters)
コード例 #18
0
def featurenotimplemented(SMSTo, SMSFrom, SMSList):
    logger.debug("Returning: Not Implemented")
    message = "Sorry, feature not implemented yet. \n \n Text '?' for help."
    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    return "<Response></Response>"
コード例 #19
0
def unblock(SMSTo, SMSFrom, SMSList):
    bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
    ).add_analytics_record("Count", "Command-UNBLOCK", instancename)

    def send_unblock_blockee_messages(service_number, unblocker_number,
                                      blockee_number, blocked_reg,
                                      blocker_name, blockee_name):
        messageblockee = blocker_name + " is no longer blocking your car (" + blocked_reg + ") in."

        bb_sms_handler.send_sms_notification(service_number, blockee_number,
                                             messageblockee)

        #Send a push notification if the user wants it
        subject = "You've been unblocked"
        send_push_notification_if_appropriate(service_number, blockee_number,
                                              subject, messageblockee)

        # Ask the notification handler to send out the appropriate notifications
        bb_notification_handler.send_notifications(blockee_number, subject,
                                                   messageblockee)

    def send_unblock_blocker_message(service_number, unblocker_number,
                                     list_of_names):
        messageblocker = "I've told these people that you've moved: \n\n" + list_of_names
        bb_sms_handler.send_sms_notification(service_number, unblocker_number,
                                             messageblocker)

    # Check whether the UNBLOCK command was sent on its own....
    if len(SMSList) < 2:
        logger.debug('Command: UNBLOCK (no reg)')

        list_of_blocks = bb_dbconnector_factory.DBConnectorInterfaceFactory(
        ).create().get_list_of_blocks_for_blocker(SMSFrom)

        # Check the length of the cursor to see how many active blocks there are
        # If there is at least one active block, process those blocks...
        if len(list_of_blocks) > 0:

            list_of_names = ""
            # Iterate through the cursor and process each active block.
            # Send a message to the blockee, and remove the block.
            for block_item in list_of_blocks:
                a = SMSTo
                b = SMSFrom
                c = block_item['blockee_mobile']
                d = block_item['blocked_reg']
                blocker_name = bb_dbconnector_factory.DBConnectorInterfaceFactory(
                ).create().get_name_from_mobile(b)
                blockee_name = bb_dbconnector_factory.DBConnectorInterfaceFactory(
                ).create().get_name_from_reg(d)
                send_unblock_blockee_messages(a, b, c, d, blocker_name,
                                              blockee_name)
                list_of_names = list_of_names + blockee_name + "\n"
                bb_dbconnector_factory.DBConnectorInterfaceFactory().create(
                ).remove_blocks(b, d)

            # Now send a message to the blocker containing a list of all people who were being blocked.
            send_unblock_blocker_message(SMSTo, SMSFrom, list_of_names)
            return "<Response></Response>"

        # If there are no active blocks, inform the unblocker that there are no active blocks found
        else:
            logger.debug("No active blocks found.")
            bb_sms_handler.send_sms_notification(
                SMSTo, SMSFrom, "You are not currently blocking anyone in.")
            return "<Response></Response>"

    # ... or if a registration plate was specified with the UNBLOCK command
    else:
        try:
            blocked_reg = SMSList[1].upper()
        except Exception, e:
            bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
            logger.warn('No Registration Specified')
            respond_noregistrationspecified(SMSTo, SMSFrom)
            return "<Response></Response>"

        # Search the database for the registration number provided
        if checkifregexists(blocked_reg):
            try:
                dict_blockee = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_reg(blocked_reg)
                logger.debug(dict_blockee['Surname'])

            except Exception, e:
                bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
                logger.error("Error retrieving user dictionary from reg \n" +
                             str(e))
                pass

            if dict_blockee['Mobile'] == "" or dict_blockee['Mobile'] is None:
                message = "Sorry - that car belongs to " + dict_blockee['FirstName'] + " " \
                          + dict_blockee['Surname'] + " but they do not have a mobile number registered."
                bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
                return "<Response></Response>"

            try:
                dict_blocker = bb_dbconnector_factory.DBConnectorInterfaceFactory().create()\
                    .get_user_dict_from_mobile(SMSFrom)

                logger.debug(dict_blocker['Surname'])

            except Exception, e:
                bb_auditlogger.BBAuditLoggerFactory().create().logException(e)
                message = "Sorry - please register this mobile number to use this BlockBuster service. \n \n " \
                          "Text '?' for help."

                bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)

                return "<Response></Response>"
コード例 #20
0
def notEnoughBlockDetails(SMSTo, SMSFrom):
    logger.debug("Returning: Not Enough Details Provided")
    message = "You have not provided enough details. Please use format: \n \n'BLOCK FD05RYT' \n \nwith the registration as a single word."
    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    return "<Response></Response>"
コード例 #21
0
 def send_unblock_blocker_message(service_number, unblocker_number,
                                  list_of_names):
     messageblocker = "I've told these people that you've moved: \n\n" + list_of_names
     bb_sms_handler.send_sms_notification(service_number, unblocker_number,
                                          messageblocker)
コード例 #22
0
def send_not_registered_SMS(SMSTo, SMSFrom):
    logger.debug("Returning: Please Register To Use This Service")
    message = "Please register to use BlockBuster. \n \nSimply text 'REGISTER YourNumberPlate Firstname Surname'."
    bb_sms_handler.send_sms_notification(SMSTo, SMSFrom, message)
    return None