Commit fd20e0cf authored by PizZaKatZe's avatar PizZaKatZe

Fix handling of recurring sessions

parent 02028b15
......@@ -30,6 +30,8 @@ def parse_arguments(args):
"""Parses command-line arguments.
"""
parser = ArgumentParser()
parser.add_argument('-d', '--day', nargs='?', default=28,
help='day of month (default: 28)')
parser.add_argument('-l', '--links', action='store_true',
help='generate QR codes with links to sessions\'s wiki pages')
parser.add_argument('-m', '--homepage',
......@@ -63,7 +65,7 @@ def main():
sessions = fetch_data(args.url)
elif args.path:
sessions = read_data(args.path)
sessions = process_sessions(sessions)
sessions = process_sessions(sessions, int(args.day))
if args.print:
end = int(args.print)
......
......@@ -48,7 +48,7 @@ def generate_flyer(sessions: List[Dict], homeurl: str, links=True) -> bytes:
pdf = build_pdf(template.render(sessions=sessions, homeurl=homeurl, links=links))
return pdf.__bytes__()
def process_sessions(sessions: List[Dict]) -> List[Dict]:
def process_sessions(sessions: List[Dict], day: int) -> List[Dict]:
"""Filters out irrelevant sessions and sanitizes session data.
Args:
......@@ -58,10 +58,11 @@ def process_sessions(sessions: List[Dict]) -> List[Dict]:
a list of filtered, re-organized session data
"""
def is_correct_date(start: Dict) -> bool:
return datetime.fromtimestamp(int(start['timestamp'])).day == 27
return datetime.fromtimestamp(int(start['timestamp'])).day == day
def relevant(session: Dict) -> bool:
return bool(list(filter(is_correct_date, session['printouts']['Start'])))
sessions = [transform_session(s) for s in sessions if relevant(s)]
sessions = [transform_session(s, day) for s in sessions if relevant(s)]
sessions = [s for ss in sessions for s in ss]
sessions.sort(key=lambda a: a['start'])
return sessions
......@@ -77,7 +78,7 @@ def read_data(path: str) -> List[Dict]:
with open(path) as data_file:
return load(data_file)
def transform_session(session: Dict) -> Dict:
def transform_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.
......@@ -88,15 +89,20 @@ def transform_session(session: Dict) -> Dict:
Returns:
an uncluttered, organized version of the input dict containing only relevant data
"""
def build_session(title, url, providers, start):
result = {}
result['title'] = title
result['url'] = url
result['providers'] = providers
result['start'] = start
return result
def parse_date(start: Dict) -> datetime:
return datetime.fromtimestamp(int(start['timestamp']))
def process_provider(provider: Dict) -> str:
return sub('Assembly:', '', sub('Static:', '', provider['fulltext']))
result = {}
result['title'] = sub('Session:', '', session['fulltext'])
result['url'] = session['fullurl']
providers = list(map(process_provider, session['printouts']['organized by']))
result['providers'] = ', '.join(providers)
title = sub('Session:', '', session['fulltext'])
url = session['fullurl']
providers = ', '.join(map(process_provider, session['printouts']['organized by']))
starts = list(map(parse_date, session['printouts']['Start']))
result['start'] = list(filter(lambda d: d.day == 27, starts))[0].strftime('%H:%M')
return result
starts = [s.strftime('%H:%M') for s in filter(lambda d: d.day == day, starts)]
return [build_session(title, url, providers, s) for s in starts]
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