add moerder list, improve Athenanans names in badge list, clean up main.py file

This commit is contained in:
Johannes 2023-11-21 21:21:10 +01:00
parent 3f15fa10b3
commit 0381c5ea6c
2 changed files with 34 additions and 6 deletions

17
main.py
View file

@ -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))

View file

@ -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))