-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweet from a JS file #579
Comments
something like this, but this is quick and crude psuedocode setInterval(function(){ //inside nameofscript.js |
Hey thanks. but i think i'm doing something wrong. my index file: console.log('Starting'); const Twit = require('twit'); const config = require('./config');
node tweets.js one two three four five T.post('statuses/update', tweet, tweeted);
} My tweets file: const myArgs = process.argv.slice(2); 'This is a test tweet' |
try something like this just to understand how command line args work, then copy all of your tweeting code into testTweet.js. your setinterval should be in index.js and your tweet code should be in the second file. you can also spawn a child process. google node child process //index.js let testTweet = 'this is a test'; //tweetTest.js console.log('Starting'); const myArgs = process.argv.slice(2); |
I seem to get an error again, do i need to remove something from the index file ? Index.js file: console.log('Starting'); const Twit = require('twit'); const config = require('./config');
node tweets.js + ' ' + testTweet T.post('statuses/update', tweet, tweeted);
} tweet.js file: const myArgs = process.argv.slice(2); |
what error? |
C:\Users\richa\Documents\TwitBot>node index.js SyntaxError: Unexpected identifier |
oh duh, i forgot you have to use child process const { spawn } = require('node:child_process'); bat.stdout.on('data', (data) => { bat.stderr.on('data', (data) => { bat.on('exit', (code) => { |
Thank man, so should both my files look like this below ? Index.js: console.log('Starting'); const Twit = require('twit'); const config = require('./config'); const { spawn } = require('node:child_process'); bat.stdout.on('data', (data) => { bat.stderr.on('data', (data) => { bat.on('exit', (code) => { let testTweet = 'this is a test'; node tweets.js + ' ' + testTweet T.post('statuses/update', tweet, tweeted); function tweeted(err, data, response) { if (err) { console.log("Something went wrong!"); } else { console.log("It worked!"); } } tweets.js: const myArgs = process.argv.slice(2); |
I would do it like this, make index call tweets.js and have all the tweet code in tweets.js, then inside index loop or interval to repeat index.js: console.log('Starting'); const { spawn } = require('node:child_process'); //then i would do the setInterval here so it calls this every x secs bat.stdout.on('data', (data) => { bat.stderr.on('data', (data) => { bat.on('exit', (code) => { tweets.js: const Twit = require('twit'); const config = require('./config'); const myArgs = process.argv.slice(2); // i forget how to pass testTweet into T.post but you need to do that here function tweeted(err, data, response) { if (err) { console.log("Something went wrong!"); } else { console.log("It worked!"); } } |
this guy has a video series https://www.youtube.com/playlist?list=PLRqwX-V7Uu6atTSxoRiVnSuOn6JHnq2yV |
This should work. // Replace these with your own API keys // This function will be called every minute to tweet a message // Post the message // Call the function every minute |
Does anyone know how I tweet from another JS File ?
My index file looks likes this:
console.log('Starting');
var Twit = require('twit');
var config = require('./config');
var T = new Twit(config);
T.post('statuses/update', tweet, tweeted);
I'm new to this and all I want to do is say tweet from another js file called tweets that say has a list of tweets in it like the below:
'This is a test tweet'
'This is a test tweet 2'
'This is a test tweet 3'
and I want it to tweet them from top to bottom and also with an interval say like every hour.
Can anyone help with this ?
Thanks
The text was updated successfully, but these errors were encountered: