HTML and CSS Reference
In-Depth Information
Replace the bottom of your
app.js
file with the highlighted content in
Listing 22-3
to listen for tweets
directed at your account. You need to replace the value of the
accountName
property with the name of the
account you created.
Listing 22-3:
Reading from the user stream
var twitter = require("ntwitter");
var client = new twitter({
consumer_key: "YOUR_CONSUMER_KEY",
consumer_secret: "YOUR_CONSUMER_SECRET",
access_token_key: "YOUR_ACCESS_TOKEN_KEY",
access_token_secret: "YOUR_ACCESS_TOKEN_SECRET"
});
var accountName = 'hangmangame';
client.stream('user', { track:accountName ,replies:'all' },
function(stream) {
stream.on('data', function (data) {
console.log("****************");
console.log(data);
console.log("****************");
});
stream.on('end', function (response) {
// Need to reconnect
});
stream.on('destroy', function (response) {
// Need to reconnect
});
});
If you run this file via
node app.js
, you should first see a list of friend account IDs for the account pop-
ulated, and then the interface should sit and wait for activity on the user (your development account may not
have anyone followed or following yet).
If you tweet at the account (
@hangmangame
in the example) or from the account itself, those tweets log to
the console.
Generating Random Words
To play a game of
Hangman
, the app needs access to a list of words to play. Luckily lists of words are available
in a number of places on the web. One of the best spots to grab a list is at
http://wordlist.sourceforge.net/
.
Of
the myriad lists available there, the best list for the purposes of
Hangman
is the 12dicts list, which contains a
list approximating the common core of the vocabulary of American English.
You can download the original 12dicts source files from
http://downloads.sourceforge.net/wordlist/12-
dicts-5.0.zip
, but the chapter code has a file called
words.txt
that is a single list of the most common words,
which has been slightly modified to adjust the line endings. The 12dicts file uses the Automatically Generated
Inflection Database (AGID) list as a source, so the license for the AGID is included in the chapter download. It
can be used freely but must include the copyright notice if distributed.