<commit_before>// libs
const OneSignal = require('node-onesignal').default;
const {flag, code, name} = require('country-emoji');
const jsonfile = require('jsonfile');
const Twitter = require('twitter');

// setup twitter
const clientTwitter = new Twitter({
    consumer_key: process.env.TWITTER_CONSUMER_KEY,
    consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
    access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
    access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});

// setup onesignal
const client = new OneSignal(process.env.ONESIGNAL_APPID, process.env.ONESIGNAL_KEY);

// file name
const lastFile = 'last.json';
const submissionFile = 'submission.json';
const jsonFile = 'contents.json';

// get file content
const lastContent = jsonfile.readFileSync(lastFile);

// read json file
const json = jsonfile.readFileSync(submissionFile);

// last repo found
var lastConference = "";

// new conferences
var newConferences = [];

// loop
var startCounting = false;
json.conferences.forEach(function(item) {

    // convert flags
    item.emojiflag = flag(item.country);

    if(item.country === 'Vietnam') {
      item.emojiflag = '🇻🇳';
    }

    //console.log(item);
    if(startCounting === true) {
        lastConference = item.homepage;
        newConferences.push(item);
        // set this conference as new
        item.isnew = true;

    } else {
        // set all the other conf as old
        item.isnew = false;
    }

    if(item.homepage === lastContent.last) {
        startCounting = true;
    }
});


//console.log(totalNew);

if(newConferences.length > 0) {
    var message = '';

    if(newConferences.length === 1) {
        message = '🎫 ' + newConferences.length + ' new mobile conference ('+ newConferences[0].title +'), check it out!';
    } else {
        const confNames = newConferences.reduce(function(last, conference) {
            return last+", "+conference.title;
        });
        message = '🎫 ' + newConferences.length + ' new mobile conferences ('+ confNames +'), check them out!';
    }

    // send push
    client.sendNotification(message, {
        included_segments: "Active Users"
    });


    newConferences.forEach(function(conf) {
        // prepare message
        const twitterMessage =  conf.flag+' ' + conf.title + ' ( '+ conf.twitter +' ) will be between '+ conf.start +' and '+ conf.end +' in '+ conf.city +' 🎫 #awesomemobileconference';
        // send twitter
        clientTwitter.post('statuses/update', {status: twitterMessage }, function(error, tweet, response) {
            if (!error) {
                console.log(tweet);
            } else {
                console.log(error);
            }
        });
    });<commit_msg>fix script for pushes<commit_after>// libs
const OneSignal = require('node-onesignal').default;
const {flag, code, name} = require('country-emoji');
const jsonfile = require('jsonfile');
const Twitter = require('twitter');

// setup twitter
const clientTwitter = new Twitter({
    consumer_key: process.env.TWITTER_CONSUMER_KEY,
    consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
    access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
    access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});

// setup onesignal
const client = new OneSignal(process.env.ONESIGNAL_APPID, process.env.ONESIGNAL_KEY);

// file name
const lastFile = 'last.json';
const submissionFile = 'submission.json';
const jsonFile = 'contents.json';

// get file content
const lastContent = jsonfile.readFileSync(lastFile);

// read json file
const json = jsonfile.readFileSync(submissionFile);

// last repo found
var lastConference = "";

// new conferences
var newConferences = [];

// loop
var startCounting = false;
json.conferences.forEach(function(item) {

    // convert flags
    item.emojiflag = flag(item.country);

    if(item.country === 'Vietnam') {
      item.emojiflag = '🇻🇳';
    }

    //console.log(item);
    if(startCounting === true) {
        lastConference = item.homepage;
        newConferences.push(item);
        // set this conference as new
        item.isnew = true;

    } else {
        // set all the other conf as old
        item.isnew = false;
    }

    if(item.homepage === lastContent.last) {
        startCounting = true;
    }
});


//console.log(totalNew);

if(newConferences.length > 0) {
    var message = '';

    if(newConferences.length === 1) {
        message = '🎫 ' + newConferences.length + ' new mobile conference ('+ newConferences[0].title +'), check it out!';
    } else {
        var confNames = "";
        newConferences.forEach(function(conf){
            confNames = confNames + ", "+ conf.title;
        });
        message = '🎫 ' + newConferences.length + ' new mobile conferences ('+ confNames +'), check them out!';
    }

    // send push
    client.sendNotification(message, {
        included_segments: "Active Users"
    });


    newConferences.forEach(function(conf) {
        // prepare message
        const twitterMessage =  conf.emojiflag+' ' + conf.title + ' ( '+ conf.twitter +' ) will be between '+ conf.startdate +' and '+ conf.enddate +' in '+ conf.city +' 🎫 #awesomemobileconference';
        // send twitter
        clientTwitter.post('statuses/update', { status: twitterMessage }, function(error, tweet, response) {
            if (!error) {
                console.log(tweet);
            } else {
                console.log(error);
            }
        });
    });
{'fraction_non_alphanumeric': 0.13500641143066497, 'fraction_numerical': 0.001099102399706906, 'mean_word_length': 2.8342696629213484, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4973091', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1664, 'n_words': 364}