<commit_before>var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var sqlite3 = require("sqlite3").verbose();
var db = new sqlite3.Database('database_hofc.db');
var CronJob = require('cron').CronJob
var parser = require('./parser_node_module.js');
var http = require('http');
var pg = require('pg');

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set('port', (process.env.PORT || 3000));


var creation_table_notification_query = "CREATE TABLE IF NOT EXISTS notification_client (id serial PRIMARY KEY , uuid varchar(255) NOT NULL, notification_id varchar(255) NOT NULL)";

var job = new CronJob('0 */15 * * * *', function(){
      console.log('Update database start');
      parser.updateDatabase(pg);
  }, function () {
    
  },
  true // Start the job right now 
);

app.get('/classement', function(req, res){
    console.log('Classement Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from classement order by points desc, diff desc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting classement : ' + err);
                return;
            }
            res.send(results.rows);
        })
    })
});

app.get('/calendrier', function(req, res){
	console.log('Calendrier Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from calendrier order by date asc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting calendrier : ' + err);
                return;
            }
            res.send(results.rows);
        })
    })
});

app.get('/actus', function(req, res){
	console.log('Actus Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from actus  order by date desc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting actus : ' + err);
                return;
            }
            res.send(results.rows);
        })
    })
});

app.post('/parsePage', function(req, res) {
    console.log('url page : ' + req.body.url);
    var url = req.body.url;
    if(url.indexOf('en-images') != -1) {
        parser.parseDiaporama(url, function(resultats) {
            res.send(resultats);<commit_msg>Add Content Type header<commit_after>var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var sqlite3 = require("sqlite3").verbose();
var db = new sqlite3.Database('database_hofc.db');
var CronJob = require('cron').CronJob
var parser = require('./parser_node_module.js');
var http = require('http');
var pg = require('pg');

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set('port', (process.env.PORT || 3000));


var creation_table_notification_query = "CREATE TABLE IF NOT EXISTS notification_client (id serial PRIMARY KEY , uuid varchar(255) NOT NULL, notification_id varchar(255) NOT NULL)";

var job = new CronJob('0 */15 * * * *', function(){
      console.log('Update database start');
      parser.updateDatabase(pg);
  }, function () {
    
  },
  true // Start the job right now 
);

app.get('/classement', function(req, res){
    console.log('Classement Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from classement order by points desc, diff desc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting classement : ' + err);
                return;
            }
            res.set('Content-Type', 'application/json; charset=utf-8');
            res.send(results.rows);
        })
    })
});

app.get('/calendrier', function(req, res){
	console.log('Calendrier Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from calendrier order by date asc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting calendrier : ' + err);
                return;
            }
            res.set('Content-Type', 'application/json; charset=utf-8');
            res.send(results.rows);
        })
    })
});

app.get('/actus', function(req, res){
	console.log('Actus Request');
    pg.connect(process.env.DATABASE_URL, function(err, client, done){
        if(err) {
            console.error('Error while connecting to database', err);
        }
        client.query('select * from actus  order by date desc', function(err, results){
            done();
            if(err) {
                console.error('Error while getting actus : ' + err);
                return;
            }
            res.set('Content-Type', 'application/json; charset=utf-8');
            res.send(results.rows);
        })
    })
});

app.post('/parsePage', function(req, res) {
    console.log('url page : ' + req.body.url);
    var url = req.body.url;
    if(url.indexOf('en-images') != -1) {
        parser.parseDiaporama(url, function(resultats) {
            res.send(resultats);
{'fraction_non_alphanumeric': 0.15069444444444444, 'fraction_numerical': 0.006423611111111111, 'mean_word_length': 2.527862829148806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1152397', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1660, 'n_words': 391}