Skip to content

Instantly share code, notes, and snippets.

@danzeeeman
Created February 24, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzeeeman/d69fde9e5807c5ad4d28b67ca7fc5059 to your computer and use it in GitHub Desktop.
Save danzeeeman/d69fde9e5807c5ad4d28b67ca7fc5059 to your computer and use it in GitHub Desktop.
GEO Twitter Search
require('dotenv').config('dot.env');
var fs = require('fs');
var util = require('util');
var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags : 'w'});
var log_stdout = process.stdout;
console.log = function(d) { //
log_file.write(d + '\n');
log_stdout.write(d + '\n');
};
var Twitter = require('twitter');
var client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token_key: '',
access_token_secret: ''
});
projectId = ''
const {Translate} = require('@google-cloud/translate').v2;
// Creates a client
const translate = new Translate({projectId});
async function translateText(text, target) {
// Translates the text into the target language. "text" can be a string for
// translating a single piece of text, or an array of strings for translating
// multiple texts.
let [translations] = await translate.translate(text, target);
translations = Array.isArray(translations) ? translations : [translations];
console.log('Translations:');
translations.forEach((translation, i) => {
console.log(`${translation}`);
});
}
var location = '29.652601,45.753720,36.337648,54.381852'
var stream = client.stream('statuses/filter', {locations:location});
stream.on('data', function(event) {
console.log(event.user.screen_name+", "+event.text+", "+event.timestamp_ms)
translateText(event.text, 'en')
});
stream.on('error', function(error) {
console.log(error)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment