changeset 27:f27ddfa42e94

try/catch; From/To/-ESN changes; google probs
author Mathias Gebbe <mgebbe@intevation.de>
date Sat, 28 Jun 2014 13:08:40 +0200
parents cdbc77880565
children faeb3b96bdeb
files src/app.coffee src/facebook.coffee src/google.coffee src/syncALONE.coffee src/twitter.coffee
diffstat 5 files changed, 39 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/app.coffee	Tue Jun 24 08:32:51 2014 +0200
+++ b/src/app.coffee	Sat Jun 28 13:08:40 2014 +0200
@@ -38,7 +38,7 @@
         # Start Deamon!
         # or comment to the next hashtag after ')' and use
         # Sync.sync()
-        # or start coffee syncALONE.coffee in a different window
+        # or (best) start coffee syncALONE.coffee in a different shell
         exec = require("child_process").exec
         child = undefined
         child = exec("coffee syncALONE.coffee", (error, stdout, stderr) ->
--- a/src/facebook.coffee	Tue Jun 24 08:32:51 2014 +0200
+++ b/src/facebook.coffee	Sat Jun 28 13:08:40 2014 +0200
@@ -336,13 +336,16 @@
       callback null, null
 
     newposts = new Array()
-    async.each res.data, ((post,cb) ->
-      newposts.push(post) if (post.type is 'status' or post.type is 'photo' or post.type is 'link' or post.type is 'video') and (post.status_type is 'mobile_status_update' or post.status_type is 'added_photos' or post.status_type is 'shared_story')
-      cb()
-      return
-    ), (err) ->
-      callback null, newposts.reverse()
-      return
+
+    if res.data?
+      async.each res.data, ((post,cb) ->
+        if (post.type is 'status' or post.type is 'photo' or post.type is 'link' or post.type is 'video') and (post.status_type is 'mobile_status_update' or post.status_type is 'added_photos' or post.status_type is 'shared_story')
+          newposts.push(post)
+        cb()
+      ), (err) ->
+        callback null, newposts.reverse()
+    else
+      callback null,null
   return
 
 #######################################
--- a/src/google.coffee	Tue Jun 24 08:32:51 2014 +0200
+++ b/src/google.coffee	Sat Jun 28 13:08:40 2014 +0200
@@ -52,16 +52,18 @@
           async.eachLimit stream.items, 10, ((post, cb) ->
             async.waterfall [
               (callback) ->
-                console.log "check googlepost "+ post.id
+                console.log "check googlepost " + post.id + " to " +  me
                 FromESN.search {uid: post.id + "@google_to_" + me}, callback
               (result, callback) ->
-                return if result.length isnt 0
-                ti = new Date().getTime() - interval
-                ts = Date.parse(post.published)
-                if (ts >= ti)
+                if result.length isnt 0
+                  return
+                else
                   Sync.postParser post, null, 'google', callback
-                else
-                  return
+                #ti = new Date().getTime() - interval
+                #ts = Date.parse(post.published)
+                #if (ts >= ti)
+                #else
+                #  return
               (parsed, callback) ->
                 console.log "post googlepost "+ post.id
                 Pump.postUser bridgeid, me, parsed, callback
--- a/src/syncALONE.coffee	Tue Jun 24 08:32:51 2014 +0200
+++ b/src/syncALONE.coffee	Sat Jun 28 13:08:40 2014 +0200
@@ -33,7 +33,7 @@
         Facebook.sync(user)
     ), (err) ->
   catch err
-    console.log 'Error!' + err
+    console.log 'Facebook Error!' + err
 
   # Twitter
   try
@@ -44,7 +44,7 @@
         Twitter.syncFromESN(user)
     ), (err) ->
   catch err
-    console.log 'Error!' + err
+    console.log 'Twitter Error!' + err
 
   # Google
   try
@@ -54,7 +54,7 @@
         Google.sync(user)
     ), (err) ->
   catch err
-    console.log 'Error!' + err
+    console.log 'Google Error!' + err
   ####
 
   return
@@ -73,7 +73,6 @@
   ], (err, result) ->
     setInterval syncFromESN, interval
     syncFromESN()
-
   return
 
 sync()
--- a/src/twitter.coffee	Tue Jun 24 08:32:51 2014 +0200
+++ b/src/twitter.coffee	Sat Jun 28 13:08:40 2014 +0200
@@ -91,7 +91,7 @@
 
       return
 
-    syncFromESN: (user) ->
+    syncToESN: (user) ->
       me = user.user_pumpio
       id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
       token = user.oauth_token
@@ -159,7 +159,7 @@
         return
       return
 
-    syncToESN: (user) ->
+    syncFromESN: (user) ->
       me = user.user_pumpio
       id = user.user_ESN.substr(0,user.user_ESN.indexOf('@'))
       token = user.oauth_token
@@ -177,15 +177,18 @@
         #console.log util.inspect(data)
         console.log "get twitter HomeTimeline " + me
         return
-      ).getHomeTimeline {include_rts: true, count: 20 }, (data) ->
+      ).getHomeTimeline {include_rts: true, count: 10 }, (data) ->
+        console.log "got twitter HomeTimeline " + me
+        return if not data? or data.length is 0
+        console.log "data isnt empty for" + me
         ti = (new Date().getTime() - interval)
-        return if not data? or data.length is 0
-        async.eachLimit data, 10, ((tweet, cb) ->
+        async.eachLimit data, 5, ((tweet, cb) ->
           async.waterfall [
             (callback) ->
               FromESN.search {uid: tweet.id + "@twitter_to_" + me}, callback
             (result, callback) ->
               return if result.length isnt 0 or tweet.user.id_str is id
+              console.log "new tweet found"
               twitterdate = new Date(Date.parse(tweet.created_at.replace(/( +)/, " UTC$1")))
               ts = Date.parse(twitterdate)
               if (ts >= ti)
@@ -193,9 +196,14 @@
               else
                 return
             (parsed, callback) ->
+              console.log "try to post new tweet"
               Pump.postUser bridgeid, me, parsed, callback
             (pumppost, callback) ->
-              pumppost = JSON.parse(pumppost)
+              try
+                pumppost = JSON.parse(pumppost)
+              catch err
+                console.log "parse err " + err
+                return
               FromESN.create
                 postid: tweet.id + "@twitter"
                 sourceUser: tweet.user.id
@@ -205,14 +213,13 @@
                 created: Date.now()
               , callback
           ], (err, result) ->
+            console.log "post a tweet to user" + me
             cb()
-          return
         ), (err) ->
           if (err)
             console.log "Error: " + err
           else
-            console.log "done ToESN twitter user" + me
-          return
+            console.log "done FromESN twitter user" + me
       return
 
     getOAuth: (site) ->
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)