implement export of badge data
This commit is contained in:
parent
d54ab30523
commit
3f15fa10b3
2 changed files with 13 additions and 7 deletions
6
main.py
6
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))
|
||||
|
|
14
parse.py
14
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],
|
||||
|
|
Loading…
Reference in a new issue