mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
allow twitter multipe sech terms... space for AND and , for OR. (not sure why I had knobbled it in first place...)
This commit is contained in:
parent
e700a11647
commit
c17687e5db
@ -128,6 +128,7 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="twitter in">
|
||||
<p>Twitter input node. Watches either the public or the user's stream for tweets containing the configured search term.</p>
|
||||
<p>Use space for <i>and</i> and comma , for <i>or</i> when searching for multiple terms.</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.tweet</b> to the full tweet object as documented by <a href="https://dev.twitter.com/docs/platform-objects/tweets">Twitter</a>.
|
||||
@ -157,7 +158,6 @@
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="twitter out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-twitter"><i class="icon-user"></i> Twitter</label>
|
||||
|
@ -28,7 +28,8 @@ function TwitterInNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.active = true;
|
||||
this.user = n.user;
|
||||
this.tags = n.tags.replace(/ /g,'');
|
||||
//this.tags = n.tags.replace(/ /g,'');
|
||||
this.tags = n.tags;
|
||||
this.twitter = n.twitter;
|
||||
this.topic = n.topic||"tweets";
|
||||
this.twitterConfig = RED.nodes.getNode(this.twitter);
|
||||
@ -47,9 +48,21 @@ function TwitterInNode(n) {
|
||||
try {
|
||||
var thing = 'statuses/filter';
|
||||
if (this.user == "true") { thing = 'user'; }
|
||||
var st = { track: [node.tags] };
|
||||
var bits = node.tags.split(",");
|
||||
if ((bits.length > 0) && (bits.length % 4 == 0)) {
|
||||
if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) {
|
||||
st = { locations: node.tags };
|
||||
}
|
||||
else {
|
||||
node.warn("twitter: possible bad geo area format. Should be lower-left lon,lat, upper-right lon,lat");
|
||||
}
|
||||
}
|
||||
|
||||
function setupStream() {
|
||||
if (node.active) {
|
||||
twit.stream(thing, { track: [node.tags] }, function(stream) {
|
||||
twit.stream(thing, st, function(stream) {
|
||||
//console.log(st);
|
||||
//twit.stream('user', { track: [node.tags] }, function(stream) {
|
||||
//twit.stream('site', { track: [node.tags] }, function(stream) {
|
||||
//twit.stream('statuses/filter', { track: [node.tags] }, function(stream) {
|
||||
@ -64,14 +77,17 @@ function TwitterInNode(n) {
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
stream.on('error', function(tweet) {
|
||||
stream.on('limit', function(tweet) {
|
||||
node.log("tweet rate limit hit");
|
||||
});
|
||||
stream.on('error', function(tweet,rc) {
|
||||
node.warn(tweet);
|
||||
setTimeout(setupStream,5000);
|
||||
setTimeout(setupStream,10000);
|
||||
});
|
||||
stream.on('destroy', function (response) {
|
||||
if (this.active) {
|
||||
node.warn("twitter ended unexpectedly");
|
||||
setTimeout(setupStream,5000);
|
||||
setTimeout(setupStream,10000);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -85,21 +101,19 @@ function TwitterInNode(n) {
|
||||
} else {
|
||||
this.error("Invalid tag property");
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
this.error("missing twitter credentials");
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("twitter in",TwitterInNode);
|
||||
|
||||
TwitterInNode.prototype.close = function() {
|
||||
this.on('close', function() {
|
||||
if (this.stream) {
|
||||
this.active = false;
|
||||
this.stream.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("twitter in",TwitterInNode);
|
||||
|
||||
|
||||
function TwitterOutNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -134,11 +148,8 @@ function TwitterOutNode(n) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
RED.nodes.registerType("twitter out",TwitterOutNode);
|
||||
|
||||
|
||||
|
||||
var oa = new OAuth(
|
||||
"https://api.twitter.com/oauth/request_token",
|
||||
"https://api.twitter.com/oauth/access_token",
|
||||
@ -184,7 +195,6 @@ RED.app.get('/twitter/:id/auth', function(req, res){
|
||||
});
|
||||
|
||||
RED.app.get('/twitter/:id/auth/callback', function(req, res, next){
|
||||
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
credentials.oauth_verifier = req.query.oauth_verifier;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user