diff src/twitter.coffee @ 7:2123f355ab68

go back interval or 15 min, delete credentials, layout
author Mathias Gebbe <mgebbe@intevation.de>
date Wed, 11 Jun 2014 02:32:53 +0200
parents af9f5b94c019
children 6fd0a307850f
line wrap: on
line diff
--- a/src/twitter.coffee	Sat Jun 07 10:22:12 2014 +0200
+++ b/src/twitter.coffee	Wed Jun 11 02:32:53 2014 +0200
@@ -33,6 +33,9 @@
   bridgeid = config.bridgeid
   client_id = config.twclient_id
   client_secret = config.twclient_secret
+  interval = config.interval
+  if not (interval?)
+    interval =  15 * 60 * 1000
   request_token_endpoint = "https://api.twitter.com/oauth/request_token"
   access_token_endpoint = "https://api.twitter.com/oauth/access_token"
   authorization_endpoint = "https://api.twitter.com/oauth/authorize"
@@ -107,18 +110,22 @@
         (user, callback) ->
           Pump.getUserFeed(user[0],callback)
         (feed, callback) ->
+          ti = new Date().getTime() - interval
           async.eachSeries feed.items, ((post, callback) ->
             # do for each post
-            if (post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and (typeof post.object.deleted is "undefined")
+            ts = Date.parse(post.updated)
+            if (ts >= ti and post.verb is "post" or post.verb is "share") and (post.object.objectType is "note" or post.object.objectType is "image") and (Pump.isPublicActivity(post)) and (typeof post.object.deleted is "undefined")
               ToESN.search {uid: post.object.id + "@twitter"}, (err, result) ->
                 if result.length is 0
                   # post to twitter
+                  status = ""
                   text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
-                  status = ""
+                  if post.verb is "share"
+                    status = post.object.author.url + " wrotes: "
                   if text.length <= 140
-                    status = text
+                    status += text
                   else
-                    status = text.substr(0, 140 - (post.object.url.length + 2)) + ".." + post.object.url
+                    status += text.substr(0, 140 - (post.object.url.length + 2)) + ".." + post.object.url
                   twit.verifyCredentials((data) ->
                     #console.log util.inspect(data)
                     return
@@ -148,15 +155,20 @@
       twit.verifyCredentials((data) ->
         #console.log util.inspect(data)
         return
-      ).getHomeTimeline {include_rts: false}, (data) ->
+      ).getHomeTimeline {include_rts: true, count: 20 }, (data) ->
         #console.log util.inspect(data)
+        ti = (new Date().getTime() - interval)
         _.each data, (tweet) ->
           async.waterfall [
             (callback) ->
               FromESN.search {uid: tweet.id + "@twitter_to_" + me, recipientUser: me}, callback
             (result, callback) ->
-              return if result.length isnt 0 or tweet.user.id == id
-              Sync.postParser tweet, null, 'twitter', callback
+              return if result.length isnt 0 or tweet.user.id_str is id
+              twitterdate = new Date(Date.parse(tweet.created_at.replace(/( +)/, " UTC$1")))
+              ts = Date.parse(twitterdate)
+              if (ts >= ti)
+                Sync.postParser tweet, null, 'twitter', callback
+              return
             (parsed, callback) ->
               Pump.postUser bridgeid, me, parsed, callback
             (pumppost, callback) ->
@@ -176,7 +188,9 @@
       return
 
       return
-  
+ 
+    parseTwitterDate : (text) ->
+
     getOAuth: (site) ->
       new OAuth(request_token_endpoint, access_token_endpoint, client_id, client_secret, "1.0", site.url("/authorized-for-twitter"), "HMAC-SHA1", null, # nonce size; use default
         "User-Agent": site.userAgent()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)