def print_transcript(trans,
                     terms=None,
                     report='transcript_default',
                     show=['summary', 'credit', 'grades']):
    if 'header' not in show:
        del trans['000000']

    if terms is not None:
        iter = (term for term in terms)
    else:
        iter = (term for term in sorted(trans.keys()))

    for term in iter:
        termv = trans[term]
        (info_fmt, gpa_fmt, grades_fmt) = load_transcript_format(report)

        if 'summary' in show:
            sys.stdout.write(sched_parse.apply_format(termv['info'], info_fmt))

        if 'credit' in show and 'tgpa' in termv['info']:
            sys.stdout.write(sched_parse.apply_format(termv['info'], gpa_fmt))

        if 'grades' in show and termv['grades']:
            sort = config.reports[report]['sort']
            grades = sched_parse.multi_keysort(termv['grades'], sort)
            print ""
            for grade in grades:
                sys.stdout.write(sched_parse.apply_format(grade, grades_fmt))
def gen_ics_event(entry, datetime, fmt, tag):
    dt_start, dt_end = find_exam_times(datetime)
    location = entry['_building'] + ' ' + entry['room']

    summary = sched_ics.ics_escape(sched_parse.apply_format(entry, fmt[0]))
    description = sched_ics.ics_escape(sched_parse.apply_format(entry, fmt[1]))
    uid = entry['_code'] + '-' + tag + "@minervac.icebergsys.net"
    created = dt.utcnow().strftime(iso_date['full']) + "Z"

    cal = u"""
BEGIN:VEVENT
UID:{uid}
SUMMARY:{summary}
DTSTAMP;VALUE=DATE-TIME:{dt_stamp}
DTSTART;TZID=America/Montreal;VALUE=DATE-TIME:{dt_start}
DTEND;TZID=America/Montreal;VALUE=DATE-TIME:{dt_end}
DESCRIPTION:{description}
LOCATION:{location}
END:VEVENT""".format(uid=uid,
                     summary=summary,
                     description=description,
                     location=location,
                     dt_start=dt_start,
                     dt_end=dt_end,
                     dt_stamp=created)

    return cal
def timetable_struct(sched, report='timetable_default'):
    (fmt, sched) = sched_parse.prepare_report(report, sched)
    timetable = {}
    i = 1

    for entry in sched:
        if '_time' not in entry:
            continue

        t_start = entry['_time']['start']
        if t_start not in timetable:
            timetable[t_start] = {}

        if entry['days'] not in timetable[t_start]:
            timetable[t_start][entry['days']] = {}

        entry['_action_desc'] = entry['_action_desc'].replace(
            '\033[1;32m',
            '<strong>').replace('\033[0m',
                                '</strong>')  #FIXME: This is really ugly.
        summary = sched_parse.apply_format(entry, fmt)

        wait = 'wait_pos' in entry and entry['wait_pos'] is not None
        timetable[t_start][entry['days']][i] = ((entry['_time'], summary,
                                                 wait))
        i += 1

    return timetable
Beispiel #4
0
def export_ics_sched(sched, report='cal'):
    fmt = prepare_cal_report(report)

    cal = u"""BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Minervaclient//NONSGML minervac.icebergsys.net//EN"""

    for entry in sched:
        (days, dt_start, dt_end) = find_first_day(entry['days'],
                                                  entry['_date']['start'],
                                                  entry['_time']['start'],
                                                  entry['_time']['end'])
        date_end = find_last_day(entry['_date']['end'])

        location = entry['_building'] + ' ' + entry['_room']

        summary = ics_escape(sched_parse.apply_format(entry, fmt[0]))
        description = ics_escape(sched_parse.apply_format(entry, fmt[1]))
        uid = entry['_code'] + "@minervac.icebergsys.net"
        created = dt.utcnow().strftime(iso_date['full']) + "Z"

        cal += u"""
BEGIN:VEVENT
UID:{uid}
SUMMARY:{summary}
DTSTAMP;VALUE=DATE-TIME:{dt_stamp}
DTSTART;TZID=America/Montreal;VALUE=DATE-TIME:{dt_start}
DTEND;TZID=America/Montreal;VALUE=DATE-TIME:{dt_end}
DESCRIPTION:{description}
LOCATION:{location}
RRULE:FREQ=WEEKLY;UNTIL={date_end};BYDAY={days}
END:VEVENT""".format(uid=uid,
                     summary=summary,
                     description=description,
                     location=location,
                     dt_start=dt_start,
                     dt_end=dt_end,
                     days=days,
                     date_end=date_end,
                     dt_stamp=created)

    cal += u"""
END:VCALENDAR"""

    return cal