-
Notifications
You must be signed in to change notification settings - Fork 1
/
liri.js
151 lines (139 loc) · 5.42 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
require("dotenv").config();
//packages and files required
const keys = require("./keys.js");
const axios = require("axios");
const fs = require("fs");
const moment = require("moment");
const Spotify = require("node-spotify-api");
//variables to hold user input
let command = process.argv[2];
let searchArgs = process.argv;
let search = "";
//loop to get all of the words in the title, artist, etc the user searches
for (let i = 3; i < searchArgs.length; i++) {
if (i > 3 && i < searchArgs.length) {
search = search + "+" + searchArgs[i];
} else {
search += searchArgs[i];
}
}
function runLiri(command, search) {
switch(command) {
case "movie-this":
movieThis(search);
break;
case "concert-this":
concertThis(search);
break;
case "spotify-this-song":
spotifyThis(search);
break;
case "do-what-it-says":
doWhatItSays();
break;
}
}
function movieThis(search) {
let movieQueryURL = "http://www.omdbapi.com/?t=" + search + "&y=&plot=short&apikey=trilogy";
axios.get(movieQueryURL).then(
function(response) {
if (response.data.Response === "False") {
console.log("If you haven't watched 'Mr. Nobody,' then you should: http://www.imdb.com/title/tt0485947/");
console.log("It's on Netflix!");
} else {
console.log("--------------------------------------------------------------------------------");
console.log("Title: " + response.data.Title);
console.log("Year: " + response.data.Year);
console.log("IMDB Rating: " + response.data.imdbRating);
console.log("Rotten Tomatoes: " + response.data.Ratings[1].Value);
console.log("Country: " + response.data.Country);
console.log("Language: " + response.data.Language);
console.log("Plot: " + response.data.Plot);
console.log("Actors: " + response.data.Actors);
console.log("--------------------------------------------------------------------------------");
}
})
.catch(function(error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log("---------------Data---------------");
console.log(error.response.data);
console.log("---------------Status---------------");
console.log(error.response.status);
console.log("---------------Status---------------");
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an object that comes back with details pertaining to the error that occurred.
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log("Error", error.message);
}
console.log(error.config);
});
}
function concertThis(search) {
let concertQueryURL = "https://rest.bandsintown.com/artists/" + search + "/events?app_id=codingbootcamp"
axios.get(concertQueryURL).then(
function(response) {
for (let i = 0; i < 10; i++) {
console.log("--------------------------------------------------------------------------------");
console.log("Venue: " + response.data[i].venue.name);
console.log("Location: " + response.data[i].venue.city + ", " + response.data[i].venue.country);
console.log("Date: " + moment(response.data[i].datetime).format("MM/DD/YYYY"));
}
})
.catch(function(error) {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log("---------------Data---------------");
console.log(error.response.data);
console.log("---------------Status---------------");
console.log(error.response.status);
console.log("---------------Status---------------");
console.log(error.response.headers);
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an object that comes back with details pertaining to the error that occurred.
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.log("Error", error.message);
}
console.log(error.config);
});
}
function spotifyThis(search) {
let spotify = new Spotify(keys.spotify);
if (!search) {
search = "The Sign";
}
spotify.search({type: "track", query: search}, function(error, data) {
let results = data.tracks.items;
if (error) {
console.log("Sorry, there was an error.");
}
for (let i = 0; i < 5; i++) {
console.log("--------------------------------------------------------------------------------");
console.log("Artist: " + results[i].artists[0].name);
console.log("Song: " + results[i].name);
console.log("Preview: " + results[i].preview_url);
console.log("Album: " + results[i].album.name);
}
})
}
function doWhatItSays() {
fs.readFile("random.txt", "utf8", function(error, data) {
if (error) {
return console.log(error);
}
let dataArr = data.split(',');
// console.log(dataArr[0], dataArr[1]);
// console.log(dataArr[0], dataArr[1].replace(/['"]+/g, ''));
runLiri(dataArr[0], dataArr[1].replace(/['"]+/g, ''));
});
}
runLiri(command, search);