Merge 6bb3b85666fb6bc63dcde22aa5d054586f3be029 into 5fe8f83bc58eb9a06acd67ad2488467aaf8cac17

This commit is contained in:
ukmoose 2015-12-17 22:20:49 +00:00
commit a60e658508
3 changed files with 58 additions and 4 deletions

16
social/twitter/27-twitter.html Normal file → Executable file
View File

@ -105,6 +105,7 @@
<option value="true" data-i18n="twitter.search.follow"></option> <option value="true" data-i18n="twitter.search.follow"></option>
<option value="user" data-i18n="twitter.search.user"></option> <option value="user" data-i18n="twitter.search.user"></option>
<option value="dm" data-i18n="twitter.search.direct"></option> <option value="dm" data-i18n="twitter.search.direct"></option>
<option value="event" data-i18n="twitter.search.events"></option>
</select> </select>
</div> </div>
<div class="form-row" id="node-input-tags-row"> <div class="form-row" id="node-input-tags-row">
@ -123,11 +124,17 @@
<ul><li>the public or a user's stream for tweets containing the configured search term</li> <ul><li>the public or a user's stream for tweets containing the configured search term</li>
<li>all tweets by specific users</li> <li>all tweets by specific users</li>
<li>direct messages received by the authenticated user</li> <li>direct messages received by the authenticated user</li>
<li>twitter events for the authenticated user</li>
</ul></p> </ul></p>
<p>Use space for <i>and</i> and comma , for <i>or</i> when searching for multiple terms.</p> <p>Use space for <i>and</i> ,a comma for <i>or</i> ,when searching for multiple terms.</p>
<p>When returning tweets or DM's:</p>
<p>Sets the <b>msg.topic</b> to <i>tweets/</i> and then appends the senders screen name.</p> <p>Sets the <b>msg.topic</b> to <i>tweets/</i> and then appends the senders screen name.</p>
<p>Sets <b>msg.location</b> to the tweeters location if known.</p> <p>Sets <b>msg.location</b> to the tweeters location if known.</p>
<p>Sets <b>msg.tweet</b> to the full tweet object as documented by <a href="https://dev.twitter.com/docs/platform-objects/tweets">Twitter</a>. <p>Sets <b>msg.tweet</b> to the full tweet object as documented by <a href="https://dev.twitter.com/docs/platform-objects/tweets">Twitter</a>.</p>
<p>When returning events:</p>
<p>Sets the <b>msg.event</b> to the twitter event, a full list is documented by <a href=https://dev.twitter.com/streaming/overview/messages-types#Events_event">Twitter</a>.</p>
<p>Sets <b>msg.payload</b> to the full tweet object as documented by <a href="https://dev.twitter.com/docs/platform-objects/tweets">Twitter</a>.</p>
<p><b>Note:</b> when set to a specific user's tweets, or your direct messages, the node is subject to <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 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 exceed the limit and will see errors from the node. These errors will clear when the current 15 minute window
@ -155,6 +162,9 @@
if (this.user == "dm") { if (this.user == "dm") {
var user = RED.nodes.node(this.twitter); var user = RED.nodes.node(this.twitter);
return (user?user.label()+" ":"")+this._("twitter.label.dmslabel"); return (user?user.label()+" ":"")+this._("twitter.label.dmslabel");
} else if (this.user == "event") {
var user = RED.nodes.node(this.twitter);
return (user?user.label()+" ":"")+this._("twitter.label.eventslabel");
} else if (this.user == "user") { } else if (this.user == "user") {
return this.tags+" "+this._("twitter.label.tweetslabel"); return this.tags+" "+this._("twitter.label.tweetslabel");
} }
@ -174,7 +184,7 @@
$("#node-input-tags-row").show(); $("#node-input-tags-row").show();
$("#node-input-tags-label").html(userlabel); $("#node-input-tags-label").html(userlabel);
$("#node-input-tags").attr("placeholder",userph); $("#node-input-tags").attr("placeholder",userph);
} else if (type == "dm") { } else if (type == "dm" || type == "event") {
$("#node-input-tags-row").hide(); $("#node-input-tags-row").hide();
} else { } else {
$("#node-input-tags-row").show(); $("#node-input-tags-row").show();

42
social/twitter/27-twitter.js Normal file → Executable file
View File

@ -182,6 +182,48 @@ module.exports = function(RED) {
},120000)); },120000));
}); });
} else if (this.user === "event") {
try {
var thing = 'user';
var setupStream = function() {
if (node.active) {
twit.stream(thing, st, function(stream) {
//twit.stream('user', { track: [node.tags] }, function(stream) {
node.stream = stream;
stream.on('data', function(tweet) {
if (tweet.event !== undefined) {
console.log("stream event"+tweet.event);
console.log(tweet);
var la = tweet.target.lang || tweet.source.lang;
var msg = { event:tweet.event, payload:tweet };
node.send(msg);
}
});
stream.on('limit', function(tweet) {
node.warn("tweet rate limit hit");
});
stream.on('error', function(tweet,rc) {
if (rc == 420) {
node.warn("Twitter rate limit hit");
} else {
node.warn("Stream error:"+tweet.toString()+" ("+rc+")");
}
setTimeout(setupStream,10000);
});
stream.on('destroy', function (response) {
if (this.active) {
node.warn("twitter ended unexpectedly");
setTimeout(setupStream,10000);
}
});
});
}
}
setupStream();
}
catch (err) {
node.error(err);
}
} else if (this.tags !== "") { } else if (this.tags !== "") {
try { try {
var thing = 'statuses/filter'; var thing = 'statuses/filter';

View File

@ -7,6 +7,7 @@
"user": "User", "user": "User",
"dmslabel": "DMs", "dmslabel": "DMs",
"tweetslabel": "tweets", "tweetslabel": "tweets",
"eventslabel": "events",
"clickhere": "Click here to authenticate with Twitter." "clickhere": "Click here to authenticate with Twitter."
}, },
"placeholder": { "placeholder": {
@ -17,7 +18,8 @@
"public": "all public tweets", "public": "all public tweets",
"follow": "the tweets of who you follow", "follow": "the tweets of who you follow",
"user": "the tweets of specific users", "user": "the tweets of specific users",
"direct": "your direct messages" "direct": "your direct messages",
"events": "your twitter events"
}, },
"tip": "Tip: Use commas without spaces between multiple search terms. Comma = OR, Space = AND.<br/>The Twitter API WILL NOT deliver 100% of all tweets.<br/>Tweets of who you follow will include their retweets and favourites.", "tip": "Tip: Use commas without spaces between multiple search terms. Comma = OR, Space = AND.<br/>The Twitter API WILL NOT deliver 100% of all tweets.<br/>Tweets of who you follow will include their retweets and favourites.",
"status": { "status": {