-
Notifications
You must be signed in to change notification settings - Fork 0
/
liri.js
142 lines (126 loc) · 3.83 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
require("dotenv").config();
const axios = require("axios");
const moment = require('moment');
const fs = require('fs');
function getUserArguments() {
return process.argv.slice(2);
}
function getSearchType() {
return getUserArguments()[0];
}
function getSearchTerm() {
return getUserArguments().slice(1).join('+');
}
function searchType(searchType, searchTerm) {
switch (searchType) {
case 'spotify-this-song':
spotifyThisSong(searchTerm);
break;
case "concert-this":
concertThis(searchTerm);
break;
case "movie-this":
movieThis(searchTerm);
break;
default:
doWhatItSays();
}
}
function movieThis(movie) {
if (!movie) {
movie = "Mr. Nobody";
}
// Use axios to search OMDB for film info
axios.get("http://www.omdbapi.com/?t=" + movie + "&y=&plot=short&apikey=trilogy").then(
function (response) {
// Then print out the results
var title = "Film Title: " + response.data.Title;
var year = "Year Released: " + response.data.Year;
var imdb = "IMDB Rating: " + response.data.imdbRating;
var rotten = "Rotten Tomatoes Rating: " + response.data.Metascore;
var country = "Country: " + response.data.Country;
var language = "Language: " + response.data.Language;
var plot = "Plot: " + response.data.Plot;
var cast = "Cast: " + response.data.Actors;
var output = title + "\n" + year + "\n" + imdb + "\n" + rotten + "\n" + country + "\n" + language + "\n" + plot + "\n" + cast;
console.log(output);
logData(output);
}
);
};
// concert-this
function concertThis(artist) {
if (!artist) {
artist = "Adam Lambert";
}
axios.get("https://rest.bandsintown.com/artists/" + artist + "/events?app_id=codingbootcamp")
.then(
function (response) { logConcerts(response) }
)
.catch(function (err) {
console.log(err);
});
};
function logConcerts(response) {
const array = response.data;
for (let index = 0; index < array.length; index++) {
var path = response.data[index];
var group = path.lineup;
var venue = path.venue.name;
var location = path.venue.city + ", " + path.venue.country;
// * Date of the Event (use moment to format this as "MM/DD/YYYY")
var date = moment(path.datetime).format("MM/DD/YYYY");
var output = "Artist: " + group + "\nVenue: " + venue + "\nLocale: " + location + "\nDate: " + date + "\n-----";
console.log(output);
logData(output);
}};
// do-what-it-says
function doWhatItSays() {
fs.readFile('./random.txt', 'utf8', function (err, data) {
if (err) throw err;
var action = getAction(data);
function getAction(data) {
return data.split(",").slice(0, 1);
}
var song = getSong(data);
function getSong(data) {
return data.split(",").slice(1);
}
spotifyThisSong(song);
// searchType(action, song);
});
};
function spotifyThisSong(songTitle) {
var Spotify = require('node-spotify-api');
var keys = require("./keys.js");
var spotify = new Spotify(keys.spotify);
if (!songTitle) {
songTitle = "The Sign Ace of Base";
}
spotify.search({
type: 'album,artist,track',
query: songTitle,
limit: 1
})
.then(function (response) {
var path = response.tracks.items[0];
var artist = path.artists[0].name;
var song = path.name;
var link = path.preview_url;
var album = path.album.name;
var output = "Artist: " + artist + "\nSong: " + song + "\nPreview: " + link + "\nAlbum: " + album;
console.log(output);
logData(output);
})
.catch(function (err) {
console.log(err);
});
}
function logData(data) {
fs.appendFile('log.txt', data + "\n", function (err) {
if (err) throw err;
// console.log('Saved!');
});
}
searchType(getSearchType(), getSearchTerm());
logData("\nRequest: " + process.argv.slice(2));