-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliri.js
110 lines (95 loc) · 3.7 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
// Node Package Permission Variables
require("dotenv").config();
var Twitter = require('twitter');
var Spotify = require('node-spotify-api');
var keys = require('./keys.js');
var request = require('request');
var fs = require('fs');
// Argument variables
var arg2 = process.argv[2];
var arg3 = process.argv[3];
var procArg = process.argv;
var spotify = new Spotify(keys.spotify);
var client = new Twitter (keys.twitter);
var params = {screen_name: 'JKM17421117'};
//Functions
function appendFile(data) {
fs.appendFile('log.txt', '\n' + data, function(err) {
if (err) throw err;
console.log('Saved!');
})
}
function listTweets() {
client.get('statuses/user_timeline', params, function(error, tweets,) {
var allTweets = ''
if (!error) {
for (i = 0; i < tweets.length; i++) {
allTweets += ('\nTweet Text: ' + tweets[i].text + '\nTweet Date: ' + tweets[i].created_at+ '\n');
}
console.log(allTweets);
appendFile(allTweets);
}
});
}
function searchSpotify(arg) {
var songSearch = process.argv.slice(3).join(" ");
spotify.search({ type: 'track', query: songSearch }, function(err, data) {
if (err) {
spotify.search({ type: 'track', query: arg }, function(err, data) {
if (err) {
return console.log('Error occurred: ' + err);
}
var song = 'Artist Name: ' + data.tracks.items[0].album.artists[0].name + '\nTrack Title: ' + data.tracks.items[0].name + '\nPreview URL: ' + data.tracks.items[0].preview_url + '\nAlbum Title: ' + data.tracks.items[0].album.name
console.log(song)
appendFile(song)
});
}
var song = 'Artist Name: ' + data.tracks.items[0].album.artists[0].name + '\nTrack Title: ' + data.tracks.items[0].name + '\nPreview URL: ' + data.tracks.items[0].preview_url + '\nAlbum Title: ' + data.tracks.items[0].album.name
console.log(song)
appendFile(song)
});
}
function findMovie () {
var term = process.argv.slice(3).join(" ");
request('http://www.omdbapi.com/?apikey=trilogy&t=' + term, function (err, res) {
var data = JSON.parse(res.body);
var movieData = '\nTitle: ' + data.Title + '\nRelease date: '
+ data.Released + '\nRotten Tomatoes Rating: ' + data.Ratings[1].Value
+ '\nCountry: ' + data.Country + '\nLanguage: ' + data.Language + '\nPlot: '
+ data.Plot + '\nActors: ' + data.Actors;
console.log('error:', err);
console.log(movieData);
appendFile(movieData);
});
}
function doRandom () {
fs.readFile('random.txt', 'utf-8', function(err, data) {
if (err) {
return console.log(err);
}
var dataArr = data.split(',');
if (dataArr[0] === 'spotify') {
console.log(dataArr[1]);
searchSpotify(dataArr[1]);
} else if (dataArr[0] === 'my-tweets') {
listTweets();
}
});
}
//Code execute
if (arg2 === 'my-tweets') {
listTweets();
} else if (arg2 === 'spotify' && arg3 === undefined) {
searchSpotify('The Sign Ace of the Base');
} else if (arg2 === 'spotify' && arg3 != undefined) {
searchSpotify(arg3);
} else if (arg2 === 'movies' && arg3 != undefined) {
findMovie();
} else if (arg2 === 'movies' && arg3 === undefined) {
findMovie('Mr. Nobody');
} else if (arg2 === 'do-random' && arg3 === undefined) {
doRandom();
}
// * 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.