Пример #1
0
    def _next6(self):
        # TODO: This is a repeat of _run for the most part.
        dtstart = datetime.datetime.today()

        out('Loading state....')

        state = phil.util.load_state(self.config.datadir)

        out('Parsing ics file "{0}"....'.format(self.config.icsfile))

        events = parse_ics(self.config.icsfile)
        for event in events:
            out('Looking at event "{0}"....'.format(event.summary))
            next_date = dtstart

            for i in range(6):
                next_date = get_next_date(next_date, event.rrule)
                previous_remind = state.get(event.event_id)
                if (previous_remind
                        and previous_remind == str(next_date.date())):
                    out('* {0} (sent reminder already)'.format(
                        next_date.strftime('%c')))

                else:
                    out('* {0}'.format(next_date.strftime('%c')))

                next_date = next_date + datetime.timedelta(1)
Пример #2
0
    def _next6(self):
        # TODO: This is a repeat of _run for the most part.
        dtstart = datetime.datetime.today()

        out('Loading state....')

        state = phil.util.load_state(self.config.datadir)

        out('Parsing ics file "{0}"....'.format(self.config.icsfile))

        events = parse_ics(self.config.icsfile)
        for event in events:
            out('Looking at event "{0}"....'.format(event.summary))
            next_date = dtstart

            for i in range(6):
                next_date = get_next_date(next_date, event.rrule)
                previous_remind = state.get(event.event_id)
                if (previous_remind
                        and previous_remind == str(next_date.date())):
                    out('* {0} (sent reminder already)'.format(
                        next_date.strftime('%c')))

                else:
                    out('* {0}'.format(next_date.strftime('%c')))

                next_date = next_date + datetime.timedelta(1)
Пример #3
0
    def _run(self):
        dtstart = datetime.datetime.today()

        if not self.quiet:
            out('Loading state....')

        state = phil.util.load_state(self.config.datadir)

        if not self.quiet:
            out('Parsing ics file "{0}"....'.format(self.config.icsfile))

        events = parse_ics(self.config.icsfile)
        for event in events:
            if not self.quiet:
                out('Looking at event "{0}"....'.format(event.summary))

            next_date = get_next_date(dtstart, event.rrule)
            previous_remind = state.get(event.event_id)
            if previous_remind and previous_remind == str(next_date.date()):
                if not self.quiet:
                    out('Already sent a reminder for this meeting.')
                continue

            if should_remind(dtstart, next_date, self.config.remind):
                if not self.quiet:
                    out('Sending reminder....')
                summary = '{0} ({1})'.format(event.summary,
                                             format_date(next_date))
                description = event.description % generate_date_bits(next_date)

                if self.debug:
                    out('From:', self.config.sender)
                    out('To:', self.config.to_list)
                    out('Subject:', summary)
                    out('Body:')
                    out(description, indent='    ', wrap=False)
                else:
                    phil.util.send_mail_smtp(self.config.sender,
                                             self.config.to_list, summary,
                                             description, self.config.host,
                                             self.config.port)

                    state[event.event_id] = str(next_date.date())
            elif not self.quiet:
                out('Next reminder should get sent on {0}.'.format(
                    next_date.date() - datetime.timedelta(self.config.remind)))

        phil.util.save_state(self.config.datadir, state)
Пример #4
0
    def _run(self):
        dtstart = datetime.datetime.today()

        if not self.quiet:
            out('Loading state....')

        state = phil.util.load_state(self.config.datadir)

        if not self.quiet:
            out('Parsing ics file "{0}"....'.format(self.config.icsfile))

        events = parse_ics(self.config.icsfile)
        for event in events:
            if not self.quiet:
                out('Looking at event "{0}"....'.format(event.summary))

            next_date = get_next_date(dtstart, event.rrule)
            previous_remind = state.get(event.event_id)
            if previous_remind and previous_remind == str(next_date.date()):
                if not self.quiet:
                    out('Already sent a reminder for this meeting.')
                continue

            if should_remind(dtstart, next_date, self.config.remind):
                if not self.quiet:
                    out('Sending reminder....')
                summary = '{0} ({1})'.format(
                    event.summary, format_date(next_date))
                description = event.description % generate_date_bits(next_date)

                if self.debug:
                    out('From:', self.config.sender)
                    out('To:', self.config.to_list)
                    out('Subject:', summary)
                    out('Body:')
                    out(description, indent='    ', wrap=False)
                else:
                    phil.util.send_mail_smtp(
                        self.config.sender, self.config.to_list, summary,
                        description, self.config.host, self.config.port)

                    state[event.event_id] = str(next_date.date())
            elif not self.quiet:
                out('Next reminder should get sent on {0}.'.format(
                    next_date.date() - datetime.timedelta(self.config.remind)))

        phil.util.save_state(self.config.datadir, state)
Пример #5
0
def test_should_remind():
    def build_rrule(freq, **args):
        freq = FREQ_MAP[freq]
        return dateutil.rrule.rrule(freq, **args)

    # look at yesterday at 12:00
    today = datetime.datetime.today()
    td = datetime.timedelta

    # 1 days from now
    rule = build_rrule('DAILY', dtstart=today + td(1), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), True)

    # 2 day from now
    rule = build_rrule('DAILY', dtstart=today + td(2), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 3 days from now
    rule = build_rrule('DAILY', dtstart=today + td(3), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 4 days from now
    rule = build_rrule('DAILY', dtstart=today + td(4), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 5 days from now
    rule = build_rrule('DAILY', dtstart=today + td(5), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 6 days from now
    rule = build_rrule('DAILY', dtstart=today + td(6), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 3 days from now, remind in 3
    rule = build_rrule('DAILY', dtstart=today + td(3), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 3), True)
Пример #6
0
def test_should_remind():
    def build_rrule(freq, **args):
        freq = FREQ_MAP[freq]
        return dateutil.rrule.rrule(freq, **args)

    # look at yesterday at 12:00
    today = datetime.datetime.today()
    td = datetime.timedelta

    # 1 days from now
    rule = build_rrule('DAILY', dtstart=today + td(1), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), True)

    # 2 day from now
    rule = build_rrule('DAILY', dtstart=today + td(2), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 3 days from now
    rule = build_rrule('DAILY', dtstart=today + td(3), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 4 days from now
    rule = build_rrule('DAILY', dtstart=today + td(4), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 5 days from now
    rule = build_rrule('DAILY', dtstart=today + td(5), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 6 days from now
    rule = build_rrule('DAILY', dtstart=today + td(6), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 1), False)

    # 3 days from now, remind in 3
    rule = build_rrule('DAILY', dtstart=today + td(3), interval=7)
    eq_(should_remind(today, get_next_date(today, rule), 3), True)