简体   繁体   中英

Great CSV module for python?

I'm automating a long task that involves vulnerabilities within a spreadsheet. However, I'm noticing that the "recommendation" for these vulnerabilities are sometimes pretty long.

The CSV module for python seems to be truncating some of this text when writing new rows. Is there any way to prevent this from happening? I simply see "NOTE: THIS FIELD WAS TRUNCATED" in places where the recommendation (which is a lot of text) would be.

The whole objective is to do this:

  1. Import a master spreadsheet which has confirmation statuses and everything up-to-date
  2. Take a new spreadsheet containing vulnerabilities which doesn't have conf status/severity up-to-date.
  3. Compare the second spreadsheet to the first. It'll update the severity levels from the second spreadsheet, and then write to a new file.
  4. Newly created csv file can be copied and pasted into master spreadsheet. All vulnerabilities which match the first spreadsheet now have the same severity level/confirmation status.

What I'm noticing though, even in Ruby for some reason, is that some of the recommendations in these vulnerabilities have long text; therefore, it's being truncated when the CSV file is created for some reason. Here's a sample piece of the code that I've quickly written for demonstration:

#!/usr/bin/python
from sys import argv
import getopt, csv

master_vulns = {}
criticality = {}

############################ Extracting unique vulnerabilities from master file
contents = csv.reader(open(argv[1], 'rb'), delimiter=',')

for row in contents:
    if "Confirmation_Status" in row:
        continue
    try:
        if row[7] in master_vulns:
            continue
        if row[7] in master_vulns:
            continue
        master_vulns[row[7]] = row[3]
        criticality[rows[7]] = row[2]
    except Exception:
        pass

############################ Updating confirmation status of newly created file
new_contents = csv.reader(open(argv[1], 'rb'), delimiter=',')
new_data = []
results = open('results.csv','wb')
writer = csv.writer(results, delimiter=',')

for nrow in new_contents:
    if "Confirmation_Status" in nrow:
        continue
    try:
        if nrow[1] == "DELETE":
            continue
        vuln_name = nrow[7]
        vuln_status = nrow[3]
        criticality = criticality[vuln_name]
        vuln_status = master_vulns[vuln_name]
        nrow[3] = vuln_status
        nrow[2] = criticality
        writer.writerow(nrow)
    except Exception:
        writer.writerow(nrow)
        pass

results.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM