-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
125 lines (100 loc) · 3.48 KB
/
code.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
require("dotenv").config();
var keys = require("./keys.js");
var Twitter = require('twitter');
var Spotify = require('node-spotify-api');
var fs = require("fs");
var request = require('request');
var spotify = new Spotify(keys.spotify);
var twitter = new Twitter(keys.twitter);
var LiriSearch = function () {
this.twitter = function () {
var params = { screen_name: 'addiesgjohnson', count: 20 };
twitter.get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi", params, function (error, tweets, response) {
if (!error) {
tweets = (JSON.parse(response.body));
// console.log(tweets[1].text);
for (var i = 0; i < tweets.length; i++) {
console.log(
"\nTweet: " + tweets[i].text +
"\nTweet Date: " + tweets[i].created_at
)
}
}
})
}
//twitter function ends
this.spotify = function () {
fs.readFile("random.txt", "utf8", function (error, song) {
if (error) {
return console.log(error);
}
var songData = song.slice(17);
spotify.search({ type: 'track', query: songData, limit: 1 }, function (err, data) {
if (err) {
return console.log('Error occurred: ' + err);
}
var info = data.tracks.items
console.log(
"\nArtist: " + info[0].artists[0].name +
"\nSong title: " + info[0].name +
"\nAlbum name: " + info[0].album.name +
"\nURL Preview: " + info[0].preview_url)
})
})
}//spotify ends
this.aceOfBase = function () {
spotify
.request('https://api.spotify.com/v1/tracks/3DYVWvPh3kGwPasp7yjahc')
.then(function (data) {
// console.log(JSON.stringify(data, null, 2))
var info = data.album
console.log(
"\nArtist: " + info.artists[0].name +
"\nSong title: " + data.name +
"\nAlbum name: " + info.name +
"\nURL Preview: " + data.preview_url)
})
.catch(function (err) {
console.error('Error occurred: ' + err);
});
}//aceOfBase ends
this.movie = function () {
fs.readFile("random.txt", "utf8", function (error, movie) {
if (error) {
return console.log(error);
}
console.log(movie);
var movieData = movie.slice(11);
console.log(movieData);
request("https://www.omdbapi.com/?t=" + movieData + "&y=&plot=short&apikey=trilogy", function (error, response) {
var stuff = JSON.parse(response.body);
// console.log(stuff.Error);
if (stuff.Error === 'Movie not found!') {
console.log("Movie not found - enter new request");
}
else {
array = stuff.Ratings;
console.log(stuff);
function search(nameKey, myArray) {
for (var i = 0; i < myArray.length; i++) {
if (myArray[i].Source === nameKey) {
return myArray[i];
}
}
}
var resultObject = search("Rotten Tomatoes", array);
console.log(
"\nMovie Title: " + stuff.Title +
"\nRelease Year: " + stuff.Year +
"\nIMDB Rating: " + stuff.imdbRating +
"\nRotten Tomatoes: " + resultObject.Value +
"\nCountry produced: " + stuff.Country +
"\nLanguage: " + stuff.Language +
"\nPlot: " + stuff.Plot +
"\nActors: " + stuff.Actors)
}
});
});
} //this.movie end
}; //lirisearch ends
module.exports = LiriSearch;