forked from esitarski/CrossMgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlienImport.py
48 lines (42 loc) · 1.32 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
40
41
42
43
44
45
46
47
import wx
import io
import re
import six
import math
import Utils
import Model
import JChip
from ChipImport import ChipImportDialog
import datetime
combine = datetime.datetime.combine
import string
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:
errors.append( u'{} {}: {}'.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 io.open(r"C:\Users\edwar\Downloads\Alien-2017-05-10-18-37-51.txt",'r',encoding='utf-8') as f:
for lineno, line in enumerate(f,1):
six.print_( parseTagTime( line, lineno, errors ) )
app = wx.App(False)
mainWin = wx.Frame(None,title="CrossMan", size=(600,400))
Model.setRace( Model.Race() )
mainWin.Show()
dlg = AlienImportDialog( mainWin )
dlg.ShowModal()
dlg.Destroy()