Created
January 9, 2022 11:39
-
-
Save AbhinavMadahar/f04cb4dd6c981930a0f441dd2229944a to your computer and use it in GitHub Desktop.
19hz shows library
This file contains 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
import { parse } from 'node-html-parser'; | |
import fetch from 'node-fetch'; | |
export default async (location) => { | |
try { | |
const page = await fetch(`https://19hz.info/eventlisting_${location}.php`); | |
const parsed = parse(await page.text()); | |
const rows = parsed.querySelector('tbody').childNodes.slice(1).map(tr => tr.childNodes); | |
const shows = rows | |
.map(row => row.map(td => td.childNodes.reduce((prev, curr) => prev + curr.rawText, ''))) | |
.map(show => ({ | |
'Date/Time': show[0], | |
'Event Title @ Venue': show[1], | |
'Tags': show[2], | |
'Organizers': show[3], | |
'Links': show[4], | |
})); | |
return shows; | |
} catch (e) { | |
throw `Incorrect location provided: ${location}`; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment