From 3ff0b6a761196ab2c6b54c185ee994e8da71240f Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 30 Sep 2016 20:38:05 +0100 Subject: [PATCH] More twitter rate fixes, Redo input pin logic --- social/twitter/27-twitter.html | 25 +++++++++++++------------ social/twitter/27-twitter.js | 18 +++++++++--------- social/twitter/package.json | 4 ++-- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/social/twitter/27-twitter.html b/social/twitter/27-twitter.html index 552cd8db..e0080952 100644 --- a/social/twitter/27-twitter.html +++ b/social/twitter/27-twitter.html @@ -145,9 +145,10 @@ tags: {value:""}, user: {value:"false",required:true}, name: {value:""}, - topic: {value:"tweets"} + topic: {value:"tweets"}, + inputs: {value:0} }, - inputs: 1, + inputs: 0, outputs: 1, icon: "twitter.png", label: function() { @@ -188,16 +189,16 @@ } }); $("#node-input-user").change(); - }//, - // oneditsave: function() { - // if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() === 'false') { - // this.inputs=1; - // } - // else { - // //set back the default state of 0 inputs - // this.inputs=0; - // } - // } + }, + oneditsave: function() { + if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() === 'false') { + this.inputs = 1; + } + else { + //set back the default state of 0 inputs + //this.inputs = 0; + } + } }); diff --git a/social/twitter/27-twitter.js b/social/twitter/27-twitter.js index 44b77b54..f2388ac6 100644 --- a/social/twitter/27-twitter.js +++ b/social/twitter/27-twitter.js @@ -202,7 +202,7 @@ module.exports = function(RED) { twit.stream(thing, st, function(stream) { //console.log("ST",st); node.stream = stream; - var retry = 15000; // 15 secs for general errors + var retry = 60000; // 60 secs backoff for now stream.on('data', function(tweet) { if (tweet.user !== undefined) { var where = tweet.user.location; @@ -213,20 +213,19 @@ module.exports = function(RED) { addLocationToTweet(msg); } node.send(msg); - node.status({fill:"green", shape:"dot", text:(tags||" ")}); + //node.status({fill:"green", shape:"dot", text:(tags||" ")}); } }); stream.on('limit', function(tweet) { - node.status({fill:"grey", shape:"dot", text:RED._("twitter.errors.limitrate")}); - //node.warn(RED._("twitter.errors.ratelimit")); + //node.status({fill:"grey", shape:"dot", text:RED._("twitter.errors.limitrate")}); + node.status({fill:"grey", shape:"dot", text:(tags||" ")}); }); stream.on('error', function(tweet,rc) { + //console.log("ERRO",rc,tweet); if (rc == 420) { node.status({fill:"red", shape:"ring", text:RED._("twitter.errors.ratelimit")}); - retry = 60000; // 60 secs for rate limit - //node.warn(RED._("twitter.errors.ratelimit")); } else { - node.status({fill:"red", shape:"ring", text:"rc:"+rc}); + node.status({fill:"red", shape:"ring", text:tweet.toString()}); node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc})); } twitterRateTimeout = Date.now() + retry; @@ -235,7 +234,8 @@ module.exports = function(RED) { } }); stream.on('destroy', function (response) { - twitterRateTimeout = Date.now() + retry; + //console.log("DEST",response) + twitterRateTimeout = Date.now() + 15000; if (node.restart) { node.status({fill:"red", shape:"dot", text:" "}); node.warn(RED._("twitter.errors.unexpectedend")); @@ -303,7 +303,7 @@ module.exports = function(RED) { node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")}); } else { - node.status({fill:"green", shape:"dot", text:(tags||" ")}); + this.restart = true; setupStream(); } } diff --git a/social/twitter/package.json b/social/twitter/package.json index 69755008..b31da0e6 100644 --- a/social/twitter/package.json +++ b/social/twitter/package.json @@ -1,11 +1,11 @@ { "name" : "node-red-node-twitter", - "version" : "0.1.6", + "version" : "0.1.7", "description" : "A Node-RED node to talk to Twitter", "dependencies" : { "twitter-ng": "0.6.2", "oauth" : "0.9.14", - "request" : "2.67.0" + "request" : "^2.75.0" }, "repository" : { "type":"git",