<commit_before>var path = require('path');
var ipc = require('ipc');

function renderTemplate(type, data) {
  var templateSource = document.getElementById('template-' + type).innerHTML;
  var template = Handlebars.compile(templateSource);
  var resultsPlaceholder = document.getElementById('result-' + type);
  resultsPlaceholder.innerHTML = template(data);
}

function createNotification(events) {
  // TODO: if the upcoming event is in an hour, only then notify
  // FIX: display separate notifications without replacing each other
  events.forEach(function(event) {
    require('node-notifier').notify({
      'title': event.name,
      'message': 'by ' + event.group_name + ' on ' + event.formatted_time,
      'icon': path.join(__dirname, 'logo.png'),
      'wait': true,
      'open': event.url
    });
  })
}

function callAPI(type, willNotify){
  var xhr = new XMLHttpRequest();
  xhr.onload = function(){
    var body = JSON.parse(this.responseText);
    var data = {};
    data[type] = body[type].slice(0, 3);
    if (type === 'events' && willNotify) {
      createNotification(data[type] );
    }<commit_msg>Refactor notifier<commit_after>var path = require('path');
var ipc = require('ipc');
var notifier = require('node-notifier');

function renderTemplate(type, data) {
  var templateSource = document.getElementById('template-' + type).innerHTML;
  var template = Handlebars.compile(templateSource);
  var resultsPlaceholder = document.getElementById('result-' + type);
  resultsPlaceholder.innerHTML = template(data);
}

function createNotification(events) {
  // TODO: if the upcoming event is in an hour, only then notify
  // FIX: display separate notifications without replacing each other
  events.forEach(function(event) {
    notifier.notify({
      'title': event.name,
      'message': 'by ' + event.group_name + ' on ' + event.formatted_time,
      'icon': path.join(__dirname, 'logo.png'),
      'wait': true,
      'open': event.url
    });
  })
}

function callAPI(type, willNotify){
  var xhr = new XMLHttpRequest();
  xhr.onload = function(){
    var body = JSON.parse(this.responseText);
    var data = {};
    data[type] = body[type].slice(0, 3);
    if (type === 'events' && willNotify) {
      createNotification(data[type] );
    }
{'fraction_non_alphanumeric': 0.1455668284075871, 'fraction_numerical': 0.00176444640494045, 'mean_word_length': 3.9519650655021836, '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': '3647727', 'n_tokens_mistral': 672, 'n_tokens_neox': 662, 'n_words': 168}