...
 
Commits (2)
......@@ -30,9 +30,11 @@ def parse_arguments(args):
"""Parses command-line arguments.
"""
parser = ArgumentParser()
parser.add_argument('-p', '--print',
parser.add_argument('-p', '--print', action='store_true',
help='print filtered data of session with index PRINT, starting at 1; ' +
'0 prints all sessions')
parser.add_argument('-q', '--qrcodes', action='store_true',
help='print QR encoded URLs to sessions\'s wiki pages')
parser.add_argument('output', nargs='?',
help='path to output file; if omitted raw PDF data is written to stdout')
......@@ -67,6 +69,6 @@ def main():
if args.output:
with open(args.output, 'wb') as output:
output.write(generate_flyer(sessions))
output.write(generate_flyer(sessions, args.qrcodes))
else:
stdout.buffer.write(generate_flyer(sessions))
stdout.buffer.write(generate_flyer(sessions, args.qrcodes))
......@@ -40,12 +40,12 @@ def fetch_data(url: str) -> List[Dict]:
results: Dict = load(urlopen(url))['results']
return list(results.values())
def generate_flyer(sessions: List[Dict]) -> bytes:
def generate_flyer(sessions: List[Dict], urls=True) -> bytes:
"""Generates a PDF from self-organized session data.
"""
env = make_env(loader=FileSystemLoader(dirname(__file__)))
template = env.get_template('template.tex')
pdf = build_pdf(template.render(sessions=sessions))
pdf = build_pdf(template.render(sessions=sessions, urls=urls))
return pdf.__bytes__()
def process_sessions(sessions: List[Dict]) -> List[Dict]:
......@@ -61,8 +61,9 @@ def process_sessions(sessions: List[Dict]) -> List[Dict]:
return datetime.fromtimestamp(int(start['timestamp'])).day == 27
def relevant(session: Dict) -> bool:
return bool(list(filter(is_correct_date, session['printouts']['Start'])))
sessions = list(filter(relevant, sessions))
return list(map(transform_session, sessions))
sessions = [transform_session(s) for s in sessions if relevant(s)]
sessions.sort(key=lambda a: a['start'])
return sessions
def read_data(path: str) -> List[Dict]:
"""Reads self-organized session data from file.
......
......@@ -23,16 +23,29 @@
\begin{document}
\maketitle
\begin{longtable}{|p{0.45\linewidth}|p{0.2\linewidth}|l|l|}
%- if urls
\begin{longtable}{|l|p{0.45\linewidth}|p{0.2\linewidth}|l|}
\hline
\textbf{Was?} & \textbf{Wo?} & \textbf{Wann?} & \textbf{URL}
\textbf{Wann?} & \textbf{Was?} & \textbf{Wo?} & \textbf{URL}
\\ \hline \hline
%- for session in sessions
\VAR{session.title | e} & \VAR{session.providers | e} & \VAR{session.start | e}
\VAR{session.start | e} & \VAR{session.title | e} & \VAR{session.providers | e}
& \qrcode{\VAR{session.url | e}}
\\ \hline
%- endfor
\end{longtable}
%- else
\begin{longtable}{|l|p{0.45\linewidth}|p{0.2\linewidth}|}
\hline
\textbf{Wann?} & \textbf{Was?} & \textbf{Wo?}
\\ \hline \hline
%- for session in sessions
\VAR{session.start | e} & \VAR{session.title | e} & \VAR{session.providers | e}
\\ \hline
%- endfor
\end{longtable}
%- endif
\end{document}