infile = open(manifest_file,'rb') # Skip the first line, but instead write it to the output file. filedata = next(infile) # where the result csv goes. Put in this dir for now. outfilename = "WBTV_read.csv" outfile = open(outfilename, 'w') # write the file data row to the first line of the output file outfile.write(filedata) reader = csv.DictReader(infile) dataheaders = reader.fieldnames parser = atomic_line_parser(line_captures_current) oldparser = atomic_line_parser(line_captures_2013ish) field_names = parser.get_keys(dataheaders) outfile.write(",".join(field_names) +"\n") dw = csv.DictWriter(outfile, fieldnames=field_names, restval='', extrasaction='ignore') for row in reader: #print row filename = "../../" + row['txt_location'] fileid = row['fcc_id'] intid = int(fileid) # there are two styles of forms -- this is adjusted on a case-by-case basis if ( intid < 14037030612510 or intid in [14037241509178, 14037241836964, 14037237369948, 14037241958930, 14037960869016, 14037956506019] ): result = oldparser.process_file(filename, row)
# where the data on the files is manifest_file = "../../manifest_files/KMGH-TV.csv" infile = open(manifest_file, 'rb') # Skip the first line, but instead write it to the output file. filedata = next(infile) # where the result csv goes. Put in this dir for now. outfilename = "KMGH_read.csv" outfile = open(outfilename, 'w') # write the file data row to the first line of the output file outfile.write('"' + filedata + '"' + "\n") reader = csv.DictReader(infile) dataheaders = reader.fieldnames parser = atomic_line_parser(line_captures_current) field_names = parser.get_keys(dataheaders) outfile.write(",".join(field_names) + "\n") dw = csv.DictWriter(outfile, fieldnames=field_names, restval='', extrasaction='ignore') for row in reader: filename = "../../" + row['txt_location'] result = parser.process_file(filename, row) dw.writerow(result) print result
from capture_formats import line_captures_current # where the data on the files is manifest_file = "../../manifest_files/KKTV.csv" infile = open(manifest_file,'rb') # Skip the first line, but instead write it to the output file. filedata = next(infile) # where the result csv goes. Put in this dir for now. outfilename = "KKTV_read.csv" outfile = open(outfilename, 'w') # write the file data row to the first line of the output file outfile.write('"' + filedata + '"' + "\n") reader = csv.DictReader(infile) dataheaders = reader.fieldnames parser = atomic_line_parser(line_captures_current) field_names = parser.get_keys(dataheaders) outfile.write(",".join(field_names) +"\n") dw = csv.DictWriter(outfile, fieldnames=field_names, restval='', extrasaction='ignore') for row in reader: filename = "../../" + row['txt_location'] result = parser.process_file(filename, row) dw.writerow(result) print result
manifest_file = "../../manifest_files/WBTV.csv" infile = open(manifest_file, 'rb') # Skip the first line, but instead write it to the output file. filedata = next(infile) # where the result csv goes. Put in this dir for now. outfilename = "WBTV_read.csv" outfile = open(outfilename, 'w') # write the file data row to the first line of the output file outfile.write(filedata) reader = csv.DictReader(infile) dataheaders = reader.fieldnames parser = atomic_line_parser(line_captures_current) oldparser = atomic_line_parser(line_captures_2013ish) field_names = parser.get_keys(dataheaders) outfile.write(",".join(field_names) + "\n") dw = csv.DictWriter(outfile, fieldnames=field_names, restval='', extrasaction='ignore') for row in reader: #print row filename = "../../" + row['txt_location'] fileid = row['fcc_id'] intid = int(fileid)