Skip to content

Instantly share code, notes, and snippets.

@nattybear
Created December 18, 2016 14:26
Show Gist options
  • Save nattybear/368111e404030ba4d7f4d33629bdf6ab to your computer and use it in GitHub Desktop.
Save nattybear/368111e404030ba4d7f4d33629bdf6ab to your computer and use it in GitHub Desktop.
from sys import argv, exit
from StringIO import StringIO
if len(argv) != 2:
print 'Usage:', argv[0], '<txt>'
exit()
txt = argv[1]
new = txt.split('.')[0] + '.csv'
fp1 = open(txt, 'rb')
fp2 = open(new, 'wb')
buf1 = fp1.read()
buf2 = buf1.replace('\r\n ', ' ')
s = StringIO(buf2)
s.seek(0)
s.readline()
s.readline()
cnt = 0
while True:
t = []
t1 = s.readline()
if len(t1) == 0: break
t2 = t1.split(' ')
dir = t2[0]
if dir[0] != '/': dir = '/' + dir
dir = txt.split('.')[0] + dir
t.append(dir)
filename = dir.split('/')[-1]
t.append(filename)
t.append(str(cnt))
cnt = cnt + 1
if len(t2) > 4: t.append('compress')
else: t.append('uncompress')
fp2.write(','.join(t) + b'\x0d\x0a')
print '[*]', new, 'saved'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment