-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliri.js
More file actions
146 lines (130 loc) · 4.27 KB
/
liri.js
File metadata and controls
146 lines (130 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//RPM Simplified HTTP request client
var request = require('request');
var fs = require("fs");
//RPM Spotify API library for node.js
var spotifyData = require('spotify');
//RPM Twitter API client library for node.js
var keys = require ('./keys.js');
var Twitter = require('twitter');
var accountTweets = new Twitter(keys.twitterKeys);
//Global Variables
var command = process.argv[2];
var value = process.argv[3];
var limitSpotify = 5;
var limitTweets = 20;
//Will show the last 20 tweets and the date they were created
function myTweets(){
var params = {screen_name: 'rvilmars', count: limitTweets};
accountTweets.get('statuses/user_timeline', params, function(error, tweets, response) {
if (!error) {
console.log('\nThis are your last ' + (tweets.length) + ' tweets: \n');
for(var i = 0 ; i < tweets.length ; i++){
console.log('Tweet' + (i+1) + ': ');
console.log(tweets[i].text);
console.log('Created on: ' + tweets[i].created_at);
console.log('-------------------------')
}
// console.log(response);
}
});
return;
}//End myTweets function
//Will access the spotify API and will show:
//Artist, Song Name, Preview Link and the Album
//by Default the song will be 'The Sign by Aces of base'
function spotify(value) {
var songDefault = 'The Sign';
var artistDefault = 'Aces of base';
//Evaluation of user input, if undefined we assign a default song
if(value == undefined){
song = songDefault;
}
else{
song = value;
}
//Call the RPM funtion to search the song
spotifyData.search({ type: 'track', query: song}, function(err, data) {
if ( err ) {
console.log('Error occurred: ' + err);
return;
}
var formatted = JSON.stringify(data, null, 2);
console.log('\nI found this many songs:\n');
for (var i = 0; i < limitSpotify; i++) {
// console.log(data.tracks.items[i]);
console.log('Song ' + (i+1) + ':')
console.log('Artist: ' + data.tracks.items[i].artists[0].name);
console.log('Song Name: ' + data.tracks.items[i].name);
console.log('Album Name: ' + data.tracks.items[i].album.name);
console.log('Peeview Link: ' + data.tracks.items[i].preview_url);
console.log('-------------------------')
}
});
return;
}//End Spotify function
//Will access the imdb API and willl show
//Title, year, rating, Country, Language, plot, Actors, Rotten Tomatos rating and URL
//by Defaut 'Mr. Nobody'
function movieInfo(value){
var movieDefault = 'Mr. Nobody';
//Evaluation of user input, if undefined we assign a default movie
if(value == undefined){
movieName = movieDefault;
}
else{
movieName = value;
}
// We run a request to the OMDB API with the movie specified
var queryUrl = "http://www.omdbapi.com/?t=" + movieName + "&y=&plot=short&tomatoes=true&r=json";
//Create the request
request(queryUrl, function(error, response, movies) {
if(!error && response.statusCode === 200){
var movies = JSON.parse (movies);
console.log('\nCheck it out:\n');
console.log('Title of the movie: ' + movies.Title );
console.log('Year the movie came out: ' + movies.Year );
console.log('IMDB Rating of the movie: ' + movies.imdbRating);
console.log('Country where the movie was produced: ' + movies.Country);
console.log('Language of the movie: ' + movies.Language);
console.log('Plot of the movie: ' + movies.Plot);
console.log('Actors in the movie: ' + movies.Actors );
console.log('Rotten Tomatoes Rating: ' + movies.tomatoRating );
console.log('Rotten Tomatoes URL: ' + movies.tomatoURL);
console.log('-------------------------');
}
});
}//end Movie Info function
//Will use the fs Node Package and take the text inside to call one of the LIRI's commands
function doWhatItSays(){
fs.readFile("random.txt", "utf8", function(err, data){
var command = data.split(',');
// var value = command.join("\n");
switch (command[0]){
case 'my-tweets':
myTweets();
break;
case 'spotify-this-song':
spotify(command[1]);
break;
case 'movie-this':
movieInfo(command[1]);
break;
}
// console.log(command);
})
return;
}
switch (command){
case 'my-tweets':
myTweets();
break;
case 'spotify-this-song':
spotify(value);
break;
case 'movie-this':
movieInfo();
break;
case 'do-what-it-says':
doWhatItSays();
break;
}