コード例 #1
0
def create_industrial_thing_stocks(thing_offers_by_name):
    logger.info("create_industrial_thing_stocks")

    thing_stocks_by_name = {}
    short_names_to_increase_price = []

    thing_offer_items = list(thing_offers_by_name.items())

    thing_offer_items_with_stocks = remove_every(thing_offer_items, THING_OFFERS_WITH_STOCK_REMOVE_MODULO)

    for thing_offer_item_with_stocks in thing_offer_items_with_stocks:
        (thing_offer_with_stocks_name, thing_offer_with_stocks) = thing_offer_item_with_stocks
        quantity = 20

        short_name = get_occurrence_short_name(thing_offer_with_stocks_name)
        price = get_price_by_short_name(short_name)
        price_counter = short_names_to_increase_price.count(short_name)
        if price_counter > 2:
            price = price + price_counter
        short_names_to_increase_price.append(short_name)

        name = thing_offer_with_stocks_name + " / " + str(quantity) + " / " + str(price)
        thing_stocks_by_name[name] = create_stock_from_offer(thing_offer_with_stocks, quantity=quantity, price=price)

    repository.save(*thing_stocks_by_name.values())

    logger.info("created %d thing_stocks", len(thing_stocks_by_name))
コード例 #2
0
def create_industrial_event_stocks(event_occurrences_by_name):
    logger.info("create_industrial_event_stocks")

    event_stocks_by_name = {}
    short_names_to_increase_price = []

    event_occurrence_items = list(event_occurrences_by_name.items())

    event_occurrence_items_with_stocks = remove_every(
        event_occurrence_items, EVENT_OCCURRENCES_WITH_STOCKS_REMOVE_MODULO
    )

    for event_occurrence_item_with_stocks in event_occurrence_items_with_stocks:
        (event_occurrence_with_stocks_name, event_occurrence_with_stocks) = event_occurrence_item_with_stocks
        available = 10

        short_name = get_occurrence_short_name(event_occurrence_with_stocks_name)
        price = get_price_by_short_name(short_name)
        price_counter = short_names_to_increase_price.count(short_name)
        if price_counter > 2:
            price = price + price_counter
        short_names_to_increase_price.append(short_name)

        if event_occurrence_with_stocks["offer"].product.offerType["value"] == str(EventType.ACTIVATION):
            price = 0

        name = event_occurrence_with_stocks_name + " / " + str(available) + " / " + str(price)

        event_stocks_by_name[name] = create_stock_from_event_occurrence(
            event_occurrence_with_stocks, price=price, quantity=available
        )

    repository.save(*event_stocks_by_name.values())

    logger.info("created %d event_stocks", len(event_stocks_by_name))
コード例 #3
0
def create_industrial_event_occurrences(event_offers_by_name):
    logger.info("create_industrial_event_occurrences")

    event_occurrences_by_name = {}

    event_offers = list(event_offers_by_name.values())

    event_offers_with_occurrences = remove_every(event_offers, EVENT_OFFERS_WITH_OCCURRENCES_REMOVE_MODULO)

    for event_offer_with_occurrences in event_offers_with_occurrences:
        for beginning_datetime in EVENT_OCCURRENCE_BEGINNING_DATETIMES:
            name = "{} / {} / {} ".format(
                event_offer_with_occurrences.product.name,
                event_offer_with_occurrences.venue.name,
                strftime(beginning_datetime),
            )
            event_occurrences_by_name[name] = create_event_occurrence(
                beginning_datetime=strftime(beginning_datetime), offer=event_offer_with_occurrences
            )

    return event_occurrences_by_name
コード例 #4
0
def create_industrial_mediations(offers_by_name):
    logger.info("create_industrial_mediations")

    mediations_with_asset = {}
    mediations_by_name = {}

    offer_items = list(offers_by_name.items())
    offer_items_with_mediation = remove_every(
        offer_items, OFFERS_WITH_MEDIATION_REMOVE_MODULO)
    for (offer_with_mediation_name,
         offer_with_mediation) in offer_items_with_mediation:
        mediations_by_name[offer_with_mediation_name] = create_mediation(
            offer_with_mediation)

    repository.save(*mediations_by_name.values())

    for mediation in mediations_by_name.values():
        mediations_with_asset[
            mediation.id] = store_public_object_from_sandbox_assets(
                "thumbs", mediation, mediation.offer.type)

    repository.save(*mediations_with_asset.values())

    logger.info("created %d mediations", len(mediations_by_name))