Last active
August 29, 2015 13:57
-
-
Save samplereality/9781715 to your computer and use it in GitHub Desktop.
longlive.js
This file contains 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
// This is a code comment. | |
// Any line preceded by two slashes | |
// will not be executed as code. | |
// (Even if the line has otherwise functioning code in it.) | |
// You can also use these double slashes _after_ a line of code, | |
// to serve as an in-line comment on that line of code. | |
// (Kinda like a note in the margin.) | |
// This little program requires "libraries"--other programs that extend the functionality of the base node.js code | |
// So the next two lines tell this program to look for two libraries | |
var Twit = require('twit'); // This library lets us communicate with Twitter | |
var rita = require('rita'); // This library provides a lot of text processing tools | |
// We'll start with next few lines commented out. | |
// We won't need these until we're ready to post to Twitter | |
// var T = new Twit({ | |
// consumer_key: 'CONSUMER KEY HERE', | |
// consumer_secret: 'SECRET KEY HERE', | |
// access_token: 'ACCESS TOKEN HERE', | |
// access_token_secret: 'ACCESS TOKEN SECRET HERE' | |
// }); | |
// Here we create a lexicon library (a word list), using the RiTa library | |
// Documentation on RiTa is at http://rednoise.org/rita/reference/index.html | |
lexicon = new rita.RiLexicon(); | |
// Here we create a function to capitalize the first letter of a string | |
function capitalizeFirstLetter(string) | |
{ | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
// Here we create the function to generate text | |
function makeLive() { | |
var theKing = lexicon.randomWord('nn'); | |
var longLive = "Long live" + " " + theKing + "."; | |
console.log(longLive); | |
// Toggle Twitter by un/commenting next four lines | |
// T.post('statuses/update', { status: dead}, function(err, reply) { | |
// console.log("error: " + err); | |
// console.log("reply: " + reply); | |
// }); | |
} | |
// Let's execute the function! | |
makeLive(); | |
// A timer to run the script every 60 minutes | |
// setInterval(function () { | |
// try { | |
// makeLive(); | |
// } | |
// catch (e) { | |
// console.log(e); | |
// } | |
// }, 1000 * 60 * 60); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment