Last active
May 17, 2018 20:38
-
-
Save joewright/ee7aa735ef73d90ecf8442c08171d968 to your computer and use it in GitHub Desktop.
Reverb nation check upcoming shows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// made this because I got tired of trying to scroll on a website that used this widget. | |
// only tested on node 10.1.0 | |
'use strict'; | |
var TINROOF_WIDGET_URL = 'https://www.reverbnation.com/widget_code/html_widget/venue_1008205?widget_id=52'; | |
var https = require('https'); | |
// allow optional `--json` arg to just display the json; | |
var handler = displayData; | |
if (process.argv[2] === '--json') { | |
handler = saveJson; | |
} | |
getData(handler); | |
function getData(onDataLoaded) { | |
// make an HTTP request to get the widget HTML | |
https | |
.request(TINROOF_WIDGET_URL, function(res) { | |
res.setEncoding('utf8'); | |
var response = ''; | |
res.on('data', function(chunk) { | |
response += chunk; | |
}); | |
res.on('end', function() { | |
onDataLoaded(parseHTML(response)); | |
}); | |
}) | |
.on('error', function(err) { | |
console.error(`something blew up: ${err.message}`); | |
}) | |
.end(); | |
} | |
function saveJson(data) { | |
// gotta show those performers | |
console.dir(data, {depth: 3}); | |
} | |
function parseHTML(txt) { | |
// parse the widget html for the json payload; parse the json too | |
txt = txt | |
.split('<script type="application/ld+json">') | |
.pop() | |
.split('</script>') | |
.shift() | |
.trim(); | |
return JSON.parse(txt); | |
} | |
function displayData(data) { | |
data.forEach(function(event) { | |
console.log(` | |
Name: ${event.name} | |
Performer: ${event.performer.map(formatPerformer).join()} | |
Date: ${event.startDate} | |
Link: ${event.url}`); | |
}); | |
} | |
function formatPerformer(performer) { | |
return performer.name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment