我正在自动执行涉及电子表格漏洞的长任务。但是,我注意到这些漏洞的“建议”有时很长。
用于python的CSV模块似乎在编写新行时截断了部分文本。有没有办法防止这种情况发生?我只是在推荐(很多文字)的地方看到“注意:这个领域已被截止”。
答案 0 :(得分:0)
整个目标是这样做:
我注意到的是,即使在Ruby中出于某种原因,这些漏洞中的一些建议也有长篇文章;因此,当出于某种原因创建CSV文件时,它会被截断。这是我为了演示而快速编写的代码示例:
#!/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()