2 回答

TA贡献1909条经验 获得超7个赞
您实际上需要将这些函数称为我的兄弟
def my_func(stuff):
print(stuff) #or whatever
my_func(1234)
每条评论更新
import os
p=r'path\to\your\files'
filelist=os.listdir(p) #creates list of all files/folders in this dir
#make a loop for each file in the dir
for file in filelist:
f=os.path.join(p,file) #this just joins the file name and path for full file path
your_func(f) #here you can pass the full file name to your functions

TA贡献1880条经验 获得超4个赞
如前所述,当前的问题似乎是您根本不调用cert_check
函数。但是,尽管此站点实际上不用于代码审查,但我不禁建议对您的代码进行一些改进。特别是,所有这些try/except:pass
构造都使得检测代码中的任何错误变得异常困难,因为所有异常只会被静默捕获和吞噬except: pass
。
您应该删除所有这些
try/except:pass
块,尤其是围绕整个功能主体的那个块如果某些键不存在,则可以使用
dict.get
代替代替[]
,这不会引发键错误,而是返回None
(或一些默认值),并且所有检查仍然可以进行您可以使用
|=
而不是if
检查来or
检查变量的结果您可以
any
用来检查某个列表中的任何元素是否满足某些条件
我的vt_result_check
函数版本:
def vt_result_check(vt_result_path):
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)
# Look for any positive detected referrer samples
# Look for any positive detected communicating samples
# Look for any positive detected downloaded samples
# Look for any positive detected URLs
sample_types = ('detected_referrer_samples', 'detected_communicating_samples',
'detected_downloaded_samples', 'detected_urls')
vt_result |= any(sample['positives'] > 0 for sample_type in sample_types
for sample in vt_data.get(sample_type, []))
# Look for a Dr. Web category of known infection source
vt_result |= vt_data.get('Dr.Web category') == "known infection source"
# Look for a Forecepoint ThreatSeeker category of elevated exposure
# Look for a Forecepoint ThreatSeeker category of phishing and other frauds
# Look for a Forecepoint ThreatSeeker category of suspicious content
threats = ("elevated exposure", "phishing and other frauds", "suspicious content")
vt_result |= vt_data.get('Forcepoint ThreatSeeker category') in threats
return vt_result
添加回答
举报