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/10/24 12:07:45 UTC

[kibble-scanners] 01/02: some lists require credentials

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 b1a142f1272bf29e67fbc7c9fbcd6a301717e9d6
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Tue Oct 24 14:07:24 2017 +0200

    some lists require credentials
    
    also switch to the json plugin for fetching data, since that
    handles cookies already
---
 src/plugins/scanners/ponymail-tone.py | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/src/plugins/scanners/ponymail-tone.py b/src/plugins/scanners/ponymail-tone.py
index 69f7623..e6ffaa6 100644
--- a/src/plugins/scanners/ponymail-tone.py
+++ b/src/plugins/scanners/ponymail-tone.py
@@ -65,6 +65,10 @@ def scan(KibbleBit, source):
         KibbleBit.pprint("No Watson/BlueMix creds configured, skipping tone analyzer")
         return
     
+    cookie = None
+    if 'creds' in source and source['creds']:
+        cookie = source['creds'].get('cookie', None)
+        
     rootURL = re.sub(r"list.html.+", "", source['sourceURL'])
     query = {
             'query': {
@@ -98,15 +102,20 @@ def scan(KibbleBit, source):
             if 'mood' not in eml:
                 emlurl = "%s/api/email.lua?id=%s" % (rootURL, eml['id'])
                 KibbleBit.pprint("Fetching %s" % emlurl)
-                rv = requests.get(emlurl).json()
-                body = rv['body']
-                KibbleBit.pprint("analyzing email")
-                mood = plugins.utils.tone.getTone(KibbleBit, body)
-                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)
+                rv = None
+                try:
+                    rv = plugins.utils.jsonapi.get(emlurl, cookie = cookie)
+                except Exception as err:
+                    KibbleBit.pprint("Server error, skipping this email")
+                if rv and 'body' in rv:
+                    body = rv['body']
+                    KibbleBit.pprint("analyzing email")
+                    mood = plugins.utils.tone.getTone(KibbleBit, body)
+                    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)
     KibbleBit.pprint("Done with tone analysis")

-- 
To stop receiving notification emails like this one, please contact
"commits@kibble.apache.org" <co...@kibble.apache.org>.