Skip to content

Instantly share code, notes, and snippets.

@hubgit
Created February 4, 2020 18:02
Show Gist options
  • Select an option

  • Save hubgit/2adc09ee0079fc08b2c4e5634f457eab to your computer and use it in GitHub Desktop.

Select an option

Save hubgit/2adc09ee0079fc08b2c4e5634f457eab to your computer and use it in GitHub Desktop.
Average UK weekly television viewing figures from BARB
const axios = require('axios')
const qs = require('qs')
const fs = require('fs-extra')
const thisYear = (new Date).getFullYear()
const fetch = async () => {
const years = []
for (let year = 1992; year <= thisYear; year++) {
years.push(year)
}
const body = qs.stringify({
data_series: years
}, {
arrayFormat: 'brackets'
})
const response = await axios.post(
'https://barb-api.mediatel.co.uk/trendspotting/data/average-weekly-viewing',
body
)
await fs.writeJSON('weekly-viewing-figures.json', response.data, {
spaces: 2
})
}
fetch().then(() => {
console.log('done')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment