2022-03-13 20:19:07 +00:00
|
|
|
#!/usr/bin/env python
|
2022-03-11 14:33:09 +00:00
|
|
|
import otime
|
2022-03-17 16:52:26 +00:00
|
|
|
import json
|
2022-03-13 16:33:26 +00:00
|
|
|
import asyncio
|
2022-03-13 20:19:07 +00:00
|
|
|
from difflib import Differ
|
2022-03-13 16:33:26 +00:00
|
|
|
from watchgod import awatch
|
2022-03-11 14:33:09 +00:00
|
|
|
from config import config
|
|
|
|
from rich import print
|
|
|
|
from rich import inspect
|
|
|
|
from rich.console import Console
|
|
|
|
from rich.columns import Columns
|
|
|
|
from rich.table import Table
|
|
|
|
|
2022-03-13 16:33:26 +00:00
|
|
|
def start():
|
2022-03-16 20:28:49 +00:00
|
|
|
global event
|
2022-03-11 14:33:09 +00:00
|
|
|
event = otime.event(0, config['event_name'])
|
|
|
|
event.import_ttime_cnf('/home/trygve/Documents/sprintcup040330/sprintcup040330.cnf')
|
|
|
|
event.import_ttime_db(config['db_file'])
|
|
|
|
event.import_mtr_file('/home/trygve/Documents/sprintcup040330/sprintcup040330.log')
|
|
|
|
event.match_runners_cards()
|
2022-03-16 20:28:49 +00:00
|
|
|
global db_file
|
|
|
|
global db_file_u
|
|
|
|
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
2022-03-11 14:33:09 +00:00
|
|
|
|
2022-03-13 16:33:26 +00:00
|
|
|
async def main():
|
|
|
|
async for changes in awatch(config['db_file']):
|
2022-03-16 20:28:49 +00:00
|
|
|
global event
|
|
|
|
global db_file
|
|
|
|
global db_file_u
|
2022-03-17 16:52:26 +00:00
|
|
|
print(len(event.runners))
|
2022-03-16 20:28:49 +00:00
|
|
|
db_file_u = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
2022-03-13 20:19:07 +00:00
|
|
|
d = Differ()
|
|
|
|
result = list(d.compare(db_file, db_file_u))
|
2022-03-16 20:28:49 +00:00
|
|
|
db_file = db_file_u
|
2022-03-13 20:19:07 +00:00
|
|
|
|
2022-03-17 16:52:26 +00:00
|
|
|
added_raw = []
|
|
|
|
removed_raw = []
|
|
|
|
added = []
|
|
|
|
removed = []
|
|
|
|
changed = []
|
2022-03-13 20:19:07 +00:00
|
|
|
for line in result:
|
|
|
|
if line[:1] == '+':
|
2022-03-17 16:52:26 +00:00
|
|
|
#print(line)
|
2022-03-16 20:28:49 +00:00
|
|
|
clean = str(line).replace('+ ', '').split(';')
|
|
|
|
runner = otime.runner.from_string(clean, event.o_classes)
|
2022-03-17 16:52:26 +00:00
|
|
|
added_raw.append(runner)
|
2022-03-16 20:28:49 +00:00
|
|
|
|
|
|
|
elif line[:1] == '-':
|
2022-03-17 16:52:26 +00:00
|
|
|
#print(line)
|
2022-03-16 20:28:49 +00:00
|
|
|
clean = str(line).replace('- ', '').split(';')
|
2022-03-17 16:52:26 +00:00
|
|
|
runner = otime.runner.from_string(clean, event.o_classes)
|
|
|
|
removed_raw.append(runner)
|
|
|
|
|
|
|
|
for plus in added_raw:
|
|
|
|
for index, minus in enumerate(removed_raw):
|
|
|
|
if plus.id == minus.id:
|
|
|
|
changed.append(plus)
|
|
|
|
removed_raw[index] = plus
|
|
|
|
break
|
|
|
|
|
|
|
|
added = [x for x in added_raw if x not in changed]
|
|
|
|
removed = [x for x in removed_raw if x not in changed]
|
|
|
|
#print(len(added_raw),len(removed_raw))
|
|
|
|
#print(len(added),len(removed),len(changed))
|
|
|
|
|
|
|
|
event.runners.extend(added)
|
|
|
|
|
|
|
|
for r in removed:
|
|
|
|
for n in event.runners:
|
|
|
|
if n.id == r.id:
|
|
|
|
event.runners.remove(n)
|
|
|
|
|
|
|
|
for change in changed:
|
2022-03-16 20:28:49 +00:00
|
|
|
for i, n in enumerate(event.runners):
|
2022-03-17 16:52:26 +00:00
|
|
|
if n.id == runner.id:
|
|
|
|
event.runners[i] = runner
|
|
|
|
event.match_runners_cards()
|
|
|
|
print(len(event.runners))
|
|
|
|
event.get_xml_res().write(config['xml_res_file'])
|
2022-03-16 20:28:49 +00:00
|
|
|
|
2022-03-13 20:19:07 +00:00
|
|
|
|
2022-03-16 20:28:49 +00:00
|
|
|
db_file_u = None
|
2022-03-11 14:33:09 +00:00
|
|
|
if __name__ == "__main__":
|
2022-03-13 16:33:26 +00:00
|
|
|
start()
|
|
|
|
asyncio.run(main())
|