-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
653788a
commit acb8992
Showing
9 changed files
with
691 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.DS_Store | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,30 @@ | ||
# liri-bot | ||
# liri-node-app | ||
|
||
#Liri Search Bot# | ||
|
||
This node application at it's core is a simple SWITCH CASE statement. From the command line run the liri.js file as you would any other Node.js and provide it with any of the following commands then a search term as noted below: | ||
|
||
Commands & Filter: | ||
* "*concert-this*" *Artist* | ||
- Will call the Bands In Town API and return the first result of a concert matching the artist that you entered. | ||
|
||
- "*spotify-this-song*" *Song* | ||
- Will call the Spotify API and return the first result matching the song you entered. | ||
|
||
- "*movie-this*" *Movie* | ||
- Will call the IMBD API and display the details of the movie you searched for. | ||
|
||
- "*do-what-it-says*" n/a | ||
- No search filter accepted, just call liri.js with this command and it will read in a search term from the file "random.txt" and search Spotify for the term that was read into the file. Random.txt is structured as a comma delimited file so the search term is always idex 1 on the array created using the javascript "split()" function. | ||
|
||
All entered commands are logged to the comma delimited log.txt file so that it can be easily read into an array later if desired. You'll need to strip off the trailing ",". | ||
|
||
|
||
Dependancies: | ||
- fs | ||
- moment | ||
- axios | ||
- node-spotify-api | ||
|
||
The successful Commands called in iTerm | ||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//console.log('this is loaded'); | ||
|
||
exports.spotify = { | ||
id: process.env.SPOTIFY_ID, | ||
secret: process.env.SPOTIFY_SECRET | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// required libraries | ||
require("dotenv").config(); | ||
let fs = require("fs"); | ||
let moment = require("moment"); | ||
let axios = require("axios"); | ||
const keys = require("./keys.js"); | ||
const Spotify = require("node-spotify-api"); | ||
let spotify = new Spotify(keys.spotify); | ||
|
||
//pull in required variables | ||
const spotifyTest = process.env.SPOTIFY_ID; | ||
let command = process.argv[2]; | ||
let searchTerm = process.argv[3]; | ||
|
||
fs.appendFile("log.txt", `${command},`, err => { | ||
if (err) throw err; | ||
}); | ||
|
||
switch (command) { | ||
case "concert-this": //bands in town | ||
searchForBandsInTown(searchTerm); | ||
break; | ||
case "spotify-this-song": //spotify | ||
spotifyThisSong(searchTerm); | ||
break; | ||
case "movie-this": // OMDB for movies | ||
movieThis(searchTerm); | ||
break; | ||
case "do-what-it-says": // read commands from a file and excute the commands above | ||
doRandom(); | ||
break; | ||
} | ||
|
||
function searchForBandsInTown(artist) { | ||
const queryUrl = `https://rest.bandsintown.com/artists/${artist}/events?app_id=codingbootcamp`; | ||
axios | ||
.get(queryUrl) | ||
.then(({ data }) => { | ||
if (data[0].venue != undefined) { | ||
console.log(`Event Veunue: ${data[0].venue.name}`); | ||
console.log(`Event Location: ${data[0].venue.city}`); | ||
const eventDateTime = moment(data[0].datetime); | ||
console.log( | ||
`Event Date & Time: ${eventDateTime.format("dddd, MMMM Do YYYY")}` | ||
); | ||
} else { | ||
console.log("No results found."); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
}); | ||
} | ||
|
||
function spotifyThisSong(song) { | ||
spotify | ||
.search({ type: "track", query: song }) | ||
.then(({ tracks }) => { | ||
if (tracks.total === 0) { | ||
errorConditionForSpotify(); | ||
} else { | ||
console.log(`Artist: ${tracks.items[0].artists[0].name}`); | ||
console.log(`Track: ${tracks.items[0].name}`); | ||
console.log(`Preview URL: ${tracks.items[0].preview_url}`); | ||
console.log(`Album: ${tracks.items[0].album.name}`); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
console.log( | ||
"No Results found. Showing results for 'The Sign' by Ace of Base" | ||
); | ||
}); | ||
} | ||
|
||
function errorConditionForSpotify() { | ||
spotify | ||
.search({ type: "track", query: "The Sign" }) | ||
.then(({ tracks }) => { | ||
for (let i = 0; i < tracks.items.length; i++) { | ||
if (tracks.items[i].artists[0].name === "Ace of Base") { | ||
console.log(`Artist: ${tracks.items[i].artists[0].name}`); | ||
console.log(`Track: ${tracks.items[i].name}`); | ||
console.log(`Preview URL: ${tracks.items[i].preview_url}`); | ||
console.log(`Album: ${tracks.items[i].album.name}`); | ||
i = tracks.items.length; | ||
} | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error); | ||
console.log("No Results found. "); | ||
}); | ||
} | ||
|
||
function movieThis(movie) { | ||
axios | ||
.get( | ||
`http://www.omdbapi.com/?t=${movie}&y=&plot=short&tomatoes=true&apikey=trilogy` | ||
) | ||
.then( | ||
({ data }) => { | ||
//console.log(response.data); | ||
if (data.Title != undefined) { | ||
console.log(`Title: ${data.Title}`); | ||
console.log(`Year: ${data.Year}`); | ||
console.log(`imdbRating:: ${data.imdbRating}`); | ||
console.log(`Title: ${data.Title}`); | ||
console.log(`Country:: ${data.Country}`); | ||
console.log(`Language:: ${data.Language}`); | ||
console.log(`Plot: ${data.Plot}`); | ||
console.log(`Actors: ${data.Actors}`); | ||
console.log(`RottenTomatoes: ${data.tomatoRating}`); | ||
} else { | ||
movieThis("Mr. Nobody"); | ||
} | ||
} | ||
// if response is empty call the api again with the "default" movie | ||
) | ||
.catch(error => { | ||
console.log(error); | ||
console.log("No Results found. "); | ||
}); | ||
} | ||
|
||
function doRandom() { | ||
fs.readFile("random.txt", "utf8", (error, data) => { | ||
const dataArr = data.split(","); | ||
spotifyThisSong(dataArr[1]); | ||
// If the code experiences any errors it will log the error to the console. | ||
if (error) { | ||
return console.log(error); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
do-what-it-says,spotify-this-song,concert-this,concert-this,concert-this,concert-this,concert-this,concert-this,spotify-this-song,spotify-this-song,spotify-this-song,spotify-this-song,concert-this,spotify-this-song,spotify-this-song,spotify-this-song,movie-this,movie-this,do-what-it-says, |
Oops, something went wrong.