-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliri.js
166 lines (124 loc) · 4.43 KB
/
liri.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//DotENV require and config
require("dotenv").config();
var keys = require("./keys.js");
//Request for OMDB API Module
var request = require("request");
//Spotify-API NPM Module
var Spotify = require("node-spotify-api");
//Twitter npm Module
var Twitter = require("twitter");
//assign movieTitle var to argv[2]
var action = process.argv[2];
var value = process.argv[3];
var fs = require("fs");
//switch statement, containing functions to designate liri commands
switch (action) {
case "my-tweets":
myTweets();
break;
case "spotify-this-song":
spotifyThisSong();
break;
case "movie-this":
movieThis();
break;
case "do-what-it-says":
doWhatItSays();
break;
default:
console.log("Unexpected command line argument");
}
//MovieThis Function to access OMDB API
function movieThis() {
if (process.argv[3] === undefined) {
process.argv[3] = "Mr. Nobody;";
}
var value = process.argv.slice(3).join("+");
//set up query to OMDB API
var queryUrl = "http://www.omdbapi.com/?t=" + value + "&apikey=4645abe9";
// console.log(queryUrl);
request(queryUrl, function(error, response, body) {
if (!error && response.statusCode === 200) {
console.log(
"Here is the movie info you requested about " + value.toUpperCase() + ", Taddes, comliments of me, Liri: ");
console.log("========================MOVIES========================");
console.log("Title: " + JSON.parse(body).Title);
console.log("Year of Release: " + JSON.parse(body).Year);
console.log("IMDB Rating: " + JSON.parse(body).Ratings[0].Value);
console.log("Rotten Tomatoes Rating: " + JSON.parse(body).Ratings[1].Value);
console.log("Country/Countires of Production: " + JSON.parse(body).Country);
console.log("Language: " + JSON.parse(body).Language);
console.log("Plot: " + JSON.parse(body).Plot);
console.log("Actors: " + JSON.parse(body).Actors);
console.log("========================MOVIES========================");
}
});
} //end of movieThis function
function spotifyThisSong() {
// var value = process.argv.slice(3).join("+");
// console.log("value: " + value);
if (process.argv[3] === undefined) {
process.argv[3] = "The Sign Ace of";
}
var spotify = new Spotify(keys.spotify);
var value = process.argv.slice(3).join(" ");
spotify.search({ type: "track", query: value, limit: 1 }, function(err,data) {
if (err) {
return console.log("Error occurred: " + err);
}
console.log(value);
//declaration to break down code needed to access pathway
var songInfo = data.tracks.items[0];
console.log("Here is the song info on " + value.toUpperCase() +" that you requested, Taddes, comliments of me, Liri: ");
console.log("========================SPOTIFY========================");
console.log("Artist(s): " + songInfo.artists[0].name);
console.log("Song Name: " + songInfo.album.name);
console.log("Album: " + songInfo.album.name);
if (songInfo.preview_url === null) {
console.log("No song preview link available");
} else {
console.log("Album Preview URL: " + songInfo.preview_url);
}
console.log("========================SPOTIFY========================");
});
} //end of spotifyThisSong function
//Twitter Module Function
function myTweets() {
var client = new Twitter(keys.twitter);
var params = { screen_name: "taddes_k", count: 20 };
client.get("statuses/user_timeline", params, function(error, tweets, response) {
if (!error) {
console.log(tweets);
}
console.log("Here are your Tweets, Taddes, comliments of me, Liri: ");
console.log("========================Tweets========================");
for (var i = 0; i < tweets.length; i++) {
console.log("Tweet No." + (i + 1) + ": " + tweets[i].text);
}
console.log("========================Tweets========================");
});
}
function doWhatItSays() {
fs.readFile("random.txt", "utf8", function(error, data) {
if (error) {
return console.log("Do What It Says Error: " + error);
}
else {
console.log(data);
var dataArr = data.split(",");
action = dataArr[0];
value = dataArr[1];
spotifyThisSong();
console.log(dataArr);
}
});
}
//output to log.txt function BONUS
function appendToLog() {
fs.appendFile("log.txt", "utf-8", function(error) {
if (error) {
return console.log("ERROR: " + error);
}
console.log("log file updated");
});
}