Ejemplo n.º 1
0
def imei_batch_api(**kwargs):
    """
    IMEI API POST method handler for IMEI-Batch request.

    :param kwargs: input imei list
    :return: json
    """
    if bool(kwargs):
        imeis = kwargs.get('imeis')
        data = []
        with get_db_connection() as db_conn, db_conn.cursor() as cursor:
            for imei in imeis:
                imei_norm = validate_imei(imei)
                condition_results = get_conditions(cursor, imei_norm)

                response = {
                    'imei_norm':
                    imei_norm,
                    'block_date':
                    block_date(cursor, imei_norm),
                    'classification_state': {
                        'blocking_conditions': [
                            dict({
                                'condition_name': key,
                                'condition_met': value['result']
                            }) for key, value in condition_results.items()
                            if value['blocking']
                        ],
                        'informative_conditions': [
                            dict({
                                'condition_name': key,
                                'condition_met': value['result']
                            }) for key, value in condition_results.items()
                            if not value['blocking']
                        ]
                    },
                    'realtime_checks': {
                        'ever_observed_on_network':
                        ever_observed_on_network(cursor, imei_norm),
                        'invalid_imei':
                        False if re.match(r'^\d{14}$', imei_norm) else True,
                        'is_paired':
                        is_paired(cursor, imei_norm),
                        'is_exempted_device':
                        is_exempted_device(cursor, imei_norm)
                    },
                    'registration_status':
                    registration_list_status(cursor, imei_norm),
                    'stolen_status':
                    stolen_list_status(cursor, imei_norm)
                }

                data.append(IMEI().dump(response).data)
            return jsonify({'results': data})
    abort(400, 'Bad Input format (args cannot be empty)')
Ejemplo n.º 2
0
def imei_api(imei):
    """
    IMEI API handler.

    :param imei: IMEI
    :return: json
    """
    imei_norm = validate_imei(imei)

    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        condition_results = get_conditions(cursor, imei_norm)

        response = {
            'imei_norm': imei_norm,
            'block_date': block_date(cursor, imei_norm),
            'classification_state': {
                'blocking_conditions': [
                    dict({
                        'condition_name': key,
                        'condition_met': value['result']
                    }) for key, value in condition_results.items()
                    if value['blocking']
                ],
                'informative_conditions': [
                    dict({
                        'condition_name': key,
                        'condition_met': value['result']
                    }) for key, value in condition_results.items()
                    if not value['blocking']
                ]
            },
            'realtime_checks': {
                'ever_observed_on_network':
                ever_observed_on_network(cursor, imei_norm),
                'invalid_imei':
                False if re.match(r'^\d{14}$', imei_norm) else True,
                'is_paired':
                is_paired(cursor, imei_norm),
                'is_exempted_device':
                is_exempted_device(cursor, imei_norm)
            },
            'registration_status': registration_list_status(cursor, imei_norm),
            'stolen_status': stolen_list_status(cursor, imei_norm)
        }

        return jsonify(IMEI().dump(response).data)
Ejemplo n.º 3
0
def imei_batch_api(**kwargs: dict) -> jsonify:
    """
    IMEI API POST method handler for IMEI-Batch request.

    Arguments:
        kwargs: required arguments (list of IMEIs)
    Returns:
        JSON response
    """
    imeis = kwargs.get('imeis')
    include_registration_status = kwargs.get('include_registration_status')
    include_stolen_status = kwargs.get('include_stolen_status')

    data = []
    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        for imei in imeis:
            imei_norm = validate_imei(imei)
            tac = imei_norm[:8]
            condition_results = get_conditions(cursor, imei_norm)
            first_seen_date = first_seen(cursor, imei_norm)
            cursor.execute(
                'SELECT NOT EXISTS (SELECT * FROM gsma_data WHERE tac = %s) AS not_in_gsma',
                [tac])
            rt_gsma_not_found = cursor.fetchone()[0]

            response = {
                'imei_norm': imei_norm,
                'block_date': block_date(cursor, imei_norm),
                'first_seen': first_seen_date,
                'classification_state': {
                    'blocking_conditions': [
                        dict({
                            'condition_name': key,
                            'condition_met': value['result']
                        }) for key, value in condition_results.items()
                        if value['blocking']
                    ],
                    'informative_conditions': [
                        dict({
                            'condition_name': key,
                            'condition_met': value['result']
                        }) for key, value in condition_results.items()
                        if not value['blocking']
                    ]
                },
                'realtime_checks': {
                    'ever_observed_on_network':
                    True if first_seen_date else False,
                    'invalid_imei':
                    False if re.match(r'^\d{14}$', imei_norm) else True,
                    'is_paired':
                    is_paired(cursor, imei_norm),
                    'is_exempted_device':
                    is_exempted_device(cursor, imei_norm),
                    'gsma_not_found':
                    rt_gsma_not_found,
                    'in_registration_list':
                    is_in_registration_list(db_conn, cursor, imei_norm)
                }
            }

            if include_registration_status:
                response['registration_status'] = registration_list_status(
                    cursor, imei_norm)
            if include_stolen_status:
                response['stolen_status'] = stolen_list_status(
                    cursor, imei_norm)

            data.append(IMEI().dump(response).data)
        return jsonify({'results': data})
Ejemplo n.º 4
0
def imei_api(imei: str,
             include_registration_status: bool = False,
             include_stolen_status: bool = False) -> jsonify:
    """
    IMEI API handler.

    Arguments:
        imei: value of the IMEI
        include_registration_status: boolean weather to include reg status or not (default False)
        include_stolen_status: boolean weather to include stolen status or not (default False)
    Returns:
        JSON response
    """
    imei_norm = validate_imei(imei)
    tac = imei_norm[:8]

    tac = imei_norm[:8]
    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        cursor.execute(
            'SELECT NOT EXISTS (SELECT * FROM gsma_data WHERE tac = %s) AS not_in_gsma',
            [tac])
        rt_gsma_not_found = cursor.fetchone()[0]
        first_seen_date = first_seen(cursor, imei_norm)
        condition_results = get_conditions(cursor, imei_norm)
        response = {
            'imei_norm': imei_norm,
            'block_date': block_date(cursor, imei_norm),
            'first_seen': first_seen_date,
            'classification_state': {
                'blocking_conditions': [
                    dict({
                        'condition_name': key,
                        'condition_met': value['result']
                    }) for key, value in condition_results.items()
                    if value['blocking']
                ],
                'informative_conditions': [
                    dict({
                        'condition_name': key,
                        'condition_met': value['result']
                    }) for key, value in condition_results.items()
                    if not value['blocking']
                ]
            },
            'realtime_checks': {
                'ever_observed_on_network':
                True if first_seen_date else False,
                'invalid_imei':
                False if re.match(r'^\d{14}$', imei_norm) else True,
                'is_paired':
                is_paired(cursor, imei_norm),
                'is_exempted_device':
                is_exempted_device(cursor, imei_norm),
                'in_registration_list':
                is_in_registration_list(db_conn, cursor, imei_norm),
                'gsma_not_found':
                rt_gsma_not_found
            }
        }

        if include_registration_status:
            response['registration_status'] = registration_list_status(
                cursor, imei_norm)
        if include_stolen_status:
            response['stolen_status'] = stolen_list_status(cursor, imei_norm)

        return jsonify(IMEI().dump(response).data)