-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliri.js
168 lines (155 loc) · 4.07 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
167
168
require("dotenv").config();
const axios = require("axios");
var moment = require("moment");
var keys = require("../Liri/keys");
var Twitter = require("twitter");
var client = new Twitter(keys.twitterKeys);
var request = require("request");
var Spotify = require("node-spotify-api");
var fs = require("fs");
// var client = new Twitter(keys.twitter);
var input = process.argv;
var action = input[2];
var inputs = input[3];
console.log("input is: ", input);
//Switch statement to switch between environment
switch (action) {
case "concert-this":
bandsInTown(inputs);
break;
case "my-tweets":
twitter(inputs);
break;
case "spotify-this-song":
spotify(inputs);
break;
case "movie-this":
movie(inputs);
break;
case "do-what-it-says":
doIt();
break;
}
function bandsInTown(inputs) {
// console.log(inputs)
var queryURL =
"https://rest.bandsintown.com/artists/" +
inputs +
"/events?app_id=codingbootcamp";
axios({
method: "get",
url: queryURL
})
.then(function(response) {
for (var i = 0; i < response.data.length; i++) {
var event = response.data[i];
console.log("------------------\n");
console.log(event.venue.name);
console.log(moment(event.datetime).format("MM/DD/YYYY"));
console.log(
event.venue.city +
", " +
event.venue.region +
", " +
event.venue.country
);
}
})
.catch(error => console.log(error));
}
function twitter(inputs) {
var params = { screen_name: inputs, count: 20 };
client.get("statuses/user_timeline", params, function(
error,
tweets,
response
) {
if (!error) {
for (i = 0; i < tweets.length; i++) {
console.log(
"Tweet: " +
"'" +
tweets[i].text +
"'" +
" Created At: " +
tweets[i].created_at
);
}
} else {
console.log(error);
}
});
}
//Spotify
function spotify(inputs) {
var spotify = new Spotify(keys.spotify);
if (!inputs) {
inputs = "The sign";
}
spotify.search(
{
type: "track",
query: inputs,
limit: 10
},
function(err, data) {
if (err) {
return console.log("Error occurred: " + err);
}
//console.log(data.tracks.items[0]);
var songInfo = data.tracks.items;
console.log("Artist(s): " + songInfo[0].artists[0].name);
console.log("Song Name:" + songInfo[0].name);
if (songInfo[0].preview_url !== null)
console.log("Preview Link:" + songInfo[0].preview_url);
console.log("Album: " + songInfo[0].album.name);
}
);
}
//IMDB
function movie(userInput) {
axios({
method: "get",
url:
"http://www.omdbapi.com/?t=" + userInput + "&y=&plot=short&apikey=trilogy"
}).then(function(response) {
console.log("response is:", response);
var movieResult = `/n
Title: ${response.data.Title}
Released: ${response.data.Year}
IMDB Rating: ${response.data.imdbRating}
Rotten Tomatos Rating: ${response.data.Ratings[1].Value}
Country: ${response.data.Country}
Language: ${response.data.Language}
Plot: ${response.data.Plot}
Actors: ${response.data.Actors}
`;
console.log(movieResult);
dataLog(movieResults);
});
}
function doIt() {
fs.readFile("random.txt", "utf8", function(error, data) {
var coolArr = data.split(",");
if (coolArr.length === 2) {
spotify(coolArr[1]);
} else if (coolArr.length < 2) {
console.log("Need more info before completing your request!!!");
} else {
console.log(error);
}
});
}
// BONUS
// In addition to logging the data to your terminal/bash window, output the data to a .txt file called log.txt.
// Make sure you append each command you run to the log.txt file.
// Do not overwrite your file each time you run a command.
function writeToLog(printInfo) {
fs.appendFile("log.txt", printInfo, function(err) {
// If the code experiences any errors it will log the error to the console.
if (err) {
return console.log(err);
}
});
}
writeToLog();