La til import av ttime config

This commit is contained in:
Trygve 2022-02-05 20:07:46 +01:00
parent 0545146d96
commit 29321676e2

62
main.py
View File

@ -1,12 +1,13 @@
import datetime import datetime
import csv import csv
import sqlite3 import sqlite3
import re
from rich.console import Console from rich.console import Console
from rich.table import Table from rich.table import Table
from rich.traceback import install from rich.traceback import install
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
install(show_locals=True) install(show_locals=True)
class Runner: class runner:
def __init__(self, first, last, club, country, card, o_class, controls, splits): def __init__(self, first, last, club, country, card, o_class, controls, splits):
self.first = first self.first = first
self.last = last self.last = last
@ -20,7 +21,44 @@ class Runner:
def fullname(self): def fullname(self):
return '{} {}'.format(self.first, self.last) return '{} {}'.format(self.first, self.last)
def xmlToClass(xml_file = 'entries_KOK_Sommercup,_løp_2.xml'): class course:
def __init__(self, name, codes):
self.name = name
self.codes = codes
class o_class:
def __init__(self, name, course):
self.name = name
self.course = course
def import_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
courses = []
o_classes = []
conf = open(ttime_file).readlines()
for line in conf:
if '-codes' in line:
code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
loops = 0
for n in code_list:
n = n.split(',')
loops += 1
courses.append(course('course_'+str(loops), n))
print(n)
print(courses)
print(courses[1].name)
elif '-courses' in line:
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
loops = 0
for n in raw_courselist:
n.split(',')
for i in n:
o_classes.append(o_class(i,courses[loops]))
loops += 1
print(o_classes[1].course.codes)
def xml_to_class(xml_file = 'entries_KOK_Sommercup,_løp_2.xml'):
tree = ET.parse(xml_file) tree = ET.parse(xml_file)
root = tree.getroot() root = tree.getroot()
runnerarray = [] runnerarray = []
@ -41,9 +79,9 @@ def xmlToClass(xml_file = 'entries_KOK_Sommercup,_løp_2.xml'):
o_class = person_root[4][1].text o_class = person_root[4][1].text
except: except:
o_class = "None" o_class = "None"
runnerarray.append(Runner(first, last, club, country, card, o_class, [], [])) runnerarray.append(runner(first, last, club, country, card, o_class, [], []))
return runnerarray return runnerarray
def ttimeMtrToClass(csv_file, runnerarray): def ttime_mtr_to_class(csv_file, runnerarray):
csvreader = csv.reader(open(csv_file)) csvreader = csv.reader(open(csv_file))
fields = next(csvreader) fields = next(csvreader)
@ -69,7 +107,7 @@ def ttimeMtrToClass(csv_file, runnerarray):
if runner.card == int(row[6]): if runner.card == int(row[6]):
runner.controls = controls runner.controls = controls
runner.splits = splits runner.splits = splits
def printTable(Runners): def print_table(Runners):
table = Table(title="Runners") table = Table(title="Runners")
table.add_column("Name", justify="right", style="cyan", no_wrap=True) table.add_column("Name", justify="right", style="cyan", no_wrap=True)
table.add_column("club", style="magenta") table.add_column("club", style="magenta")
@ -82,15 +120,21 @@ def printTable(Runners):
console = Console() console = Console()
console.print(table) console.print(table)
courses = []
o_classes = []
if __name__ == "__main__": if __name__ == "__main__":
Runners = xmlToClass() import_ttime_conf()
Runners = xml_to_class()
#print(Runners[4].last) #print(Runners[4].last)
#printTable(Runners) #print_table(Runners)
ttimeMtrToClass('mtr.csv', Runners) #ttime_mtr_to_class('sc_2021_ttime/mtr.csv', Runners)
for i in Runners: """
for i in Runners:
print(i.first + ' ' + i.last) print(i.first + ' ' + i.last)
print(i.controls) print(i.controls)
#print(i.splits) #print(i.splits)
try: try:
print(str(datetime.timedelta(seconds = i.splits[-1]))) print(str(datetime.timedelta(seconds = i.splits[-1])))
except: print('ikke deltatt') except: print('ikke deltatt')
"""