final adjustemens, export for participation certificate

adjusted long time ago, just forgot to commit...
This commit is contained in:
Johannes 2024-03-12 10:40:55 +01:00
parent 0381c5ea6c
commit ccc2a42ad2
2 changed files with 13 additions and 4 deletions

View file

@ -2,7 +2,7 @@
from datetime import datetime
from pathlib import Path
from parse import badge_data, moerder_list, parse, rahmprog_stats, wiki_stats
from parse import *
def print_wiki_stats(filename: str) -> None:
@ -30,3 +30,6 @@ if __name__ == "__main__":
#with open("moerder_list.csv", "w") as f:
# f.write(moerder_list(FILENAME))
#with open("participation_confirmation.csv", "w") as f:
# f.write(participant_certificate_list(FILENAME))

View file

@ -33,7 +33,7 @@ NICKNAME_ID = 298
def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], columns: List[str]) -> str:
def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], columns: List[str], include_type = True) -> str:
"""Parse a JSON export from pretix and query some columns from some orders.
:param filename: filename of the JSON export to parse.
@ -49,6 +49,8 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co
quest_answers = {id_: {} for id_ in questions}
head = ("type", "fullname") + tuple(questions[col] for col in columns)
if not include_type:
head = head[1:]
res = [head]
for order in data['orders']:
@ -66,14 +68,15 @@ def query_to_csv(filename: Union[str, Path], relevant_items: Collection[int], co
quest_ans = {a['question'] : a['answer'] for a in position['answers']}
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))
start = (attendee_name, ) if not include_type else (items[item_id], attendee_name)
res.append(start + 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:
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(map(str, line)) + '"') for line in res)
return "\n".join( ('"' + '";"'.join(map(str, line)) + '"') for line in [res[0]] + sorted(res[1:]))
def rahmprog_stats(filename) -> str:
return query_to_csv(filename, (HUMAN_ID,), (NICKNAME_ID, RAHMERST_ID, RAHMZWEIT_ID))
@ -94,6 +97,9 @@ def badge_data(filename) -> str:
nickname_only_id = 311
return query_to_csv(filename, (HUMAN_ID, MASCOT_ID), (NICKNAME_ID, nickname_only_id, UNI_ID, pronoun_id, ATHENE_ID))
def participant_certificate_list(filename) -> str:
ret = query_to_csv(filename, (HUMAN_ID,), (UNI_ID,), False)
return ret
def parse(filename: Union[str, Path]) -> Tuple[