<commit_before>'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const config = require('./config')
const app = express()

var rp = require('request-promise');
var cronJob = require('cron').CronJob;

const LINENotifyToken = ''
const OMGPairID = '26'
const BTCPairID = '1'
const ETHPairID = '21'

app.set('port', (process.env.PORT || config.PORT))

app.use(bodyParser.urlencoded({extended: false}))

app.use(bodyParser.json())

app.get('/', function (req, res) {
  res.send('Meeaaww');
})

app.get('/publish', function (req, res) {
  publish();
  res.status(200).send('Meaaawww');
})

function publish() {
  var bxOptions = {
    uri: 'https://bx.in.th/api/',
    json: true
  };

  rp(bxOptions)
    .then(function ( marketdata ) {
        console.log(marketdata[OMGPairID]);

        let omgPair = marketdata[OMGPairID];
        let btcPair = marketdata[BTCPairID];
        let ethPair = marketdata[ETHPairID];

        notifyToGroup(omgPair, btcPair, ethPair);
    })
    .catch(function (err) {
        console.log(err);
    });
}

function messageGenerator( omg, btc, eth ) {
  let change = omg['change'];
  let lastPrice = omg['last_price'];
  let volumeIn24HR = omg['volume_24hours'];
  let volumeBids = omg['orderbook']['bids'];
  let volumeAsks = omg['orderbook']['asks'];
  
  let omglastPriceMSG = `Last price : ${lastPrice} THB\n`;
  let omgChangeMSG = `Change : ${change}%\n`;
  let omgVolume24MSG = `Volume24HR : ${volumeIn24HR} OMG\n`;
  let omgBidsMSG = `Highest buy: ${volumeBids.highbid} THB\n`;
  let omgAsksMSG = `Lowest sell: ${volumeAsks.highbid} THB\n`;

  let spliter = '- - - - - - - - - - - - - -\n'

  let btcLastPriceMSG = `BTC : ${btc.last_price} THB\n`;
  let ethLastPriceMSG = `ETH : ${eth.last_price} THB\n`

  let theEnd = '≧◡≦';

  return `✿OMG✿\n` + omglastPriceMSG + omgChangeMSG + omgVolume24MSG 
  + omgBidsMSG + omgAsksMSG + spliter + btcLastPriceMSG + ethLastPriceMSG
  + theEnd;
}

function notifyToGroup( omg, btc, eth ) {
  var message = messageGenerator(omg, btc, eth);

  var headers = {
    'User-Agent':       'AzukiChan/0.0.1',
    'Content-Type':     'application/x-www-form-urlencoded'
  }

  var options = {
    'url': 'https://notify-api.line.me/api/notify',
    'method': 'POST',
    'headers': headers,
    'auth': {
       'bearer': LINENotifyToken
    },
    'form': {
       'message': message
    }
  }

  rp(options)
    .then(function ( result ) {
        console.log('publish success')
    })
    .catch(function (err) {
        console.log()
    });
}

app.listen(app.get('port'), () => {
  console.log(`Running Crypty on port : ${app.get('port')}`)
  
  var job = new cronJob({
    cronTime: '* 30 * * * *',
    onTick: function() {
      // Publish every 30 min
      publish();
    },
    start: false,
    timeZone: 'Asia/Bangkok'
  });

  job.start();
})<commit_msg>Fixed : Wrong setup for cron time<commit_after>'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const config = require('./config')
const app = express()

var rp = require('request-promise');
var cronJob = require('cron').CronJob;

const LINENotifyToken = ''
const OMGPairID = '26'
const BTCPairID = '1'
const ETHPairID = '21'

app.set('port', (process.env.PORT || config.PORT))

app.use(bodyParser.urlencoded({extended: false}))

app.use(bodyParser.json())

app.get('/', function (req, res) {
  res.send('Meeaaww');
})

app.get('/publish', function (req, res) {
  publish();
  res.status(200).send('Meaaawww');
})

function publish() {
  var bxOptions = {
    uri: 'https://bx.in.th/api/',
    json: true
  };

  rp(bxOptions)
    .then(function ( marketdata ) {
        console.log(marketdata[OMGPairID]);

        let omgPair = marketdata[OMGPairID];
        let btcPair = marketdata[BTCPairID];
        let ethPair = marketdata[ETHPairID];

        notifyToGroup(omgPair, btcPair, ethPair);
    })
    .catch(function (err) {
        console.log(err);
    });
}

function messageGenerator( omg, btc, eth ) {
  let change = omg['change'];
  let lastPrice = omg['last_price'];
  let volumeIn24HR = omg['volume_24hours'];
  let volumeBids = omg['orderbook']['bids'];
  let volumeAsks = omg['orderbook']['asks'];
  
  let omglastPriceMSG = `Last price : ${lastPrice} THB\n`;
  let omgChangeMSG = `Change : ${change}%\n`;
  let omgVolume24MSG = `Volume24HR : ${volumeIn24HR} OMG\n`;
  let omgBidsMSG = `Highest buy: ${volumeBids.highbid} THB\n`;
  let omgAsksMSG = `Lowest sell: ${volumeAsks.highbid} THB\n`;

  let spliter = '- - - - - - - - - - - - - -\n'

  let btcLastPriceMSG = `BTC : ${btc.last_price} THB\n`;
  let ethLastPriceMSG = `ETH : ${eth.last_price} THB\n`

  let theEnd = '≧◡≦';

  return `✿OMG✿\n` + omglastPriceMSG + omgChangeMSG + omgVolume24MSG 
  + omgBidsMSG + omgAsksMSG + spliter + btcLastPriceMSG + ethLastPriceMSG
  + theEnd;
}

function notifyToGroup( omg, btc, eth ) {
  var message = messageGenerator(omg, btc, eth);

  var headers = {
    'User-Agent':       'AzukiChan/0.0.1',
    'Content-Type':     'application/x-www-form-urlencoded'
  }

  var options = {
    'url': 'https://notify-api.line.me/api/notify',
    'method': 'POST',
    'headers': headers,
    'auth': {
       'bearer': LINENotifyToken
    },
    'form': {
       'message': message
    }
  }

  rp(options)
    .then(function ( result ) {
        console.log('publish success')
    })
    .catch(function (err) {
        console.log()
    });
}

app.listen(app.get('port'), () => {
  console.log(`Running Crypty on port : ${app.get('port')}`)
  
  var job = new cronJob({
    cronTime: '0 */30 * * * *',
    onTick: function() {
      // Publish every 30 min
      publish();
    },
    start: false,
    timeZone: 'Asia/Bangkok'
  });

  job.start();
})
{'fraction_non_alphanumeric': 0.17579750346740639, 'fraction_numerical': 0.009535367545076282, 'mean_word_length': 3.1207142857142856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1928073', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2130, 'n_words': 428}