Created
August 14, 2017 01:33
-
-
Save JakeGinnivan/408db56ea9c4402dd10a8870d66e0edf to your computer and use it in GitHub Desktop.
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
| import cheerio from 'cheerio' | |
| export const fetchAgenda = () => { | |
| return fetch('http://ndcsydney.com/agenda') | |
| .then(r => r.text()) | |
| .then(body => { | |
| const talks = [] | |
| const $ = cheerio.load(body) | |
| $('section.day').map((i, el) => { | |
| // prettier-ignore | |
| const dayElements = el.childNodes | |
| .filter(c => c.type === 'tag')[0] | |
| .children | |
| .filter(c => c.type === 'tag') | |
| for (var index = 0; index < dayElements.length / 2; index += 2) { | |
| const slotEl = cheerio(dayElements[index]) | |
| const talkSlot = slotEl.text().split(' - ') | |
| const startParts = talkSlot[0].split(':') | |
| const endParts = talkSlot[1].split(':') | |
| const startTime = { hour: Number(startParts[0]), minutes: Number(startParts[1]) } | |
| const endTime = { hour: Number(endParts[0]), minutes: Number(endParts[1]) } | |
| cheerio(dayElements[index + 1]).find('.boxed-talk').each((j, talkEl) => { | |
| const $talk = cheerio(talkEl) | |
| const tags = talkEl.attribs['data-slugs'].split(',') | |
| const link = talkEl.attribs.href | |
| const location = $talk.find('.venue').text() | |
| const title = $talk.find('h2').text() | |
| const speaker = $talk.find('.speaker').text() | |
| talks.push({ | |
| title, | |
| speaker, | |
| location, | |
| link, | |
| tags, | |
| startTime, | |
| endTime | |
| }) | |
| }) | |
| } | |
| }) | |
| return talks | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment