Beispiel #1
0
    def event_date_processor():
        def suffix(d):
            return ("th" if 11 <= d <= 13 else {
                1: "st",
                2: "nd",
                3: "rd"
            }.get(d % 10, "th"))

        s = event_start()
        e = event_end()
        assert s.year == e.year
        if s.month == e.month:
            fancy_dates = f"""{s.strftime('%B')}<span style="white-space: nowrap">
                {s.day}<sup>{suffix(s.day)}</sup>&ndash;{e.day}<sup>{suffix(e.day)}</sup>
                {s.year}
                </span>"""

            simple_dates = f"{s.day}&ndash;{e.day} {s.strftime('%B')}"

        else:
            fancy_dates = f"""{s.strftime("%B")}
                {s.day}<sup>{suffix(s.day)}</sup>&ndash;{e.strftime("%B")}
                {e.day}<sup>{suffix(e.day)}</sup>"""

            simple_dates = (
                f"""{s.day} {s.strftime("%B")}&ndash;{e.day} {e.strftime("%B")}"""
            )

        return {
            "fancy_dates": Markup(fancy_dates),
            "simple_dates": Markup(simple_dates),
            "event_start": s,
            "event_end": e,
            "event_year": s.year,
        }
Beispiel #2
0
def make_root():
    root = etree.Element('schedule')

    _add_sub_with_text(root, 'version', '1.0-public')

    conference = etree.SubElement(root, 'conference')

    _add_sub_with_text(conference, 'title', 'Electromagnetic Field {}'.format(event_start().year))
    _add_sub_with_text(conference, 'acronym', 'emf{}'.format(event_start().year))
    _add_sub_with_text(conference, 'start', event_start().strftime('%Y-%m-%d'))
    _add_sub_with_text(conference, 'end', event_end().strftime('%Y-%m-%d'))
    _add_sub_with_text(conference, 'days', '3')
    _add_sub_with_text(conference, 'timeslot_duration', '00:10')

    return root
Beispiel #3
0
    def event_date_processor():
        def suffix(d):
            return 'th' if 11 <= d <= 13 else {1: 'st', 2: 'nd', 3: 'rd'}.get(d % 10, 'th')

        s = event_start()
        e = event_end()
        assert s.year == e.year
        if s.month == e.month:
            fancy_dates = '{s_month} ' \
                '<span style="white-space: nowrap">' \
                '{s.day}<sup>{s_suff}</sup>&mdash;' \
                '{e.day}<sup>{e_suff}</sup>' \
                '</span>' \
                .format(s=s, s_suff=suffix(s.day),
                        s_month=s.strftime('%B'),
                        e=e, e_suff=suffix(e.day))

            simple_dates = '{s.day}&mdash;' \
                '{e.day} ' \
                '{s_month}' \
                .format(s=s, s_month=s.strftime('%B'),
                        e=e)

        else:
            fancy_dates = '{s_month} ' \
                '{s.day}<sup>{s_suff}</sup>&ndash;' \
                '{e_month} ' \
                '{e.day}<sup>{e_suff}</sup>' \
                .format(s=s, s_suff=suffix(s.day),
                        s_month=s.strftime('%B'),
                        e=e, e_suff=suffix(e.day),
                        e_month=e.strftime('%B'))

            simple_dates = '{s.day} ' \
                '{s_month}&ndash;' \
                '{e.day} ' \
                '{e_month}' \
                .format(s=s, s_month=s.strftime('%B'),
                        e=e, e_month=e.strftime('%B'))


        return {
            'fancy_dates': Markup(fancy_dates),
            'simple_dates': Markup(simple_dates),
            'event_start': s,
            'event_end': e,
            'event_year': s.year,
        }
Beispiel #4
0
def make_root():
    root = etree.Element('schedule')

    _add_sub_with_text(root, 'version', '1.0-public')

    conference = etree.SubElement(root, 'conference')

    _add_sub_with_text(conference, 'title',
                       'Electromagnetic Field {}'.format(event_start().year))
    _add_sub_with_text(conference, 'acronym',
                       'emf{}'.format(event_start().year))
    _add_sub_with_text(conference, 'start', event_start().strftime('%Y-%m-%d'))
    _add_sub_with_text(conference, 'end', event_end().strftime('%Y-%m-%d'))
    _add_sub_with_text(conference, 'days', '3')
    _add_sub_with_text(conference, 'timeslot_duration', '00:10')

    return root
Beispiel #5
0
def make_root():
    root = etree.Element("schedule")

    _add_sub_with_text(root, "version", "1.0-public")

    conference = etree.SubElement(root, "conference")

    _add_sub_with_text(conference, "title",
                       "Electromagnetic Field {}".format(event_start().year))
    _add_sub_with_text(conference, "acronym",
                       "emf{}".format(event_start().year))
    _add_sub_with_text(conference, "start", event_start().strftime("%Y-%m-%d"))
    _add_sub_with_text(conference, "end", event_end().strftime("%Y-%m-%d"))
    _add_sub_with_text(conference, "days", "3")
    _add_sub_with_text(conference, "timeslot_duration", "00:10")

    return root
