From 0381c5ea6c6fd7238fb95ba80d1c0c9266eb4699 Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 21 Nov 2023 21:21:10 +0100 Subject: [PATCH] add moerder list, improve Athenanans names in badge list, clean up main.py file --- main.py | 17 ++++++++++++++--- parse.py | 23 ++++++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 9c63dec..e1917ed 100755 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from datetime import datetime from pathlib import Path -from parse import badge_data, parse, rahmprog_stats, wiki_stats +from parse import badge_data, moerder_list, parse, rahmprog_stats, wiki_stats def print_wiki_stats(filename: str) -> None: @@ -16,6 +16,17 @@ FILENAME = "koma89_pretixdata.json" if __name__ == "__main__": + # uncomment relevant stuff + print("Nothing to do!") + #print_wiki_stats(FILENAME) - with open("badge_data.csv", "w") as f: - f.write(badge_data(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)) + + #with open("moerder_list.csv", "w") as f: + # f.write(moerder_list(FILENAME)) diff --git a/parse.py b/parse.py index f76e340..cb41167 100644 --- a/parse.py +++ b/parse.py @@ -56,11 +56,17 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co continue for position in order['positions']: item_id = position['item'] - attendee_name = position.get('attendee_name') if item_id not in relevant_items: continue + # specialcasing custom Athenanas names + def get_answer(qa, col): + if col != ATHENE_ID or "Sonstiges" not in qa[col]: + return qa.get(col, "") + return qa.get(ATHENE_CUSTOM_ID, "") + quest_ans = {a['question'] : a['answer'] for a in position['answers']} - res.append((items[item_id], attendee_name) + tuple(quest_ans.get(col) for col in columns)) + attendee_name = position.get('attendee_name') or "" # for mascots, they are "None" but empty strings are prettier + res.append((items[item_id], attendee_name) + tuple(get_answer(quest_ans, col) for col in columns)) # hacky sanity check that we do not have to escape csv for line in res: @@ -72,10 +78,21 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co def rahmprog_stats(filename) -> str: return query_to_csv(filename, (HUMAN_ID,), (NICKNAME_ID, RAHMERST_ID, RAHMZWEIT_ID)) +def moerder_list(filename) -> str: + moerder_id = 301 + result = query_to_csv(filename, (HUMAN_ID,), (NICKNAME_ID, UNI_ID, moerder_id)) + ret = "" + for line in result.splitlines(): + if line.endswith('"False"'): + # does not want to take part + continue + ret += line + "\n" + return ret + 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)) + return query_to_csv(filename, (HUMAN_ID, MASCOT_ID), (NICKNAME_ID, nickname_only_id, UNI_ID, pronoun_id, ATHENE_ID))