diff --git a/main.py b/main.py index cd19298..9c63dec 100755 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from datetime import datetime from pathlib import Path -from parse import parse, rahmprog_stats, wiki_stats +from parse import badge_data, parse, rahmprog_stats, wiki_stats def print_wiki_stats(filename: str) -> None: @@ -17,5 +17,5 @@ FILENAME = "koma89_pretixdata.json" if __name__ == "__main__": #print_wiki_stats(FILENAME) - with open("rahmprogramm_wahlen.csv", "w") as f: - f.write(rahmprog_stats(FILENAME)) + with open("badge_data.csv", "w") as f: + f.write(badge_data(FILENAME)) diff --git a/parse.py b/parse.py index e5aaeda..f76e340 100644 --- a/parse.py +++ b/parse.py @@ -48,7 +48,7 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co quest_titles = {q['id']: q['question'] for q in data['questions']} quest_answers = {id_: {} for id_ in questions} - head = ("Typ", "Name") + tuple(questions[col] for col in columns) + head = ("type", "fullname") + tuple(questions[col] for col in columns) res = [head] for order in data['orders']: @@ -60,18 +60,24 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co if item_id not in relevant_items: continue quest_ans = {a['question'] : a['answer'] for a in position['answers']} - res.append((items[item_id], attendee_name) + tuple(quest_ans[col] for col in columns)) + res.append((items[item_id], attendee_name) + tuple(quest_ans.get(col) for col in columns)) # hacky sanity check that we do not have to escape csv for line in res: - if any('"' in ans for ans in line): + if any('"' in ans for ans in line if ans): raise RuntimeError(f"Illegal CSV char, escape needed in line {line}") - return "\n".join( ('"' + '","'.join(line) + '"') for line in res) + return "\n".join( ('"' + '","'.join(map(str, line)) + '"') for line in res) def rahmprog_stats(filename) -> str: return query_to_csv(filename, (HUMAN_ID,), (NICKNAME_ID, RAHMERST_ID, RAHMZWEIT_ID)) +def badge_data(filename) -> str: + pronoun_id = 299 + nickname_only_id = 311 + return query_to_csv(filename, (HUMAN_ID, MASCOT_ID), (NICKNAME_ID, nickname_only_id, UNI_ID, pronoun_id, ATHENE_ID, ATHENE_CUSTOM_ID)) + + def parse(filename: Union[str, Path]) -> Tuple[ Dict[int, str],