src/dirbs/api/v2/resources/imei.py
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})

    IMEI API POST method handler for IMEI-Batch request.

    Arguments:
        kwargs: required arguments (list of IMEIs)
    Returns:
        JSON response
    
IMEI API POST method handler for IMEI-Batch request.
IMEI API POST method handler for IMEI - Batch request .
def imei_batch_api(**kwargs: dict) -> jsonify:
    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})
def imei_batch_api ( ** kwargs : dict ) -> jsonify : 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 } )
IMEI API POST method handler for IMEI-Batch request.
IMEI API POST method handler for IMEI - Batch request .
"""
    IMEI API POST method handler for IMEI-Batch request.

    Arguments:
        kwargs: required arguments (list of IMEIs)
    Returns:
        JSON response
    """
None
kwargs
dict
required arguments (list of IMEIs)
required arguments ( list of IMEIs )