-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathAlienImport.py
40 lines (34 loc) · 1.21 KB
/
AlienImport.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
import wx
import re
import Model
from ChipImport import ChipImportDialog
import datetime
def parseTagTime( line, lineNo, errors ):
fields = [f.strip() for f in line.split(',')]
if not fields:
return None, None
if fields[0] == 'Tag':
return None, None
try:
tag = fields[0].replace( ' ', '' )
tStr = re.sub( '[^0-9]', ' ', fields[1] ).strip()
hh, mm, ss, mss, year, mon, day = tStr.split()[1:] # Skip the day of the month number.
mss += '0' * max(0, 6-len(mss))
t = datetime.datetime( int(year), int(mon), int(day), int(hh), int(mm), int(ss), int(mss) )
return tag, t
except Exception:
errors.append( '{} {}: {}'.format(_('line'), lineNo, _('unrecognised input')) )
return None, None
def AlienImportDialog( parent, id = wx.ID_ANY ):
return ChipImportDialog( 'Alien', parseTagTime, parent, id )
if __name__ == '__main__':
errors = []
with open(r"C:\Users\edwar\Downloads\Alien-2017-05-10-18-37-51.txt",'r',encoding='utf8') as f:
for lineno, line in enumerate(f,1):
print( parseTagTime( line, lineno, errors ) )
app = wx.App(False)
mainWin = wx.Frame(None,title="CrossMan", size=(600,400))
Model.setRace( Model.Race() )
mainWin.Show()
with AlienImportDialog(mainWin) as dlg:
dlg.ShowModal()