Last active
January 14, 2022 00:41
-
-
Save mikefrey/ad341efbf6b5803d33f7f836a533711f to your computer and use it in GitHub Desktop.
OpusData session issue
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
const SESSION_ID = '<INSERT SESSION ID HERE>' | |
const URL = require('url') | |
const URLSearchParams = URL.URLSearchParams | |
const https = require('https') | |
async function doRequest(urlString, headers) { | |
const url = URL.parse(urlString) | |
const options = { | |
hostname: url.hostname, | |
port: url.port, | |
path: url.path, | |
headers: headers, | |
method: 'GET', | |
} | |
console.log('\nREQUEST HEADERS', JSON.stringify(options.headers)) | |
return new Promise((resolve, reject) => { | |
const req = https.request(options, res => { | |
console.log('\nSTATUS CODE:', res.statusCode) | |
console.log('\nRESPONSE HEADERS:', JSON.stringify(res.headers)) | |
res.setEncoding('utf8') | |
const chunks = [] | |
res.on('data', chunk => { | |
chunks.push(Buffer.from(chunk)) | |
}) | |
res.on('end', () => { | |
const payload = Buffer.concat(chunks).toString('utf8') | |
try { | |
const data = JSON.parse(payload) | |
resolve({resp: res, data}) | |
} catch(err) { | |
reject(err) | |
} | |
}) | |
}) | |
req.on('error', err => { | |
reject(err) | |
}) | |
req.end() | |
}) | |
} | |
async function getMovieTheatricalChartEntries() { | |
const base = `https://data2.opusdata.com/movie_theatrical_chart_entries?` | |
const query = new URLSearchParams({ | |
merge: 'movie_chart_type', | |
fields: '*', | |
filter: `chart_date='2021-12-17' AND movie_chart_type.display_name='Weekend'`, | |
order: 'rank', | |
limit: '1000' | |
}) | |
const url = base+query.toString() | |
const headers = { | |
Authorization: SESSION_ID | |
} | |
const {resp, data} = await doRequest(url, headers) | |
return data | |
} | |
async function main() { | |
const data = await getMovieTheatricalChartEntries() | |
console.log(data) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment