Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

KQ92 - KQRS

node v10.24.1
version: 1.0.0
endpointsharetweet
const fetch = require("node-fetch"); const URL = 'https://api.tunegenie.com/v2/brand/nowplaying/?apiid=m2g_bar&b=kqrs&count=1'; const fetchNowPlaying = async () => { const response = await fetch(URL); if (!response.status === 200) { // todo - wire up some kind of error reporting/monitoring const err = await response.text(); throw Error('Unable to fetch current song for KQRS: ' + err); } let responseData = response.json(); if (Array.isArray(responseData)) { responseData = responseData[0]; } const songInfo = { artist: responseData.artist, songTitle: responseData.song, 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