You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2017/12/07 10:36:26 UTC
[kibble-scanners] 02/03: get ponymail-tone scanner to work with lib
changes
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git
commit d49c1e798f3d51da1a9ac614362846ccd3e42f3d
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Thu Dec 7 11:35:50 2017 +0100
get ponymail-tone scanner to work with lib changes
grab all bodies, array them up, then scan them all at once
---
src/plugins/scanners/ponymail-tone.py | 49 +++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 17 deletions(-)
diff --git a/src/plugins/scanners/ponymail-tone.py b/src/plugins/scanners/ponymail-tone.py
index c027a84..aae54a4 100644
--- a/src/plugins/scanners/ponymail-tone.py
+++ b/src/plugins/scanners/ponymail-tone.py
@@ -94,6 +94,7 @@ def scan(KibbleBit, source):
size = 1
)
ec = 0
+ hits = []
for hit in res['hits']['hits']:
eml = hit['_source']
if not re.search(ROBITS, eml['sender']):
@@ -106,23 +107,37 @@ def scan(KibbleBit, source):
rv = None
try:
rv = plugins.utils.jsonapi.get(emlurl, cookie = cookie)
+ if rv and 'body' in rv:
+ hits.append([hit['_id'],rv['body'], eml])
except Exception as err:
KibbleBit.pprint("Server error, skipping this email")
- if rv and 'body' in rv:
- body = rv['body']
- KibbleBit.pprint("analyzing email")
- if 'watson' in KibbleBit.config:
- mood = plugins.utils.tone.watsonTone(KibbleBit, body)
- elif 'azure' in KibbleBit.config:
- mood = plugins.utils.tone.azureTone(KibbleBit, body)
- if mood == False:
- KibbleBit.pprint("Hit Azure rate limit, not trying further emails for now.")
- break
- eml['mood'] = mood
- hm = [0,'unknown']
- for m, s in mood.items():
- if s > hm[0]:
- hm = [s,m]
- print("Likeliest overall mood: %s" % hm[1])
- KibbleBit.index('email', hit['_id'], eml)
+
+ bodies = []
+ for hit in hits:
+ body = hit[1]
+ bid = hit[0]
+ bodies.append(body)
+ if bodies:
+ if 'watson' in KibbleBit.config:
+ moods = plugins.utils.tone.watsonTone(KibbleBit, bodies)
+ elif 'azure' in KibbleBit.config:
+ moods = plugins.utils.tone.azureTone(KibbleBit, bodies)
+ if moods == False:
+ KibbleBit.pprint("Hit rate limit, not trying further emails for now.")
+
+ a = 0
+ for hit in hits:
+ mood = moods[a]
+ bid = hit[0]
+ eml = hit[2]
+ a += 1
+ eml['mood'] = mood
+ hm = [0,'unknown']
+ for m, s in mood.items():
+ if s > hm[0]:
+ hm = [s,m]
+ print("Likeliest overall mood for %s: %s" % (bid, hm[1]))
+ KibbleBit.index('email', bid, eml)
+ else:
+ KibbleBit.pprint("No emails to analyze")
KibbleBit.pprint("Done with tone analysis")
--
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.