-
Notifications
You must be signed in to change notification settings - Fork 20
/
IpicoImport.py
68 lines (57 loc) · 1.54 KB
/
IpicoImport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import wx
import datetime
import Model
from ChipImport import ChipImportDialog
def parseTagTime( line, lineNo, errors ):
line = line.strip()
try:
i = line.index( 'aa' )
except ValueError:
return None, None
line = line[i:]
if line.endswith( '\\' ):
line = line[:-1]
if line.endswith( 'LS' ):
return None, None
try:
tag = line[4:16]
year = line[20:22]
month = line[22:24]
day = line[24:26]
hour = line[26:28]
minute = line[28:30]
second = line[30:32]
hundreths = line[32:34]
except IndexError:
return None, None
try:
year = 2000 + int(year)
month = int(month)
day = int(day)
hour = int(hour)
minute = int(minute)
second = int(second)
hundreths = int(hundreths)
except ValueError:
return None, None
try:
t = datetime.datetime(year=year, month=month, day=day, hour=hour, minute=minute, second=second, microsecond=hundreths*10000)
except Exception as e:
errors.append( 'line: {}: Error: {}, line='.format( lineNo, e ) )
return None, None
return tag, t
def IpicoImportDialog( parent, id = wx.ID_ANY ):
return ChipImportDialog( 'Ipico', parseTagTime, parent, id, fileSuffix = 'rtf' )
if __name__ == '__main__':
errors = []
for fname in ['Ipico/FS_LS.rtf']:
with open(fname, encoding='utf8') as f:
for i, line in enumerate(f):
print( parseTagTime( line, i, errors ) )
print( errors )
app = wx.App(False)
mainWin = wx.Frame(None,title="CrossMan", size=(600,400))
Model.setRace( Model.Race() )
mainWin.Show()
with IpicoImportDialog(mainWin) as dlg:
dlg.ShowModal()