$ python app.py [filename]
Created
February 28, 2019 21:58
-
-
Save shohei/ab1e7b1af5a47c35e37f1a8f7ce20552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
if len(sys.argv) < 2: | |
print("Error: file name not given") | |
print("Usage: python app.py [filename]") | |
exit() | |
g0pattern = r"^G0.*" | |
g1pattern = r"^G1.*" | |
g0re = re.compile(g0pattern) | |
g1re = re.compile(g1pattern) | |
Xpattern = r".*X[-\.\d]+" | |
Ypattern = r".*Y[-\.\d]+" | |
Zpattern = r".*Z[-\.\d]+" | |
Xre = re.compile(Xpattern) | |
Yre = re.compile(Ypattern) | |
Zre = re.compile(Zpattern) | |
currentX = 0 | |
currentY = 0 | |
currentZ = 0 | |
fout = open('out.csv','w') | |
should_update = False | |
filename = sys.argv[1] | |
with open(filename) as f: | |
lines = f.readlines() | |
for line in lines: | |
if Xre.match(line): | |
should_update = True | |
nextX = re.findall(Xpattern,line)[0].split('X')[1] | |
if currentX != nextX: | |
currentX = nextX | |
if Yre.match(line): | |
should_update = True | |
nextY = re.findall(Ypattern,line)[0].split('Y')[1] | |
if currentY != nextY: | |
currentY = nextY | |
if Zre.match(line): | |
should_update = True | |
nextZ = re.findall(Zpattern,line)[0].split('Z')[1] | |
if currentZ != nextZ: | |
currentZ = nextZ | |
if should_update: | |
fout.write("{0},{1},{2}\n".format(currentX,currentY,currentZ)) | |
should_update = False | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment