Mercurial > pumpbridge
diff src/twitter.coffee @ 28:faeb3b96bdeb
use html-to-text
author | Mathias Gebbe <mgebbe@intevation.de> |
---|---|
date | Tue, 29 Jul 2014 12:14:02 +0200 |
parents | f27ddfa42e94 |
children | 3e3fa35e3ce2 |
line wrap: on
line diff
--- 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) ->