<commit_before>const { create, run } = require('rung-sdk');
const { Money, String: Text } = require('rung-sdk/dist/types');
const Bluebird = require('bluebird');
const agent = require('superagent');
const promisifyAgent = require('superagent-promise');
const { map, pipe, prop } = require('ramda');

const request = promisifyAgent(agent, Bluebird);

const token = '<<<<YOUR TOKEN HERE>>>>';
const sourceId = '<<<<YOUR SOURCE ID HERE>>>>';
const server = `http://sandbox.buscape.com.br/service/findProductList/lomadee/${token}/BR/?sourceId=${sourceId}&app-token=${token}&format=json&program=lomadee`;
//Se more in http://developer.buscape.com.br/portal/lomadee/api-de-ofertas/recursos#lista-de-produtos

function createAlert({ productshortname, pricemin }) {
    return `${productshortname} no preço mínimo de R$ ${pricemin}`
}

function main(context, done) {
    const { item, value } = context.params;

    return request.get(`${server}&keyword=${item}&priceMax=${value}`)
        .then(({ body }) => {
            const products = body.product;
            const alerts = map(pipe(prop('product'), createAlert), products);
            done(alerts);
        });
}

const params = {
    item: {
        description: 'Informe o produto que você está procurando (Ex: TV):',
        type: Text,
        default: 'TV'
    },
    value: {
        description: 'O valor do produto deve ser inferior a:',
        type: Money,
        default: 500
    }
};

const app = create(main, { params });
app.run();

module.exports = app;<commit_msg>Empty alerts on error and remove { run }<commit_after>const { create } = require('rung-sdk');
const { Money, String: Text } = require('rung-sdk/dist/types');
const Bluebird = require('bluebird');
const agent = require('superagent');
const promisifyAgent = require('superagent-promise');
const { map, pipe, prop } = require('ramda');

const request = promisifyAgent(agent, Bluebird);

const token = '<<<<YOUR TOKEN HERE>>>>';
const sourceId = '<<<<YOUR SOURCE ID HERE>>>>';
const server = `http://sandbox.buscape.com.br/service/findProductList/lomadee/${token}/BR/?sourceId=${sourceId}&app-token=${token}&format=json&program=lomadee`;
//Se more in http://developer.buscape.com.br/portal/lomadee/api-de-ofertas/recursos#lista-de-produtos

function createAlert({ productshortname, pricemin }) {
    return `${productshortname} no preço mínimo de R$ ${pricemin}`
}

function main(context, done) {
    const { item, value } = context.params;

    return request.get(`${server}&keyword=${item}&priceMax=${value}`)
        .then(({ body }) => {
            const products = body.product;
            const alerts = map(pipe(prop('product'), createAlert), products);
            done(alerts);
        })
        .catch(() => done([]));
}

const params = {
    item: {
        description: 'Informe o produto que você está procurando (Ex: TV):',
        type: Text,
        default: 'TV'
    },
    value: {
        description: 'O valor do produto deve ser inferior a:',
        type: Money,
        default: 500
    }
};

const app = create(main, { params });

module.exports = app;
{'fraction_non_alphanumeric': 0.16731016731016732, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 3.5991124260355027, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2285882', 'n_tokens_mistral': 1010, 'n_tokens_neox': 975, 'n_words': 236}