Created
February 4, 2020 18:02
-
-
Save hubgit/2adc09ee0079fc08b2c4e5634f457eab to your computer and use it in GitHub Desktop.
Average UK weekly television viewing figures from BARB
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
| 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