forked from Trygve/otime
Ferdigstilte oppdatering gjennom ttime db
This commit is contained in:
parent
387d04e379
commit
0f0fd6ebf2
60
event_mgr.py
60
event_mgr.py
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import otime
|
import otime
|
||||||
import pickle
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
from difflib import Differ
|
from difflib import Differ
|
||||||
from watchgod import awatch
|
from watchgod import awatch
|
||||||
@ -18,49 +18,65 @@ def start():
|
|||||||
event.import_ttime_db(config['db_file'])
|
event.import_ttime_db(config['db_file'])
|
||||||
event.import_mtr_file('/home/trygve/Documents/sprintcup040330/sprintcup040330.log')
|
event.import_mtr_file('/home/trygve/Documents/sprintcup040330/sprintcup040330.log')
|
||||||
event.match_runners_cards()
|
event.match_runners_cards()
|
||||||
#event.get_xml_res().write(config['xml_res_file'])
|
|
||||||
global db_file
|
global db_file
|
||||||
global db_file_u
|
global db_file_u
|
||||||
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
db_file = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async for changes in awatch(config['db_file']):
|
async for changes in awatch(config['db_file']):
|
||||||
#print(dir(changes))
|
|
||||||
#print(changes.difference()
|
|
||||||
global event
|
global event
|
||||||
global db_file
|
global db_file
|
||||||
global db_file_u
|
global db_file_u
|
||||||
|
print(len(event.runners))
|
||||||
db_file_u = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
db_file_u = open(config['db_file'], 'r', encoding='latin_1').read().splitlines()
|
||||||
d = Differ()
|
d = Differ()
|
||||||
result = list(d.compare(db_file, db_file_u))
|
result = list(d.compare(db_file, db_file_u))
|
||||||
db_file = db_file_u
|
db_file = db_file_u
|
||||||
|
|
||||||
|
added_raw = []
|
||||||
|
removed_raw = []
|
||||||
|
added = []
|
||||||
|
removed = []
|
||||||
|
changed = []
|
||||||
for line in result:
|
for line in result:
|
||||||
if line[:1] == '+':
|
if line[:1] == '+':
|
||||||
print(line)
|
#print(line)
|
||||||
clean = str(line).replace('+ ', '').split(';')
|
clean = str(line).replace('+ ', '').split(';')
|
||||||
runner = otime.runner.from_string(clean, event.o_classes)
|
runner = otime.runner.from_string(clean, event.o_classes)
|
||||||
inspect(runner)
|
added_raw.append(runner)
|
||||||
for i, n in enumerate(event.runners):
|
|
||||||
if n.id == runner.id:
|
|
||||||
inspect(n)
|
|
||||||
event.runners[i] = runner
|
|
||||||
inspect(n)
|
|
||||||
event.match_runners_cards()
|
|
||||||
inspect(n)
|
|
||||||
|
|
||||||
elif line[:1] == '-':
|
elif line[:1] == '-':
|
||||||
print(line)
|
#print(line)
|
||||||
print('MINUS')
|
|
||||||
clean = str(line).replace('- ', '').split(';')
|
clean = str(line).replace('- ', '').split(';')
|
||||||
r_id = clean[1]
|
runner = otime.runner.from_string(clean, event.o_classes)
|
||||||
print(r_id)
|
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:
|
||||||
for i, n in enumerate(event.runners):
|
for i, n in enumerate(event.runners):
|
||||||
if n.id == r_id:
|
if n.id == runner.id:
|
||||||
inspect(n)
|
event.runners[i] = runner
|
||||||
print(len(event.runners))
|
event.match_runners_cards()
|
||||||
event.runners.remove(n)
|
print(len(event.runners))
|
||||||
print(len(event.runners))
|
event.get_xml_res().write(config['xml_res_file'])
|
||||||
|
|
||||||
|
|
||||||
db_file_u = None
|
db_file_u = None
|
||||||
|
Loading…
Reference in New Issue
Block a user