La til pdf eksport for startliste

This commit is contained in:
Trygve 2022-04-01 20:13:27 +02:00
parent 2b22bcb7e1
commit 06dae8b35b
2 changed files with 25 additions and 4 deletions

9
dev.py
View File

@ -7,9 +7,10 @@ from rich.table import Table
if __name__ == "__main__": if __name__ == "__main__":
event = otime.event(0, 'supercup') event = otime.event(0, 'supercup')
event.import_ttime_cnf('sc_2021_ttime/ttime.cnf.txt') event.import_ttime_cnf('k2ds/tt.cnf')
event.import_ttime_db('sc_2021_ttime/db_eventor.csv') event.import_ttime_db('k2ds/db.csv')
event.import_mtr_file('sc_2021_ttime/mtr.csv') event.import_mtr_file('k2ds/mtr.txt')
#card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv') #card_punches = otime.card_punch.list_from_mtr_f('sc_2021_ttime/mtr.csv')
event.match_runners_cards() event.match_runners_cards()
event.get_xml_res().write('Resultater.xml') event.create_start_list_pdf('starttimes.pdf')
#event.get_xml_res().write('Resultater.xml')

View File

@ -3,6 +3,7 @@ import datetime
import csv import csv
import re import re
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from fpdf import FPDF
class event: class event:
def __init__(self, eventid, name, **kwargs): def __init__(self, eventid, name, **kwargs):
@ -127,6 +128,25 @@ class event:
#</Class> #</Class>
ET.indent(root, space=' ', level=0) ET.indent(root, space=' ', level=0)
return tree return tree
def create_start_list_pdf(self, file_name):
pdf = FPDF()
pdf.add_page()
pdf.add_font("DejaVuSans", fname="/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf")
pdf.set_font("DejaVuSans", size=10)
line_height = pdf.font_size * 2
col_width = pdf.epw / 4 # distribute content evenly
for runner in self.runners:
pdf.multi_cell(col_width, line_height, runner.fullname(), border=1, ln=3, max_line_height=pdf.font_size, align='L')
pdf.multi_cell(col_width, line_height, runner.o_class.name, border=1, ln=3, max_line_height=pdf.font_size)
pdf.multi_cell(col_width, line_height, str(runner.card), border=1, ln=3, max_line_height=pdf.font_size)
if runner.start_time != None:
pdf.multi_cell(col_width, line_height, str(runner.start_time), border=1, ln=3, max_line_height=pdf.font_size)
else:
pdf.multi_cell(col_width, line_height, '', border=1, ln=3, max_line_height=pdf.font_size)
pdf.ln(line_height)
pdf.output(file_name)
class runner: class runner:
def __init__(self, runner_id, first, last, club, country, card, o_class, start_time): def __init__(self, runner_id, first, last, club, country, card, o_class, start_time):
self.id = runner_id self.id = runner_id