Example #1
0
def message_schedule(person_name, message, ical, count, frequency, lexbot,
                     interval, timezone, start_date, start_time, end_date,
                     bot_names, ice_breaker, required_bots, introduction,
                     end_time):
    try:
        print ice_breaker
        print required_bots
        click.echo("Scheduling message for person {}".format(person_name))
        scheduler = Scheduler()
        if not timezone:
            timezone = tzlocal.get_localzone().zone
            click.echo('Timezone: {}'.format(timezone))

        if start_time is None:
            start_time = arrow.now(timezone).format('HH:mm')

        if start_date is None:
            start_date = arrow.now(timezone).format('YYYY-MM-DD')

        start_datetime = arrow.get(
            '{} {}'.format(start_date, start_time)) \
            .replace(tzinfo=tz.gettz(timezone)).to('UTC')

        if end_time is None:
            end_time = start_time.format('HH:mm')

        if end_date is None:
            end_date = start_datetime.replace(years=10).format('YYYY-MM-DD')

        end_datetime = arrow.get(
            '{} {}'.format(end_date, end_time)) \
            .replace(tzinfo=tz.gettz(timezone)).to('UTC')

        message = ScheduledMessage(StartDateTimeInUtc=start_datetime,
                                   ical=ical,
                                   Body=message,
                                   PersonName=person_name,
                                   Frequency=frequency,
                                   Count=count,
                                   Lexbot=lexbot,
                                   TimeZone=timezone,
                                   Interval=interval,
                                   BotNames=bot_names,
                                   IceBreaker=ice_breaker,
                                   Introduction=introduction,
                                   RequiredBots=required_bots,
                                   EndDateTimeInUtc=end_datetime)
        scheduler.schedule_message(message)
        click.echo('Start Time: {}'.format(start_datetime))
        click.echo('End Time: {}'.format(end_datetime))
        if ical:
            click.echo('ical:\n{}'.format(ical))
        print "Next: {}".format(message.next_occurrence_local)
        print message.to_ical()

    except Exception:
        click.echo(traceback.print_exc())
        exit(2)
Example #2
0
def test_passing_startdate_adds_to_ical():
    start_date = arrow.get('2012-01-01 01:01:00 UTC')
    ical = 'BEGIN:VEVENT\r\n' + \
        'DTSTART;VALUE=DATE-TIME:20120101T010100Z\r\n' + \
        'END:VEVENT\r\n'

    m = ScheduledMessage(
            StartDateTimeInUtc=start_date,
            Body="Test",
            PersonName="test")
    assert ical == m.to_ical()
Example #3
0
def test_passing_enddate_adds_to_ical():
    start_date = arrow.get('2012-01-01 01:01:00 UTC')
    end_date = start_date.replace(days=5)
    ical = 'BEGIN:VEVENT\r\n' + \
        'DTSTART;VALUE=DATE-TIME:20120101T010100Z\r\n' + \
        'DTEND;VALUE=DATE-TIME:20120106T010100Z\r\n' + \
        'RRULE:FREQ=HOURLY\r\n' + \
        'END:VEVENT\r\n'

    m = ScheduledMessage(
            StartDateTimeInUtc=start_date,
            EndDateTimeInUtc=end_date,
            Body="Test",
            Frequency='HOURLY',
            PersonName="test")
    assert ical == m.to_ical()