├── .gitignore ├── package.json ├── LICENSE.txt ├── README.md └── autotweet /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | settings.json -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autotweet", 3 | "version": "1.0.0", 4 | "description": "A simple script for automatically generating tweets for twitter", 5 | "main": "autotweet.js", 6 | "dependencies": { 7 | "twitter": "~0.2.7" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/WaldoHatesYou/autotweet.git" 16 | }, 17 | "keywords": [ 18 | "twitter", 19 | "markov", 20 | "automatic" 21 | ], 22 | "author": "Javed Nissar", 23 | "license": "BSD-2-Clause", 24 | "bugs": { 25 | "url": "https://github.com/WaldoHatesYou/autotweet/issues" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Javed Nissar 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # autotweet.js 2 | 3 | ## What is it? 4 | 5 | autotweet.js is a simple node.js script that randomly generates some text from a list of sentences (using a [Markov Chain](https://en.wikipedia.org/wiki/Markov_chain)) and 6 | then posts it as a tweet on twitter. 7 | 8 | ## How Do I use it? 9 | 10 | Before you try using autotweet.js, you'll need to have a [twitter](https://twitter.com) account and you'll need to have [node.js](http://nodejs.org) installed on your computer. After you have that done and over with, just clone autotweet.js from github. 11 | ```Batchfile 12 | git clone https://github.com/WaldoHatesYou/autotweet.git 13 | ``` 14 | Then, go to the "autotweet" directory and write out a "settings.json" file. The "settings.json" file should contain the information that is required to post to your twitter account (api consumer key, api consumer secret, api access token key, and api access token secret) as well as a list of sentences that is to be included in the corpus field of the "settings.json" file. An example is shown below. 15 | ```Javascript 16 | { 17 | "consumer_key":"Insert key here", 18 | "consumer_secret":"Insert consumer secret here", 19 | "access_token_key":"Insert access token key here", 20 | "access_token_secret":"Insert access token secret here", 21 | "corpus":[ 22 | "Hi, I am a sentence in a corpus", 23 | "Is this sentence awesome or is this sentence really awesome?", 24 | "Strawberry fields forever" 25 | ] 26 | } 27 | ``` 28 | After you're done that, grab the node-twitter library using the following command. 29 | ```Batchfile 30 | npm init 31 | ``` 32 | Once that finishes, convert your node.js script file into an executable by executing the following command. 33 | ```Batchfile 34 | chmod+x autotweet 35 | ``` 36 | If you finished that step, you can now start sending tweets by typing the following command into your command line. 37 | ```Batchfile 38 | ./autotweet 39 | ``` 40 | Of course, if you want to, you can place your settings file in a different location with a name other than 41 | "settings.json". If you do this, you will have to pass the location of the json file to autotweet like this. 42 | ```Batchfile 43 | ./autotweet ~/Documents/settings.json 44 | ``` 45 | -------------------------------------------------------------------------------- /autotweet: -------------------------------------------------------------------------------- 1 | #! /usr/local/bin/node 2 | 3 | var twitter=require('twitter'); 4 | var fs=require('fs'); 5 | var util=require('util'); 6 | 7 | /* Returns a random integer between min and max 8 | Using Math.round() will give you a non-uniform distribution! 9 | This code is from Mozilla Developer Network*/ 10 | function getRandomInt(min, max) { 11 | return Math.floor(Math.random() * (max - min + 1)) + min; 12 | } 13 | 14 | //MARKOV CHAIN CODE 15 | //Define the initialization of the generator 16 | function MarkovChainGenerator(corpus){ 17 | //create some variables to hold the data we need 18 | this.transitionMatrix={}; 19 | var numbers={}; 20 | var collection={} 21 | //first get the number of times every word occurs after every other word, we need this for the probability calculations 22 | for(var x=0;x