Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The below code is utilizing nodejs to run some commands, with the help of apt np

ID: 3871939 • Letter: T

Question

The below code is utilizing nodejs to run some commands, with the help of apt npm packages. However, this example is not, yet. My terminal is taking issue with recognizing the get.client for the Twitter code (and that's from the npm package documentation) ... and that's toward the beginning. Requesting debugging.

// REQUIRE FILES
var Twitter = require('twitter');
var twitterKeys = require('./keys.js');

var spotify = require('node-spotify-api');
var request = require('request');
var fs = require('fs');

// Twitter command
if (process.argv[2] === "my-tweets") {
// Using Twit constructor object to draw on Twitter API
var client = twitterKeys;
var params = { screen_name: 'MetalWorksWood', count: 20 };
client.get('statuses/user_timeline', params, function(error, tweets, response) {
if(error) {
console.log(error);
} else {
console.log(tweets);
console.log(response);
}
});

// Spotify command
} else if (process.argv[2] === "spotify-this-song") {
var Spotify = require('node-spotify-api');

var spotify = new Spotify({
id: b55a9b13219744e8acc2593cf4c6016c,
secret: c700dab217a54ae7b9895c98f299dd8e
});
var song = process.argv;
var songName = process.argv[3]

for (var i = 3; i < song.length; i++) {
if (i > 3 && i < song.length) {
songName = songName + "+" + song[i];
} else {
songName += song[i];
}

spotify.search({
type: 'track',
query: songName
}, function(err, data) {
console.log("******Spotify Response******");
console.log(data);

if (err) {
console.log(err);
} else if (!songName) {
return console.log("Artist: Ace of Base Track: 'The Sign' Preview Link: 'https://open.spotify.com/track/3DYVWvPh3kGwPasp7yjahc' Album: 'The Sign' ");
} else {
console.log("Artist: " + data.artist +" Track: 'The Sign' Preview Link: 'https://open.spotify.com/track/3DYVWvPh3kGwPasp7yjahc' Album: 'The Sign' ");
}
});
}
// OMBD Command
} else if (process.argv[2] === "movie-this") {
var nodeArgs = process.argv;

// Create an empty variable for holding the movie name
var movieName = "";

// Loop through all the words in the node argument
// And do a little for-loop magic to handle the inclusion of "+"s
for (var i = 3; i < nodeArgs.length; i++) {
if (i > 3 && i < nodeArgs.length) {
movieName = movieName + "+" + nodeArgs[i];
} else {
movieName += nodeArgs[i];
}
}

// Then run a request to the OMDB API with the movie specified
var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&apikey=40e9cece";

// This line is just to help us debug against the actual URL.
console.log(queryUrl);
request(queryUrl, function(error, response, body) {

// If the request is successful
if (!error && response.statusCode === 200) {
// Parse the body of the site and recover to output as so
// title, year released, imdb rating, rotten tomatoes rating, country of production, movie language, movie plot, movie actors
console.log("Title: " + JSON.parse(body).Title + " Release Year: " + JSON.parse(body).Year + " IMDB Rating: " + JSON.parse(body).imdbRating + " Rotten Tomatoes Rating: " + JSON.parse(body).Value + " Country Where Produced: " + JSON.parse(body).Country + " Language: " + JSON.parse(body).Language + " Plot: " + JSON.parse(body).Plot + " Actors: " + JSON.parse(body).Actors);
}
});
// Text Reader command
} else if (process.argv[2] === "do-what-it-says") {
fs.readFile("random.txt", "UTF-8", function(err, data) {
if (err) {
console.log(error);
}
console.log("node liri.js " + data);
});
} else {
console.log("Please try again. Command options are: 'my-tweets', 'spotify-this-song', 'movie-this', 'or do-what-it-says' ");
}

keys.js

console.log('this is loaded');

var twitterKeys = {
consumer_key: 'FAd8CKEvEEDKUETHbs2bUhhm1',
consumer_secret: 'Ls6i1RqZQpTwN7m3H16EsBB4xjeDBVs0IFr6diy0j8St3f39T8',
access_token_key: '913037658305294337-shH52SZKNwLBaCs1ddWa7UyamTL3lgL',
access_token_secret: 'nXIN3AAicxVu28XnSyjsCXffqGsYIoU4sdm1sxElDcCEw',
}

module.exports = twitterKeys;

Explanation / Answer

console.log()
var Twit = require('twit');
var config = require('./config')
var T = new Twit(config);
var stream = T.stream('user');
//open a stream object
stream.on('follow',followed);
// stream on follow event
function followed(eventMsg){
console.log('FOllow event');
var name = eventMsg.source.name;
var screenName = eventMsg.source.screen_name;
tweetMessage('@'+screenName+"Thank you")
}
// callback function for follow event
function tweetMessage(txt){
var tweet = {
status: txt }
T.post('statuses/update', tweet, tweeted)
function tweeted(err, data, response) {
if(err){
console.log("Something went wrong!");
}
else{
console.log("Voila It worked!");
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote