-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliri.js
147 lines (120 loc) · 3.51 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
var twitterKeys = require('./keys.js');
twitterKeys = twitterKeys.twitterKeys;
var fs = require('fs');
var spotify = require('spotify');
var Twitter = require('twitter');
var request = require('request');
var command = process.argv[2];
main(command);
function main(mode, q) {
switch (mode) {
case 'my-tweets':
fs.appendFile('./log.txt', '\nmy-tweets:\n', 'utf8', (err) => {if (err) throw err;});
getTweets();
break;
case 'spotify-this-song':
fs.appendFile('./log.txt', '\nspotify-this-song:\n', 'utf8', (err) => {if (err) throw err;});
getSongs(q);
break;
case 'movie-this':
fs.appendFile('./log.txt', '\nmovie-this:\n', 'utf8', (err) => {if (err) throw err;});
getMovie(q);
break;
case 'do-what-it-says':
fs.appendFile('./log.txt', '\ndo-what-it-says:\n', 'utf8', (err) => {if (err) throw err;});
getFile();
break;
}
}
function getTweets() {
var client = new Twitter({
consumer_key: twitterKeys.consumer_key,
consumer_secret: twitterKeys.consumer_secret,
access_token_key: twitterKeys.access_token_key,
access_token_secret: twitterKeys.access_token_secret
});
var params = {
screen_name: 'morgansliman',
count: 20
};
client.get('statuses/user_timeline', params, (err, tweets, response) => {
if (err) return err;
for (var i = 0; i < tweets.length; i++) {
var data = `Tweet ${i+1}:\n${tweets[i].text}\nCreated: ${tweets[i].created_at}\n`;
console.log(data);
fs.appendFile('./log.txt', data, 'utf8', (err) => {if (err) throw err;});
}
})
}
function getSongs(q) {
if (q) {
var song = q;
}
else if (!process.argv[3]) {
var song = 'The Sign Ace of Base';
}
else {
var song = process.argv[3];
}
if (process.argv.length > 4) {
console.log('Song title must be in quotation marks.');
return;
}
spotify.search({ type: 'track', query: song }, (err, data) => {
if (err) return err;
var result = data.tracks.items[1];
var artist = result.artists[0].name;
var name = result.name;
var preview = result.preview_url;
var album = result.album.name;
var output = `\nSong: ${name}\nArtist: ${artist}\nAlbum: ${album}\nPreview: ${preview}\n`;
console.log(output);
fs.appendFile('./log.txt', output, 'utf8', (err) => {if (err) throw err;});
});
}
function getMovie(q) {
if (q) {
var movie = q;
}
else if (!process.argv[3]) {
var movie = 'Mr. Nobody';
}
else {
var movie = process.argv[3];
}
if (process.argv.length > 4) {
console.log('Movie title must be in quotation marks.');
return;
}
var url = 'https://www.omdbapi.com/?type=movie&tomatoes=true&t=' + encodeURIComponent(movie);
request(url, (err, response, body) => {
if (!err && response.statusCode == 200) {
body = JSON.parse(body);
var title = body.Title,
year = body.Year,
imdb_rating = body.imdbRating,
country = body.Country,
language = body.Language,
plot = body.Plot,
actors = body.Actors,
tomato_rating = body.tomatoRating,
tomato_url = body.tomatoURL;
var output = `\
\nTitle: ${title}\nYear: ${year}\nIMDB Rating: ${imdb_rating}\
\nCountry: ${country}\nLanguage: ${language}\nPlot: ${plot}\
\nActors: ${actors}\nRotten Tomatoes Rating: ${tomato_rating}\
\nRotten Tomatoes URL: ${tomato_url}\n`;
console.log(output);
fs.appendFile('./log.txt', output, 'utf8', (err) => {if (err) throw err;});
}
});
}
function getFile() {
fs.readFile('./random.txt', 'utf8', (err, data) => {
if (err) return err;
data = data.trim();
var command = data.split(',')[0],
query = data.split(',')[1];
main(command, query);
});
}