Exemple #1
0
def build_campaigns(assessment, campaign_number, template_smtp):
    """Build a campaign."""
    # Set up component holders
    logging.info("Building Campaign %s", assessment.id)
    campaign = Campaign(name=assessment.id)
    campaign_tz = pytz.timezone(assessment.timezone)

    # Get Launch Time
    while True:
        campaign.launch_date = get_time_input("start", assessment.timezone)

        if campaign.launch_date > datetime.now(campaign_tz).isoformat():
            break
        else:
            logging.error("Launch date is not after the current datetime")

    while True:
        campaign.complete_date = get_time_input("end", assessment.timezone)

        if campaign.complete_date > campaign.launch_date:
            pass  # Do nothing yet and continue checks
        else:
            logging.error("Complete date is not after launch date.")

        if campaign.complete_date > datetime.now(campaign_tz).isoformat():
            break  # Valid input, break out of loop
        else:
            logging.error("Complete date is not after the current datetime.")

    campaign.smtp, campaign.template = import_email(
        assessment, campaign_number, template_smtp
    )

    # Select Group:
    campaign.group_name = select_group(assessment)

    # Select page:
    campaign.page_name = select_page(assessment)

    campaign.url = prompt(
        "    Campaign URL: ",
        default="http://" + assessment.domain,
        validator=BlankInputValidator(),
    )

    campaign = review_campaign(campaign)

    logging.info("Successfully Added Campaign {}".format(campaign.name))

    return campaign
Exemple #2
0
def build_campaigns(assessment, campaign_number, template_smtp):
    """Build a campaign."""
    # Set up component holders
    logging.info(f"Building Campaign {assessment.id}-C{campaign_number}")
    campaign = Campaign(name=f"{assessment.id}-C{campaign_number}")
    # Get Launch Time
    campaign.launch_date = get_time_input("start", assessment.timezone)

    while True:
        campaign.complete_date = get_time_input("end", assessment.timezone)

        if campaign.complete_date > campaign.launch_date:
            break
        else:
            logging.error("Complete Date is not after Launch Date.")

    campaign.smtp, campaign.template = import_email(assessment,
                                                    campaign_number,
                                                    template_smtp)

    # Select Group:
    campaign.group_name = select_group(assessment)

    # Select page:
    campaign.page_name = select_page(assessment)

    campaign.url = prompt(
        "    Campaign URL: ",
        default="http://" + assessment.domain,
        validator=BlankInputValidator(),
    )

    campaign = review_campaign(campaign)

    logging.info("Successfully Added Campaign {}".format(campaign.name))

    return campaign