Created
November 4, 2016 13:42
-
-
Save darthcoder/28b0417e3e61dad117d0d2d0b5a49642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Twitter = require('twitter'); | |
| var client = new Twitter({ | |
| consumer_key: process.env.TWITTER_CONSUMER_KEY, | |
| consumer_secret: process.env.TWITTER_CONSUMER_SECRET, | |
| access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, | |
| access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET | |
| }); | |
| const fs = require('fs'); | |
| var long_string = fs.readFileSync(__dirname + "/tweetfromhere.txt").toString(); | |
| var short_string = new String(""); | |
| const tweet_length = 140; | |
| if (long_string.length%tweet_length === 0) | |
| { | |
| var num_tweets = long_string.length/tweet_length; | |
| } | |
| else | |
| { | |
| var num_tweets = Math.floor(long_string.length/tweet_length); | |
| console.log(num_tweets); | |
| } | |
| for (i = 0; i <= num_tweets; i++) | |
| { | |
| short_string = long_string.substr(i*tweet_length, tweet_length); | |
| var stat = {status: short_string} | |
| setTimeout(function(){ | |
| client.post('statuses/update', stat, function(error, tweet,response) { | |
| if(error) | |
| { | |
| console.log(error); | |
| } | |
| //console.log(tweet); // Tweet body. | |
| console.log(response); // Raw response object. | |
| }); | |
| }, 3000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment