我有一个python脚本,试图在其中读取目录中的所有.txt文件,并确定它们是否针对脚本中的任何条件返回True或False。我没有收到错误消息,但脚本未产生任何输出。我希望脚本读取包含以.json格式格式化的文本的.txt文件。然后,我希望脚本确定.txt文件是否与下面我的代码中的任何语句匹配。然后,我想将结果输出到一个csv文件。非常感激你的帮助!
#!/usr/bin/env python
# regarding whether any positive results were found for the domain on VT.
import csv
import json
import pprint
import sys
import os
CSVPATH = 'CsvResults.csv'
VTOUTPUTPATH = './output/'
VTOUTPUTEXT = '.txt'
#files_to_search = [f for f in os.listdir('./output/') if f[-4:] == '.txt']
#vt_result_path = files_to_search
#vt_result = vt_result_check(vt_result_path)
pp = pprint.PrettyPrinter(indent=4)
# Check files from VirusTotal queries for any positive results
# Result is false unless any nonzero positive result is true
def vt_result_check(vt_result_path):
vt_result = None
try:
vt_result = False
for filename in os.listdir(path):
with open(filename, 'r', encoding='utf-16') as vt_result_file:
vt_data = json.load(vt_result_file)
#vt_result_path = [f for f in os.listdir('./output/') if f[-4:] == '.txt']
#vt_result = None
#try:
# vt_result = False
# with open(infile) as vt_result_file:
# vt_data = json.load(vt_result_file)
# Look for any positive detected referrer samples
try:
for sample in (vt_data['detected_referrer_samples']):
if (sample['positives'] > 0):
vt_result = True
except:
pass
# Look for any positive detected communicating samples
try:
for sample in (vt_data['detected_communicating_samples']):
if (sample['positives'] > 0):
vt_result = True
except:
pass
jeck猫
慕村225694
相关分类