#!/usr/bin/python
from csv import reader
import csv,re, sys, getopt
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print 'convert.py -i <inputfile> -o <outputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'convert.py -i <inputfile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
print 'Input file is ', inputfile
print 'Output file is ', outputfile
regex = re.compile(r"\s*\b(?!href|src)[^\s]+=\"[^\"]*\"(?=[^<>]*>)", re.IGNORECASE)
with open(inputfile, 'r') as read_obj, open(outputfile, 'wb') as write_obj:
csv_reader = reader(read_obj, quoting=csv.QUOTE_MINIMAL, delimiter=',', quotechar='"', skipinitialspace=True, lineterminator = '\r\n')
writer = csv.writer(write_obj, quoting=csv.QUOTE_NONNUMERIC, delimiter=',', quotechar='"', skipinitialspace=True)
for row in csv_reader:
row.append(regex.sub(r"", row[2]))
writer.writerow(row)
if __name__ == "__main__":
main(sys.argv[1:])