Exemplo n.º 1
0
    def get_line_item_available_inventory(self,
                                          line_item,
                                          use_start=False,
                                          preserve_id=False):
        """
        Get number of impressions available for line item

        @param line_item: LineItem
        @param use_start: bool, if False, checks availability from right
            now
        @param preserve_id: bool, communicate the id of the line item
            being forecasted to DFP. This is used in the case where we
            want to get a forecast on a line item in flight. This way, a
            domain doesn't need to have enough spare inventory to
            accommodate the two line items simultaneously. NOTE: If this
            is true then use_start is necessarily true.
        @return: int|None, number of available impressions
        """
        dfp_line_item = transform_forecast_line_item_to_dfp(
            line_item, use_start, preserve_id)
        logging.info("Obtaining forecast data for line item %s", line_item.id
                     or line_item)
        try:
            dfp_forecast = self.dfp_client.forecast_line_item(dfp_line_item)
        except Exception as e:
            raise ParselmouthException(e)

        forecast = recursive_asdict(dfp_forecast)
        if forecast and forecast.get('availableUnits'):
            available_units = int(forecast['availableUnits'])
        else:
            available_units = None

        logging.info("%s available impressions", str(available_units))
        return available_units
Exemplo n.º 2
0
    def get_network_timezone(self):
        """
        Get the DFP network timezone for
        the host this client is connected to

        @return: pytz.timezone
        """
        dfp_data = self.dfp_client.get_network_data()
        data = recursive_asdict(dfp_data)
        return timezone(data['timeZone'])
Exemplo n.º 3
0
    def get_network_timezone(self):
        """
        Get the DFP network timezone for
        the host this client is connected to

        @return: pytz.timezone
        """
        dfp_data = self.dfp_client.get_network_data()
        data = recursive_asdict(dfp_data)
        return timezone(data['timeZone'])
Exemplo n.º 4
0
    def get_line_item_available_inventory(self,
                                          line_item,
                                          use_start=False,
                                          preserve_id=False):
        """
        Get number of impressions available for line item

        @param line_item: LineItem
        @param use_start: bool, if False, checks availability from right
            now
        @param preserve_id: bool, communicate the id of the line item
            being forecasted to DFP. This is used in the case where we
            want to get a forecast on a line item in flight. This way, a
            domain doesn't need to have enough spare inventory to
            accommodate the two line items simultaneously. NOTE: If this
            is true then use_start is necessarily true.
        @return: int|None, number of available impressions
        """
        dfp_line_item = transform_forecast_line_item_to_dfp(
            line_item, use_start, preserve_id
        )
        logging.info(
            "Obtaining forecast data for line item %s",
            line_item.id or line_item
        )
        try:
            dfp_forecast = self.dfp_client.forecast_line_item(dfp_line_item)
        except Exception as e:
            raise ParselmouthException(e)

        forecast = recursive_asdict(dfp_forecast)
        if forecast and forecast.get('availableUnits'):
            available_units = int(forecast['availableUnits'])
        else:
            available_units = None

        logging.info(
            "%s available impressions",
            str(available_units)
        )
        return available_units
Exemplo n.º 5
0
 def _convert_response_to_dict(self, dfp_data):
     """
     @param dfp_data: list(SUDS)
     @return: list(dict)
     """
     return [recursive_asdict(d) for d in dfp_data]
Exemplo n.º 6
0
 def _convert_response_to_dict(self, dfp_data):
     """
     @param dfp_data: list(SUDS)
     @return: list(dict)
     """
     return [recursive_asdict(d) for d in dfp_data]