<commit_before>#!/usr/bin/env node

(function () {
  'use strict';

  if (process.env.NODE_ENV !== 'production') {
    // Load the .env file, that sets process.env.
    require('dotenv').load();
  }

  const express = require('express');
  const bodyParser = require('body-parser');

  const FB = require('./connectors/facebook');
  const Bot = require('./bot');

  // LETS MAKE A SERVER!
  const app = express();
  const serverInstance = app.listen(process.env.PORT, () => {
    console.log('> Running on port', process.env.PORT);
  });

  // PARSE THE BODY
  app.use(bodyParser.json());

  // Setup Email
  const nodemailer = require('nodemailer');

  const transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
      user: process.env.EMAIL_ID,
      pass: <PASSWORD>
    }
  });

  app.get('/fitbitauth/:fbid', (req, res) => {
    if (req.params.secret) {
      // Authenticate with fitbit and save details in database
      // TODO send request to fitbit with the headers
      res.send(
        '<h1>Work in progress</h1>'
      );
      // Save fitbitId and trackerId to user object

    } else {
      res.send(
        '<h1>Please specify a Facebook ID</h1>'
      );
    }

  });

  /**
   * Backup the sessions json object via email attachment.
   */
  app.get('/email/backup/:secret', (req, res) => {
    if (req.params.secret === process.env.CRON_SECRET) {
      // const mailOptions = {
      //   attachments: [{
      //     filename: (new Date()).toDateString().split(' ').join('_') + '.json',
      //     content: JSON.stringify(Bot.sessions),
      //     contentType: 'application/json'
      //   }],

      //   from: process.env.EMAIL_ID,
      //   to: process.env.EMAIL_ID,
      //   subject: 'BACKUP', // Subject line
      //   text: (new Date()).toLocaleString() + '\nChatbot backup of ' + Object.keys(Bot.sessions).length + ' users.\n\n' + JSON.stringify(Bot.sessions)
      // };

      // transporter.sendMail(mailOptions, (error, info) => {
      //   if (error) {
      //     console.log(error);
      //     console.log(error.message);
      //     res.json({response: error, message: error.message});
      //   } else {<commit_msg>Added basic fitbit auth for demo<commit_after>#!/usr/bin/env node

(function () {
  'use strict';

  if (process.env.NODE_ENV !== 'production') {
    // Load the .env file, that sets process.env.
    require('dotenv').load();
  }

  const express = require('express');
  const bodyParser = require('body-parser');
  const url = require('url');

  const FB = require('./connectors/facebook');
  const Bot = require('./bot');

  // LETS MAKE A SERVER!
  const app = express();
  const serverInstance = app.listen(process.env.PORT, () => {
    console.log('> Running on port', process.env.PORT);
  });

  // PARSE THE BODY
  app.use(bodyParser.json());

  // Setup Email
  const nodemailer = require('nodemailer');

  const transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
      user: process.env.EMAIL_ID,
      pass: <PASSWORD>.EMAIL_PASS
    }
  });

  app.get('/fitbitauth/:fbid', (req, res) => {
    if (req.params.fbid) {
      res.redirect(url.format({
        pathname: 'https://www.fitbit.com/oauth2/authorize',
        query: {
          response_type: 'code',
          client_id:  process.env.FITBIT_CLIENT_ID,
          scope: 'settings'
        }
      }));
    } else {
      res.send(
        '<h1>Please specify a Facebook ID</h1>'
      );
    }
  });

  /**
   * Backup the sessions json object via email attachment.
   */
  app.get('/email/backup/:secret', (req, res) => {
    if (req.params.secret === process.env.CRON_SECRET) {
      // const mailOptions = {
      //   attachments: [{
      //     filename: (new Date()).toDateString().split(' ').join('_') + '.json',
      //     content: JSON.stringify(Bot.sessions),
      //     contentType: 'application/json'
      //   }],

      //   from: process.env.EMAIL_ID,
      //   to: process.env.EMAIL_ID,
      //   subject: 'BACKUP', // Subject line
      //   text: (new Date()).toLocaleString() + '\nChatbot backup of ' + Object.keys(Bot.sessions).length + ' users.\n\n' + JSON.stringify(Bot.sessions)
      // };

      // transporter.sendMail(mailOptions, (error, info) => {
      //   if (error) {
      //     console.log(error);
      //     console.log(error.message);
      //     res.json({response: error, message: error.message});
      //   } else {
{'fraction_non_alphanumeric': 0.1745960502692998, 'fraction_numerical': 0.0015709156193895871, 'mean_word_length': 2.2675953079178885, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '578536', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1430, 'n_words': 303}