const fetch = require("node-fetch");
const cheerio = require("cheerio");
const URL = 'https://kool108.iheart.com/music/recently-played/';
const fetchNowPlaying = async () => {
const response = await fetch(URL);
const text = await response.text();
const $ = cheerio.load(text);
const parent = $('.track-list_item').first();
const title = parent.children('.track-title').text();
const artist = parent.children('.track-artist').text();
const songInfo = {songTitle:title, artist};
songInfo.when = new Date().getTime();
return songInfo;
};
exports.endpoint = async function(request, response) {
const songInfo = await fetchNowPlaying();
response.end(JSON.stringify(songInfo));
}