Skip to content

Commit

Permalink
#66 cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Jul 4, 2017
1 parent 89afdb8 commit ff2f72e
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions analyzers/Hippocampe/hippo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,39 @@ def __init__(self):
self.url = self.getParam('config.url', None, 'Missing URL for Hippocampe API')
self.service = self.getParam('config.service', None, 'Service parameter is missing')

def moreSummary(self, raw):
def more_summary(self, raw):
data = self.getData()
result = {}
result[data] = 0

if(data in raw):
result[data] = len(raw[data])
if data in raw:
result[data] = len(raw.get(data))

return result

def scoreSummary(self, raw):
def score_summary(self, raw):
data = self.getData()
result = {}
if(data in raw):
result[data] = raw[data]["hipposcore"]

if data in raw:
result[data] = raw.get(data).get("hipposcore")
return result

def summary(self, raw):
taxonomy = {"level": "safe", "namespace": "Hippocampe", "predicate": "Score", "value": 0}
taxonomies = []
level = "safe"
namespace = "Hippocampe"
predicate = "Score"
value = "\"0 record\""


if (self.service == 'hipposcore'):
r = self.scoreSummary(raw).get("data")
value = r
if r > 0:
level = "malicious"
taxonomies.append(taxonomy)
elif (self.service == 'more'):
r = self.moreSummary(raw).get("data", 0)
value = "\"{} record(s)\"".format(r)
if r > 0:
if self.service == 'hipposcore':
value = self.score_summary(raw)[self.getData()]
if value > 0:
level = "malicious"
taxonomies.append(self.build_taxonomy(level, namespace, predicate, value))
elif self.service == 'more':
value = self.more_summary(raw)[self.getData()]
if value > 0:
level = "malicious"
taxonomies.append(self.build_taxonomy(level, namespace, predicate, "\"{} record(s)\"".format(value)))

return {"taxonomies": taxonomies}

Expand All @@ -69,7 +63,6 @@ def run(self):
post_data = json_data.encode('utf-8')
headers = {'Content-Type': 'application/json'}

response = {}
try:
request = urllib2.Request('{}/hippocampe/api/v1.0/{}'.format(self.url, self.service), post_data, headers)
response = urllib2.urlopen(request)
Expand Down

0 comments on commit ff2f72e

Please sign in to comment.