Commits (4)
......@@ -24,7 +24,7 @@ from re import sub
from typing import Dict, List
from urllib.request import urlopen
from jinja2 import FileSystemLoader
from jinja2 import FileSystemLoader # type: ignore; pylint: disable=import-error
from latex import build_pdf # type: ignore; pylint: disable=import-error
from latex.jinja2 import make_env # type: ignore; pylint: disable=import-error
......@@ -67,12 +67,8 @@ def process_sessions(sessions: List[Dict], day: int) -> List[Dict]:
a list of filtered, re-organized session data
def is_correct_date(start: Dict) -> bool:
return datetime.utcfromtimestamp(int(start['timestamp'])).day == day
def relevant(session: Dict) -> bool:
return bool(list(filter(is_correct_date, session['printouts']['starts'])))
sessionss = [transform_session(s, day) for s in sessions if relevant(s)]
sessions = [s for ss in sessionss for s in ss]
sessions = [unpack_session(s, day) for s in sessions] # returns a list of lists
sessions = [s for ss in sessions for s in ss]
sessions.sort(key=lambda a: a['start'])
return sessions
......@@ -99,7 +95,7 @@ def render(tex: str) -> bytes:
return build_pdf(tex).__bytes__()
def transform_session(session: Dict, day: int) -> List[Dict]:
def unpack_session(session: Dict, day: int) -> List[Dict]:
"""Re-organizes self-organized session data for easier access in templates.
Also filters out superfluous stuff, that appears to be always empty.
......@@ -108,9 +104,9 @@ def transform_session(session: Dict, day: int) -> List[Dict]:
session: a dict containing information about a self-organized session
an uncluttered, organized version of the input dict containing only relevant data
a list of all instances of the self-organized session
def build_session(title, url, location, start, end):
def build_session(title, url, start, end, location):
result = {}
result['title'] = title
result['url'] = url
......@@ -118,16 +114,19 @@ def transform_session(session: Dict, day: int) -> List[Dict]:
result['start'] = start
result['end'] = end
return result
def has_correct_date(session):
return session['start'].day == day and session['end'].day == day
def transform_session(session):
session['location'] = sub('Assembly:', '', sub('Room:', '', session['location']))
session['start'] = session['start'].strftime('%H:%M')
session['end'] = session['end'].strftime('%H:%M')
return session
def parse_date(start: Dict) -> datetime:
return datetime.utcfromtimestamp(int(start['timestamp']))
def process_provider(provider: Dict) -> str:
return sub('Assembly:', '', sub('Room:', '', provider['fulltext']))
title = sub('Session:', '', session['fulltext'])
url = session['fullurl']
location = session['printouts']['location']
location = process_provider(location[0]) if location else ''
start_dates = list(map(parse_date, session['printouts']['starts']))
starts = [s.strftime('%H:%M') for s in filter(lambda d: d.day == day, start_dates)]
end_dates = list(map(parse_date, session['printouts']['ends']))
ends = [s.strftime('%H:%M') for s in filter(lambda d: d.day == day, end_dates)]
return [build_session(title, url, location, s, e) for s, e in zip(starts, ends)]
locations = [s['fulltext'] for s in session['printouts']['location']]
starts = list(map(parse_date, session['printouts']['starts']))
ends = list(map(parse_date, session['printouts']['ends']))
instances = [build_session(title, url, s, e, l) for s, e, l in zip(starts, ends, locations)]
return [transform_session(i) for i in instances if has_correct_date(i)]
No preview for this file type