Tidy up twitter node info

and re-order code to make more logical. (or at least readable)
This commit is contained in:
Dave Conway-Jones 2016-09-29 23:30:13 +01:00
parent c456f89441
commit eeb1189092
3 changed files with 39 additions and 42 deletions

View File

@ -120,8 +120,9 @@
<script type="text/x-red" data-help-name="twitter in">
<p>Twitter input node. Can be used to search either:
<ul><li>the public or a user's stream for tweets containing the configured search term</li>
<li>all tweets by specific users</li>
<ul><li>the public stream for tweets containing the configured search term</li>
<li>all the tweets from accounts that the authenticated user follows</li>
<li>all tweets by specified users</li>
<li>direct messages received by the authenticated user</li>
</ul></p>
<p>Use space for <i>and</i> and comma , for <i>or</i> when searching for multiple terms.
@ -129,10 +130,10 @@
<p>Sets the <code>msg.topic</code> to <i>tweets/</i> and then appends the senders screen name.</p>
<p>Sets <code>msg.location</code> to the tweeters location if known.</p>
<p>Sets <code>msg.tweet</code> to the full tweet object as documented by <a href="https://dev.twitter.com/overview/api/tweets">Twitter</a>.
<p><b>Note:</b> when set to a specific user's tweets, or your direct messages, the node is subject to
Twitter's API rate limiting. If you deploy the flows multiple times within a 15 minute window, you may
exceed the limit and will see errors from the node. These errors will clear when the current 15 minute window
passes.</p>
<p><b>Note:</b> when set to follow specific users, or your direct messages, the node is subject to
the rate limiting of the Twitter API. If you deploy the flows multiple times within a 15 minute window, you may
exceed the limit and will see errors from the node. These errors will clear automatically when the current 15
minute window passes.</p>
</script>
<script type="text/javascript">
@ -153,14 +154,14 @@
if (this.name) {
return this.name;
}
var uname = RED.nodes.node(this.twitter);
if (this.user == "dm") {
var user = RED.nodes.node(this.twitter);
return (user?user.label()+" ":"")+this._("twitter.label.dmslabel");
return (uname?uname.label()+" ":"")+this._("twitter.label.dmslabel");
} else if (this.user == "user") {
return this.tags+" "+this._("twitter.label.tweetslabel");
}
else if (this.user == "true") {
return this._("twitter.label.followers");
return this._("twitter.label.followers") + (uname?(" "+uname.label()):"");
}
return "twitter";
},

View File

@ -194,24 +194,6 @@ module.exports = function(RED) {
var thing = 'statuses/filter';
var tags = node.tags;
var st = { track: [tags] };
if (this.user === "true") {
thing = 'user';
//st.with = "user";
// twit.getFriendsIds(node.twitterConfig.screen_name.substr(1), function(err,list) {
// friends = list;
// });
st = null;
}
var bits = node.tags.split(",");
if (bits.length == 4) {
if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) {
st = { locations: node.tags };
node.log(RED._("twitter.status.using-geo",{location:node.tags.toString()}));
}
}
var setupStream = function() {
if (node.active) {
@ -228,10 +210,7 @@ module.exports = function(RED) {
addLocationToTweet(msg);
}
node.send(msg);
if (tags !== "zyxxyzyxxyzyxxyzyxxyzyxxyzyxxy") {
node.status({fill:"green", shape:"dot", text:tags});
}
else { node.status({fill:"green", shape:"dot", text:node.twitterConfig.screen_name}); }
node.status({fill:"green", shape:"dot", text:(tags||" ")});
}
});
stream.on('limit', function(tweet) {
@ -256,12 +235,26 @@ module.exports = function(RED) {
});
}
}
if (tags === '') {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
// ask for users stream instead of public
if (this.user === "true") {
thing = 'user';
// twit.getFriendsIds(node.twitterConfig.screen_name.substr(1), function(err,list) {
// friends = list;
// });
st = null;
}
else {
setupStream();
// if 4 numeric tags that look like a geo area then set geo area
var bits = node.tags.split(",");
if (bits.length == 4) {
if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) {
st = { locations: node.tags };
node.log(RED._("twitter.status.using-geo",{location:node.tags.toString()}));
}
}
// all public tweets
if (this.user === "false") {
node.on("input", function(msg) {
if (this.tags === '') {
@ -276,14 +269,17 @@ module.exports = function(RED) {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
}
}
//We shouldn't get into this state, but just incase, check for it
else {
//console.log("oops");
//node.status({fill:"green", shape:"dot", text:node.tags});
}
});
}
else { node.status({fill:"green", shape:"ring", text:node.twitterConfig.screen_name}); }
// wait for input or start the stream
if ((this.user === "false") && (tags === '')) {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
}
else {
node.status({fill:"green", shape:"ring", text:(tags||" ")});
setupStream();
}
}
catch (err) {
node.error(err);

View File

@ -6,7 +6,7 @@
"for": "for",
"user": "User",
"dmslabel": "DMs",
"followers": "followed users",
"followers": "followed by",
"tweetslabel": "tweets",
"clickhere": "Click here to authenticate with Twitter."
},