untitled notebook

node v10.24.1
version: 1.0.0
endpointsharetweet
const fetch = require("node-fetch"); const cheerio = require("cheerio"); const URL = 'https://www.radio.com/1041jackfm/listen'; const fetchNowPlaying = async () => { const response = await fetch(URL); const text = await response.text(); const $ = cheerio.load(text); const parent = $('.show__details').first(); const title = parent.children('.details__title').text(); const artist = parent.children('.details__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)); }
Loading…

no comments

    sign in to comment