Beispiel #6
0
    def refresh(self):
        request = requests.get(self.url)

        cal = Calendar.from_ical(request.text)
        if self.name is None:
            self.name = cal.get('X-WR-CALNAME')

        for event in self.events:
            event.displayed = False

        local_tz = pendulum.timezone('Europe/London')
        alerts = []
        uids_seen = set()
        out_of_range_event = False
        for component in cal.walk():
            if component.name == 'VEVENT':
                summary = component.get('Summary')

                # postgres converts to UTC if given an aware datetime, so strip it up front
                start_dt = pendulum.instance(component.get('dtstart').dt)
                start_dt = local_tz.convert(start_dt).naive()

                end_dt = pendulum.instance(component.get('dtend').dt)
                end_dt = local_tz.convert(end_dt).naive()

                name = summary
                if summary and start_dt:
                    name = "'{}' at {}".format(summary, start_dt)
                elif summary:
                    name = "'{}'".format(summary)
                elif start_dt:
                    name = 'Event at {}'.format(start_dt)
                else:
                    name = len(self.events) + 1

                if not component.get('uid'):
                    alerts.append(('danger', "{} has no UID".format(name)))
                    continue

                uid = str(component['uid'])
                if uid in uids_seen:
                    alerts.append(('danger', "{} has duplicate UID {}".format(name, uid)))
                    continue
                uids_seen.add(uid)

                if 'rrule' in component:
                    alerts.append(('warning', "{} has rrule, which is not processed".format(uid)))

                # Allow a bit of slop for build-up events
                if start_dt < event_start() - pendulum.duration(days=2) and not out_of_range_event:
                    alerts.append(('warning', "At least one event ({}) is before the start of the event".format(uid)))
                    out_of_range_event = True

                if end_dt > event_end() + pendulum.duration(days=1) and not out_of_range_event:
                    alerts.append(('warning', "At least one event ({}) is after the end of the event".format(uid)))
                    out_of_range_event = True

                if start_dt > end_dt:
                    alerts.append(('danger', "Start time for {} is after its end time".format(uid)))
                    out_of_range_event = True


                try:
                    event = CalendarEvent.query.filter_by(source_id=self.id, uid=uid).one()

                except NoResultFound:
                    event = CalendarEvent(uid=uid)
                    self.events.append(event)
                    if len(self.events) > 1000:
                        raise Exception("Too many events in feed")

                event.start_dt = start_dt
                event.end_dt = end_dt
                event.summary = component.get('summary')
                event.description = component.get('description')
                event.location = component.get('location')
                event.displayed = True

        self.refreshed_at = pendulum.now()

        return alerts
Beispiel #7
0
    def refresh(self):
        request = requests.get(self.url)

        cal = Calendar.from_ical(request.text)
        if self.name is None:
            self.name = cal.get("X-WR-CALNAME")

        for event in self.events:
            event.displayed = False

        local_tz = pendulum.timezone("Europe/London")
        alerts = []
        uids_seen = set()
        out_of_range_event = False
        for component in cal.walk():
            if component.name == "VEVENT":
                summary = component.get("Summary")

                # postgres converts to UTC if given an aware datetime, so strip it up front
                start_dt = pendulum.instance(component.get("dtstart").dt)
                start_dt = local_tz.convert(start_dt).naive()

                end_dt = pendulum.instance(component.get("dtend").dt)
                end_dt = local_tz.convert(end_dt).naive()

                name = summary
                if summary and start_dt:
                    name = "'{}' at {}".format(summary, start_dt)
                elif summary:
                    name = "'{}'".format(summary)
                elif start_dt:
                    name = "Event at {}".format(start_dt)
                else:
                    name = len(self.events) + 1

                if not component.get("uid"):
                    alerts.append(("danger", "{} has no UID".format(name)))
                    continue

                uid = str(component["uid"])
                if uid in uids_seen:
                    alerts.append(
                        ("danger", "{} has duplicate UID {}".format(name,
                                                                    uid)))
                    continue
                uids_seen.add(uid)

                if "rrule" in component:
                    alerts.append(
                        ("warning",
                         "{} has rrule, which is not processed".format(uid)))

                # Allow a bit of slop for build-up events
                if (start_dt < event_start() - pendulum.duration(days=2)
                        and not out_of_range_event):
                    alerts.append((
                        "warning",
                        "At least one event ({}) is before the start of the event"
                        .format(uid),
                    ))
                    out_of_range_event = True

                if (end_dt > event_end() + pendulum.duration(days=1)
                        and not out_of_range_event):
                    alerts.append((
                        "warning",
                        "At least one event ({}) is after the end of the event"
                        .format(uid),
                    ))
                    out_of_range_event = True

                if start_dt > end_dt:
                    alerts.append((
                        "danger",
                        "Start time for {} is after its end time".format(uid),
                    ))
                    out_of_range_event = True

                try:
                    event = CalendarEvent.query.filter_by(source_id=self.id,
                                                          uid=uid).one()

                except NoResultFound:
                    event = CalendarEvent(uid=uid)
                    self.events.append(event)
                    if len(self.events) > 1000:
                        raise Exception("Too many events in feed")

                event.start_dt = start_dt
                event.end_dt = end_dt
                event.summary = component.get("summary")
                event.description = component.get("description")
                event.location = component.get("location")
                event.displayed = True

        self.refreshed_at = pendulum.now()

        return alerts