changeset 28:faeb3b96bdeb

use html-to-text
author Mathias Gebbe <mgebbe@intevation.de>
date Tue, 29 Jul 2014 12:14:02 +0200
parents f27ddfa42e94
children 34cfa565f565
files INSTALL.md index.js_to_pump.io-client-app_lib_routes package.json src/app.coffee src/google.coffee src/restartSYNC.sh src/twitter.coffee
diffstat 7 files changed, 35 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/INSTALL.md	Sat Jun 28 13:08:40 2014 +0200
+++ b/INSTALL.md	Tue Jul 29 12:14:02 2014 +0200
@@ -19,6 +19,7 @@
 ```
 cp app.js_to_pump.io-client-app_lib node_modules/pump.io-client-app/lib/app.js
 cp index.js_to_pump.io-client-app_lib_routes node_modules/pump.io-client-app/lib/routes/index.js
+mkdir -p lib/ && coffee -b -c -o lib/ src/*.coffee
 ```
 
 * configure your Facebook App ID and your Google App ID in
--- a/index.js_to_pump.io-client-app_lib_routes	Sat Jun 28 13:08:40 2014 +0200
+++ b/index.js_to_pump.io-client-app_lib_routes	Tue Jul 29 12:14:02 2014 +0200
@@ -22,7 +22,7 @@
     uuid = require("node-uuid"),
     User = require("../models/user"),
     Host = require("../models/host"),
-    Usermap = require("../../../../src/usermap"),
+    Usermap = require("../../../../lib/usermap"),
     RequestToken = require("../models/requesttoken"),
     RememberMe = require("../models/rememberme"),
     site = require("../models/site");
--- a/package.json	Sat Jun 28 13:08:40 2014 +0200
+++ b/package.json	Tue Jul 29 12:14:02 2014 +0200
@@ -13,6 +13,7 @@
         "oauth": "0.9.x",
         "async": "0.2.x",
         "node-uuid": "1.4.x",
+        "html-to-text": "0.1.0",
         "validator": "1.5.x",
         "set-immediate": "0.1.x"
     },
--- a/src/app.coffee	Sat Jun 28 13:08:40 2014 +0200
+++ b/src/app.coffee	Tue Jul 29 12:14:02 2014 +0200
@@ -38,15 +38,15 @@
         # Start Deamon!
         # or comment to the next hashtag after ')' and use
         # Sync.sync()
-        # 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) ->
-          console.log "stdout: " + stdout
-          console.log "stderr: " + stderr
-          console.log "exec error: " + error  if error isnt null
-          return
-        )
+        # or start coffee syncALONE.coffee in a different window
+        #exec = require("child_process").exec
+        #child = undefined
+        #child = exec("coffee syncALONE.coffee", (error, stdout, stderr) ->
+        #  console.log "stdout: " + stdout
+        #  console.log "stderr: " + stderr
+        #  console.log "exec error: " + error  if error isnt null
+        #  return
+        #)
         #
 
       return
--- a/src/google.coffee	Sat Jun 28 13:08:40 2014 +0200
+++ b/src/google.coffee	Tue Jul 29 12:14:02 2014 +0200
@@ -43,13 +43,13 @@
       #getUser(user)
       getFriends(user,callback)
   ], (err, friends) ->
-    async.eachLimit friends, 3, ((friend, callb) ->
+    async.eachLimit friends, 2, ((friend, callb) ->
       async.waterfall [
         (callback) ->
           getStream(user, friend, callback)
         (stream, callback) ->
           return if not stream? or not stream.items? or stream.items.length is 0
-          async.eachLimit stream.items, 10, ((post, cb) ->
+          async.eachLimit stream.items, 2, ((post, cb) ->
             async.waterfall [
               (callback) ->
                 console.log "check googlepost " + post.id + " to " +  me
@@ -81,20 +81,16 @@
                  #console.log err
                  console.log "done"
                  cb()
-                 return
           ), (err) ->
             callb()
-            return
       ], (err,  result) ->
     ), (err) ->
       if err
         console.log 'one post fail to process'
       else
         console.log 'all google friends processed'
-      return
   return
 
-
 #######################################
 ###### get user info googleplus  ######
 #######################################
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/restartSYNC.sh	Tue Jul 29 12:14:02 2014 +0200
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+cd /home/pumpbridge/pumpbridge/src
+
+until coffee syncALONE.coffee; do
+    echo "sync crashed with exit code $?. Respawning.." >&2
+    sleep 1
+done
--- a/src/twitter.coffee	Sat Jun 28 13:08:40 2014 +0200
+++ b/src/twitter.coffee	Tue Jul 29 12:14:02 2014 +0200
@@ -29,6 +29,7 @@
 ToESN = require("./toESN")
 Sync = require("./sync")
 util = require("util")
+htmlToText = require('html-to-text')
 twitter = require("twitter")
 
 module.exports = (config) ->
@@ -116,7 +117,7 @@
         (feed, callback) ->
           return if not feed?
           ti = new Date().getTime() - interval
-          async.eachLimit feed.items, 10, ((post, callback) ->
+          async.eachLimit feed.items, 5, ((post, callback) ->
             # do for each post
             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")
@@ -124,9 +125,11 @@
                 if result.length is 0
                   # post to twitter
                   status = ""
-                  text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
-                  re = new RegExp(String.fromCharCode(160), "g")
-                  text = text.replace(re, " ")
+                  text = post.object.content
+                  text = htmlToText.fromString(text,wordwrap: 140)
+                  #text = post.object.content.replace(/<(?:.|\n)*?>/gm, '')
+                  #re = new RegExp(String.fromCharCode(160), "g")
+                  #text = text.replace(re, " ")
                   if post.verb is "share"
                     status = post.object.author.url + " writes: "
                   if text.length <= 140
@@ -155,7 +158,7 @@
           ), (err) ->
             callback null, 'done'
       ],(err, result) ->
-        console.log "done ToESN twitter user" + me
+        console.log "done ToESN twitter user " + me
         return
       return
 
@@ -177,12 +180,12 @@
         #console.log util.inspect(data)
         console.log "get twitter HomeTimeline " + me
         return
-      ).getHomeTimeline {include_rts: true, count: 10 }, (data) ->
+      ).getHomeTimeline {include_rts: true, count: 15 }, (data) ->
         console.log "got twitter HomeTimeline " + me
         return if not data? or data.length is 0
-        console.log "data isnt empty for" + me
+        console.log "data isnt empty for " + me
         ti = (new Date().getTime() - interval)
-        async.eachLimit data, 5, ((tweet, cb) ->
+        async.eachLimit data, 1, ((tweet, cb) ->
           async.waterfall [
             (callback) ->
               FromESN.search {uid: tweet.id + "@twitter_to_" + me}, callback
@@ -213,13 +216,13 @@
                 created: Date.now()
               , callback
           ], (err, result) ->
-            console.log "post a tweet to user" + me
+            console.log "post a tweet to user " + me
             cb()
         ), (err) ->
           if (err)
             console.log "Error: " + err
           else
-            console.log "done FromESN twitter user" + me
+            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)