Commit 55967f85 authored by PizZaKatZe's avatar PizZaKatZe

Add option to print tex document to stdout

parent 083b800f
......@@ -22,7 +22,7 @@ from json import dumps
from sys import argv
from sys import stdout
from jht_flyergen.engine import fetch_data, generate_flyer, process_sessions, read_data
from jht_flyergen.engine import fetch_data, render, generate_tex, process_sessions, read_data
TEST_URL = 'https://events.ccc.de/congress/2018/wiki/index.php/Special:Ask/cl:YzpVT9tKxFAM_KKaouzLQl5ERH1QYb8gp03t2Z5LSVJK_XrTdRcUcplhhjAZqmQyPGstkGKOhofWQZmQUoKRqWdR1LGuoEzSjYkCJ3w7fbxDl0hdq2IUEjf37RqneMOa1wuEXUeo4oeQtIM6DMqGLTSHR69XdfNQxecUez0eTRZuDk9e0Dw87_1Cu6dn7STOFmvBP_hm-pTasSr3bg2bD8_GOaQNq3xRid9X5f9RXUINZ-7s7sqNxHxbzIynnUCmWH6fhlnYbJslFsM9JizFg9DMF_YD' # pylint: disable=line-too-long
......@@ -39,6 +39,8 @@ def parse_arguments(args):
parser.add_argument('-p', '--print',
help='print filtered data of session with index PRINT, starting at 1; '
'0 prints all sessions')
parser.add_argument('-t', '--tex', action='store_true',
help='print tex document to stdout')
parser.add_argument('output', nargs='?',
help='path to output file; if omitted raw PDF data is written to stdout')
......@@ -71,7 +73,10 @@ def main():
end = int(args.print)
pretty_print(sessions[0 : end if end else -1])
flyer = generate_flyer(sessions, args.homepage, args.links)
tex = generate_tex(sessions, args.homepage, args.links)
if args.tex:
print(tex)
flyer = render(tex)
if args.output:
with open(args.output, 'wb') as output:
output.write(flyer)
......
......@@ -40,8 +40,16 @@ def fetch_data(url: str) -> List[Dict]:
results: Dict = load(urlopen(url))['results']
return list(results.values())
def generate_flyer(sessions: List[Dict], homeurl: str, links=True) -> bytes:
"""Generates a PDF from self-organized session data.
def generate_tex(sessions: List[Dict], homeurl: str, links=True) -> str:
"""Generates a LaTeX document from self-organized session data.
Args:
sessions: processed self-organized session data
homeurl: URL of JHT homepage
links: if set, QR codes with links to session wiki page are generated
Returns:
a LaTeX document
"""
libpath = dirname(__file__)
env = make_env(loader=FileSystemLoader(libpath))
......@@ -54,6 +62,7 @@ def process_sessions(sessions: List[Dict], day: int) -> List[Dict]:
Args:
sessions: a list of raw session data as read from URL / file
day: day of month on which JHT takes place
Retruns:
a list of filtered, re-organized session data
......@@ -79,6 +88,17 @@ def read_data(path: str) -> List[Dict]:
with open(path) as data_file:
return load(data_file)
def render(tex: str) -> bytes:
"""Renders a LaTeX document.
Args:
tex: a LaTeX document
Returns:
raw PDF bytes
"""
return build_pdf(tex).__bytes__()
def transform_session(session: Dict, day: int) -> List[Dict]:
"""Re-organizes self-organized session data for easier access in templates.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment