Skip to content

Instantly share code, notes, and snippets.

@JakeGinnivan
Created August 13, 2017 04:52
Show Gist options
  • Select an option

  • Save JakeGinnivan/ac655631bb7ad9b58500e8e22a50fa89 to your computer and use it in GitHub Desktop.

Select an option

Save JakeGinnivan/ac655631bb7ad9b58500e8e22a50fa89 to your computer and use it in GitHub Desktop.

Revisions

  1. JakeGinnivan created this gist Aug 13, 2017.
    59 changes: 59 additions & 0 deletions agenda.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    import * as cheerio from 'cheerio'

    export type Time = {
    hour: number
    minutes: number
    }

    export type Talk = {
    startTime: Time
    endTime: Time
    title: string
    speaker: string
    location: string
    link: string
    tags: string[]
    }

    export const fetchAgenda = async () => {
    const response = await fetch('http://ndcsydney.com/agenda')
    const body: string = await response.text()
    const talks: Talk[] = []

    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: Time = { hour: Number(startParts[0]), minutes: Number(startParts[1]) }
    const endTime: Time = { 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
    }