-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_output.py
71 lines (59 loc) · 3.62 KB
/
console_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import datetime
import sys
from bash_color import BashColor
def print_day_schedule(sessions):
if len(sessions) > 0:
earliest_start = sessions[0].start
sys.stdout.write(BashColor.BOLD + ' {id:<{width}}'.format(id='ID', width=9) + BashColor.DARKGREY + ' # ' + BashColor.END)
sys.stdout.write(BashColor.BOLD + '{title:<{width}}'.format(title='TITLE', width=60) + BashColor.DARKGREY + ' # ' + BashColor.END)
sys.stdout.write(BashColor.BOLD + BashColor.VIOLET + '{type:<{width}}'.format(type='TYPE', width=10) + BashColor.DARKGREY + ' # ' + BashColor.END)
sys.stdout.write(BashColor.BOLD + BashColor.RED + '{location:<{width}}'.format(location='LOCATION', width=9) +
BashColor.DARKGREY + ' # ' + BashColor.END)
sys.stdout.write(BashColor.BOLD + BashColor.YELLOW + '{start} '.format(start='SCHEDULE') + BashColor.END)
sys.stdout.write('\n')
sys.stdout.write(BashColor.BOLD + BashColor.DARKGREY + '{id}'.format(id='-' * 11) + '+')
sys.stdout.write('{title}'.format(title='-' * 60) + '--+')
sys.stdout.write('{type}'.format(type='-' * 10) + '--+')
sys.stdout.write('{location}'.format(location='-' * 9) + '--+')
sys.stdout.write('{start} '.format(start='-' * 30) + BashColor.END)
sys.stdout.write('\n')
sys.stdout.flush()
for session in sessions:
_print_session_for_day_schedule(earliest_start, session)
sys.stdout.flush()
sys.stdout.write('\n')
def _print_session_for_day_schedule(earliest_start, session):
duration = (session.end - session.start).seconds // 60 // 15
start_offset = (session.start - earliest_start).seconds // 60 // 15
mark_reserved_session = ''
if session.reserved:
mark_reserved_session = BashColor.GREEN
sys.stdout.write(BashColor.BOLD + mark_reserved_session + ' {id:<{width}}'.format(id=session.id, width=9) + BashColor.DARKGREY + ' | ' + BashColor.END)
sys.stdout.write('{title:<{width}}'.format(title=session.title[:60], width=60) + BashColor.DARKGREY + ' | ' + BashColor.END)
sys.stdout.write(BashColor.VIOLET + '{type:<{width}}'.format(type=session.type[:10], width=10) + BashColor.DARKGREY + ' | ' + BashColor.END)
sys.stdout.write(BashColor.RED + '{location:<{width}}'.format(location=session.location.split(',')[0][:9], width=9) + BashColor.DARKGREY + ' | ' + BashColor.END)
sys.stdout.write(' ' * start_offset)
sys.stdout.write(BashColor.YELLOW + '{start} '.format(start=datetime.datetime.strftime(session.start, '%H:%M')))
sys.stdout.write('#' * duration)
sys.stdout.write(' {end}'.format(end=datetime.datetime.strftime(session.end, '%H:%M')) + BashColor.END)
sys.stdout.write('\n')
def print_sessions(sessions, args):
for session in sessions:
print_session(session, args)
def print_session(session, args):
mark_reserved_session = ''
if session.reserved:
mark_reserved_session = BashColor.GREEN
print(BashColor.UNDERLINE + mark_reserved_session + '{id} - {title}'.format(id=session.id, title=session.title) + BashColor.END)
print(BashColor.VIOLET + '{type}'.format(type=session.type) + BashColor.END + ' by ' +
BashColor.BLUE + ', '.join(session.speakers) + BashColor.END)
print(
BashColor.YELLOW + '{start} -> {end}'.format(
start=datetime.datetime.strftime(session.start, '%a (%b %d) %H:%M'),
end=datetime.datetime.strftime(session.end, '%H:%M')
) + BashColor.END +
' @ ' + BashColor.RED + '{location}'.format(location=session.location) + BashColor.END
)
if args.verbose and args.verbose >= 2:
print(BashColor.DIM + '{abstract}'.format(abstract=session.abstract) + BashColor.END)
print()