Initial checkin
--HG-- branch : sandbox
This commit is contained in:
35
src/pricefeed.py
Normal file
35
src/pricefeed.py
Normal file
@@ -0,0 +1,35 @@
|
||||
""" pricefeed file filter
|
||||
*.log: "20070905 09:04:56.841|DE000DB0M091|4.430|4.440"
|
||||
*.csv: "09:04:56.841,DB0M09,4.430,4.440"
|
||||
"""
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
mol = re.compile("\S+\s(\S+?)\|.{5}(.{6}).\|(.*)\|(.*)")
|
||||
|
||||
def main(argv = None):
|
||||
if argv == None:
|
||||
argv = sys.argv
|
||||
if (len(argv) != 2):
|
||||
print "Usage: filter.py <filename.log>"
|
||||
return 2
|
||||
ifn = argv[1]
|
||||
ofn = "".join((ifn.split(".")[0], ".csv"))
|
||||
print "Converting [%s] to [%s]" % (ifn, ofn)
|
||||
try:
|
||||
ifh = open(ifn, "r")
|
||||
ofh = open(ofn, "w")
|
||||
except IOError:
|
||||
print "open [%s] failed" % ifn
|
||||
return 2
|
||||
try:
|
||||
for line in ifh:
|
||||
flds = mol.match(line)
|
||||
print >>ofh, ",".join(flds.groups())
|
||||
finally:
|
||||
ifh.close()
|
||||
ofh.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
||||
Reference in New Issue
Block a user