<commit_before>'use strict';

var express = require('express');
var app = express();
var mongoose = require('mongoose');
var request = require('request');
var cheerio = require('cheerio');
var bodyParser = require('body-parser');
var logger = require('morgan');
var port = process.env.PORT || 7575;
var routes;

var environment = process.env.NODE_ENV;

var dbUrl = environment === 'build' ? 'mongodb://public:<EMAIL>:63892/scrape' : 'mongodb://localhost/scrape';

mongoose.connect(dbUrl);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
    console.log('connected to mongo...');
    var ebaySchema = mongoose.Schema({
        shop : String,
        category : String,
        url : String,
        checked : Boolean
    }, {collection : 'ebay'});
    var Ebay = mongoose.model('Ebay', ebaySchema);

    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(bodyParser.json());
    app.use(logger('dev'));

    var api = '/api';
    app.get(api + '/categories', getCats);
    app.post('/api/scrape', scrape);

    function getCats(req, res, next) {
        Ebay.find({}).sort({shop: 1}).exec(function(err, docs) {
            res.json({docs: docs});
        });
    }

    function scrape(req, res) {
        request(req.body.url, function(err, response, html) {
            if (err) { throw err; }
            var $ = cheerio.load(html);
            req.body.listTitle = $('body').find('li.sresult.lvresult.clearfix').first().find('h3.lvtitle').text().replace(/\s\s+/g, ' ');
            req.body.listPrice = $('body').find('li.sresult.lvresult.clearfix').first().find('.lvprice.prc').text().replace(/\s\s+/g, ' ');
            req.body.listHref = $('body').find('li.sresult.lvresult.clearfix').first().find('a.vip').attr('href');

            res.json(req.body);
        });
    }

    console.log('About to crank up node');
    console.log('PORT=' + port);
    console.log('NODE_ENV=' + environment);

    switch (environment) {
        case 'build':
            console.log('** BUILD **');
            app.use(express.static('./build/'));
            app.use('/*', express.static('./build/index.html'));
            break;
        default:
            console.log('** DEV **');
            app.use(express.static('./src/client/'));
            app.use(express.static('./'));
            app.use(express.static('./tmp'));
            app.use('/*', express.static('./src/client/index.html'));<commit_msg>changed CSS selectors for new ebay site design<commit_after>'use strict';

var express = require('express');
var app = express();
var mongoose = require('mongoose');
var request = require('request');
var cheerio = require('cheerio');
var bodyParser = require('body-parser');
var logger = require('morgan');
var port = process.env.PORT || 7575;
var routes;

var environment = process.env.NODE_ENV;

var dbUrl = environment === 'build' ? 'mongodb://public:<EMAIL>:63892/scrape' : 'mongodb://localhost/scrape';

mongoose.connect(dbUrl);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
    console.log('connected to mongo...');
    var ebaySchema = mongoose.Schema({
        shop : String,
        category : String,
        url : String,
        checked : Boolean
    }, {collection : 'ebay'});
    var Ebay = mongoose.model('Ebay', ebaySchema);

    app.use(bodyParser.urlencoded({
        extended: true
    }));
    app.use(bodyParser.json());
    app.use(logger('dev'));

    var api = '/api';
    app.get(api + '/categories', getCats);
    app.post('/api/scrape', scrape);

    function getCats(req, res, next) {
        Ebay.find({}).sort({shop: 1}).exec(function(err, docs) {
            res.json({docs: docs});
        });
    }

    function scrape(req, res) {
        request(req.body.url, function(err, response, html) {
            //console.log(req.body.url);
            if (err) { throw err; }
            var $ = cheerio.load(html);
            req.body.listTitle = $('body').find('li.s-item').first().find('h3.s-item__title').text().replace(/\s\s+/g, ' ');
            req.body.listPrice = $('body').find('li.s-item').first().find('.s-item__price').text().replace(/\s\s+/g, ' ');
            req.body.listHref = $('body').find('li.s-item').first().find('a.s-item__link').attr('href');

            console.log(req.body.listTitle);

            res.json(req.body);
        });
    }

    console.log('About to crank up node');
    console.log('PORT=' + port);
    console.log('NODE_ENV=' + environment);

    switch (environment) {
        case 'build':
            console.log('** BUILD **');
            app.use(express.static('./build/'));
            app.use('/*', express.static('./build/index.html'));
            break;
        default:
            console.log('** DEV **');
            app.use(express.static('./src/client/'));
            app.use(express.static('./'));
            app.use(express.static('./tmp'));
            app.use('/*', express.static('./src/client/index.html'));
{'fraction_non_alphanumeric': 0.20302672955974843, 'fraction_numerical': 0.004323899371069182, 'mean_word_length': 2.6454154727793697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3695657', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1580, 'n_words': 282}