Welcome Guest [Log In] [Register]
Viewing Single Post From: Aca Cons In Digital Format
rot13
Elite member
[ *  *  *  *  * ]
Here is a python script I use to split the file up. Sometimes I have to edit the file first, though. It expects there to be a blank line between cons, and nowhere else, and it expects the first line of the con to be its title. I run it with:
python splitter.py confilename condirectory

So for this month, I did:
python splitter.py so06.txt so06

and it put all the cons into separate files in the so06 directory with names like so06a1, so06psp1, etc.

Code:
 

import sys
import re
import os
import os.path

infile = file(sys.argv[1],"r")
refilename = re.compile(r'[^a-z0-9]')

if not os.path.exists(sys.argv[2]):
       os.mkdir(sys.argv[2])

while 1:
       line = infile.readline()
       if not line: break

       line = line.strip()
       if not line: continue

       filename = refilename.sub('', line.lower())

       outfile = file(sys.argv[2]+"/"+sys.argv[2]+filename, "w")
       while 1:
               line = infile.readline()
               line = line.strip();
               if not line: break

               if (line[-1] == '-'):
                       outfile.write(line[0:-1])
               else:
                       outfile.write(line+"\n")

       outfile.close()
infile.close()
Offline Profile Quote Post
Aca Cons In Digital Format · News