src/dirbs/api/v2/resources/imei.py
def imei_pairings_api(imei: str, **kwargs: dict) -> jsonify:
    """
    IMEI-Pairings API handler.

    Arguments:
        imei: IMEI value
        kwargs: required arguments dictionary
    Returns:
        JSON response
    """
    imei_norm = validate_imei(imei)
    offset = kwargs.get('offset')
    limit = kwargs.get('limit')
    order = kwargs.get('order')

    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        query = """SELECT pairing_list.imsi, network_triplets.last_seen, COUNT(*) OVER() AS total_count
                     FROM pairing_list
                LEFT JOIN monthly_network_triplets_country_no_null_imeis AS network_triplets
                           ON network_triplets.imsi = pairing_list.imsi
                      AND network_triplets.imei_norm = pairing_list.imei_norm
                    WHERE pairing_list.imei_norm = %(imei_norm)s
                      AND pairing_list.virt_imei_shard = calc_virt_imei_shard(%(imei_norm)s)
                ORDER BY last_seen {order_type} 
                OFFSET {data_offset} 
                LIMIT {data_limit}""".format(order_type=order, data_offset=offset, data_limit=limit)  # noqa Q447

        cursor.execute(query, {'imei_norm': imei_norm})
        if cursor is not None:
            pairings = [{'imsi': x.imsi, 'last_seen': x.last_seen, 'total_count': x.total_count} for x in cursor]
            keys = {'current_key': offset,
                    'next_key': offset + limit if pairings else '',
                    'result_size': pairings[0].get('total_count') if pairings else 0}
            return jsonify(IMEIPairings().dump(dict(imei_norm=imei_norm,
                                                    pairs=pairings,
                                                    _keys=keys)).data)

        keys = {'current_key': offset, 'next_key': '', 'result_size': 0}
        return jsonify(IMEIPairings().dump(dict(imei_norm=imei_norm, pairs=None, _keys=keys)))

    IMEI-Pairings API handler.

    Arguments:
        imei: IMEI value
        kwargs: required arguments dictionary
    Returns:
        JSON response
    
IMEI-Pairings API handler.
IMEI - Pairings API handler .
def imei_pairings_api(imei: str, **kwargs: dict) -> jsonify:
    imei_norm = validate_imei(imei)
    offset = kwargs.get('offset')
    limit = kwargs.get('limit')
    order = kwargs.get('order')
    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        query = """SELECT pairing_list.imsi, network_triplets.last_seen, COUNT(*) OVER() AS total_count
                     FROM pairing_list
                LEFT JOIN monthly_network_triplets_country_no_null_imeis AS network_triplets
                           ON network_triplets.imsi = pairing_list.imsi
                      AND network_triplets.imei_norm = pairing_list.imei_norm
                    WHERE pairing_list.imei_norm = %(imei_norm)s
                      AND pairing_list.virt_imei_shard = calc_virt_imei_shard(%(imei_norm)s)
                ORDER BY last_seen {order_type} 
                OFFSET {data_offset} 
                LIMIT {data_limit}""".format(order_type=order, data_offset=offset, data_limit=limit)  
        cursor.execute(query, {'imei_norm': imei_norm})
        if cursor is not None:
            pairings = [{'imsi': x.imsi, 'last_seen': x.last_seen, 'total_count': x.total_count} for x in cursor]
            keys = {'current_key': offset,
                    'next_key': offset + limit if pairings else '',
                    'result_size': pairings[0].get('total_count') if pairings else 0}
            return jsonify(IMEIPairings().dump(dict(imei_norm=imei_norm,
                                                    pairs=pairings,
                                                    _keys=keys)).data)
        keys = {'current_key': offset, 'next_key': '', 'result_size': 0}
        return jsonify(IMEIPairings().dump(dict(imei_norm=imei_norm, pairs=None, _keys=keys)))
def imei_pairings_api ( imei : str , ** kwargs : dict ) -> jsonify : imei_norm = validate_imei ( imei ) offset = kwargs . get ( 'offset' ) limit = kwargs . get ( 'limit' ) order = kwargs . get ( 'order' ) with get_db_connection ( ) as db_conn , db_conn . cursor ( ) as cursor : query = """SELECT pairing_list.imsi, network_triplets.last_seen, COUNT(*) OVER() AS total_count
                     FROM pairing_list
                LEFT JOIN monthly_network_triplets_country_no_null_imeis AS network_triplets
                           ON network_triplets.imsi = pairing_list.imsi
                      AND network_triplets.imei_norm = pairing_list.imei_norm
                    WHERE pairing_list.imei_norm = %(imei_norm)s
                      AND pairing_list.virt_imei_shard = calc_virt_imei_shard(%(imei_norm)s)
                ORDER BY last_seen {order_type} 
                OFFSET {data_offset} 
                LIMIT {data_limit}""" . format ( order_type = order , data_offset = offset , data_limit = limit ) cursor . execute ( query , { 'imei_norm' : imei_norm } ) if cursor is not None : pairings = [ { 'imsi' : x . imsi , 'last_seen' : x . last_seen , 'total_count' : x . total_count } for x in cursor ] keys = { 'current_key' : offset , 'next_key' : offset + limit if pairings else '' , 'result_size' : pairings [ 0 ] . get ( 'total_count' ) if pairings else 0 } return jsonify ( IMEIPairings ( ) . dump ( dict ( imei_norm = imei_norm , pairs = pairings , _keys = keys ) ) . data ) keys = { 'current_key' : offset , 'next_key' : '' , 'result_size' : 0 } return jsonify ( IMEIPairings ( ) . dump ( dict ( imei_norm = imei_norm , pairs = None , _keys = keys ) ) )
IMEI-Pairings API handler.
IMEI - Pairings API handler .
"""
    IMEI-Pairings API handler.

    Arguments:
        imei: IMEI value
        kwargs: required arguments dictionary
    Returns:
        JSON response
    """ # noqa Q447
None
imei
str
None
kwargs
dict
required arguments dictionary
required arguments dictionary