Act

dbh/game-stats

  • Builds
  • latest 0.0.16 / 2017-12-26
  • Created 2017-12-26
  • Last modified 2017-12-26
  • grade 2

Description

get the stats for a game


API

To run the act, send a HTTP POST request to:

https://api.apify.com/v2/acts/dbh~game-stats/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the act. For more information, read the docs.


Example input

Content type: application/json; charset=utf-8

{"gameIds": [
  2017122407, 
  2017122402
]}

Source code

Based on the apify/actor-node-basic Docker image (see docs).

const Apify = require('apify');
const request = require('request-promise');

Apify.main(async () => {
    // Get input of your act
    const input = await Apify.getValue('INPUT');
    console.log('My input:');
    console.dir(input);

    // Do something useful here
    const responseArray = await Promise.all(input.gameIds.map(gameId => {
        return request('http://www.nfl.com/liveupdate/game-center/' + gameId + '/' + gameId + '_gtd.json')
    }));
    
    const output = responseArray.reduce((obj, item) => {
        const gameStats = JSON.parse(item)
        const gameId = Object.keys(gameStats)[0];
        obj[gameId] = gameStats[gameId];
        return obj;
    }, {})
    
    console.log('My output:');
    console.dir(output);
    await Apify.setValue('OUTPUT', output);
});