Пример #1
0
def tac_batch_api(**kwargs: dict) -> jsonify:
    """
    TAC POST API endpoint (version 2).

    Arguments:
        kwargs: required arguments (TAC list)
    Returns:
        JSON response
    """
    tacs = list(set(kwargs.get('tacs')))

    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        cursor.execute(
            """SELECT tac, manufacturer, bands, allocation_date, model_name, device_type,
                                 optional_fields
                            FROM gsma_data
                           WHERE tac IN %(tacs)s""", {'tacs': tuple(tacs)})
        gsma_data = cursor.fetchall()
        response = []
        for rec in gsma_data:
            response.append(TacInfo().dump(
                dict(tac=rec.tac, gsma=rec._asdict())).data)
        existing_tacs = [res['tac'] for res in response]
        for tac in tacs:
            if tac not in existing_tacs:
                response.append(TacInfo().dump(dict(tac=tac, gsma=None)).data)
        return jsonify({'results': response})
Пример #2
0
def tac_batch_api(**kwargs):
    """
    TAC POST API endpoint (version 2).

    :param kwargs: list of gsma tacs
    :return: json
    """
    if kwargs is not None:
        tacs = kwargs.get('tacs')
        if tacs is not None:
            tacs = list(set(tacs))
        else:
            abort(400, 'Bad TAC Input format.')

        if tacs is not None:
            if not len(tacs) > 1000 and not len(tacs) == 0:
                with get_db_connection() as db_conn, db_conn.cursor(
                ) as cursor:
                    cursor.execute(
                        """SELECT tac, manufacturer, bands, allocation_date, model_name, device_type,
                                             optional_fields
                                        FROM gsma_data
                                       WHERE tac IN %(tacs)s""",
                        {'tacs': tuple(tacs)})
                    gsma_data = cursor.fetchall()
                    response = []
                    for rec in gsma_data:
                        response.append(TacInfo().dump(
                            dict(tac=rec.tac, gsma=rec._asdict())).data)
                    existing_tacs = [res['tac'] for res in response]
                    for tac in tacs:
                        if tac not in existing_tacs:
                            response.append(TacInfo().dump(
                                dict(tac=tac, gsma=None)).data)
                    return jsonify({'results': response})
            abort(400,
                  'Bad TAC Input format (Minimum 1 & Maximum 1000 allowed).')
        abort(400, 'Bad TAC Input format.')
    abort(400, 'Bad TAC Input format.')
Пример #3
0
def tac_api(tac):
    """
    TAC GET API endpoint (version 2).

    :param tac: gsma tac
    :return: json
    """
    validate_tac(tac)
    with get_db_connection() as db_conn, db_conn.cursor() as cursor:
        cursor.execute(
            """SELECT tac, manufacturer, bands, allocation_date, model_name, device_type,
                                 optional_fields
                            FROM gsma_data
                           WHERE tac = %s""", [tac])
        gsma_data = cursor.fetchone()
        return jsonify(TacInfo().dump(
            dict(tac=tac,
                 gsma=gsma_data._asdict()
                 if gsma_data is not None else None)).data)