Commit b7c4a1ed authored by PizZaKatZe's avatar PizZaKatZe

Implement self-organized session data filter

parent ca636424
......@@ -17,7 +17,9 @@
"""JHT flyer generator
from datetime import datetime
from json import load
from re import sub
from typing import Dict, List
from urllib.request import urlopen
......@@ -33,6 +35,31 @@ def fetch_data(url: str) -> List[Dict]:
results: Dict = load(urlopen(url))['results']
return list(results.values())
def filter_session(session: Dict) -> Dict:
"""Re-organizes self-organized session data for easier access in templates.
Also filters out superfluous stuff, that appears to be always empty.
session: a dict containing information about a self-organized session
an uncluttered, organized version of the input dict containing only relevant data
def filter_provider(provider: Dict) -> Dict:
filtered = {}
filtered['name'] = sub('Static:', '', provider['fulltext'])
filtered['url'] = sub('Static:', '', provider['fullurl'])
return filtered
def filter_start(start: Dict) -> str:
return datetime.fromtimestamp(int(start['timestamp'])).strftime('%Y-%m-%d %H:%M')
result = {}
result['title'] = sub('Session:', '', session['fulltext'])
result['description'] = ' '.join(session['printouts']['description'])
result['url'] = session['fullurl']
result['providers'] = list(map(filter_provider, session['printouts']['organized by']))
result['starttimes'] = list(map(filter_start, session['printouts']['Start']))
return result
def read_data(path: str) -> List[Dict]:
"""Reads self-organized session data from file.
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