<commit_before>#!/usr/bin/env node
import _ from 'lodash';
import google from 'googleapis';
import util from '../util/seeds'
import BPromise  from 'bluebird';
import requireEnvs from '../util/require-envs';
const {knex} = require('../util/database').connect();
const logger = require('../util/logger')(__filename);
const sheets = google.sheets('v4');

requireEnvs([
  'GSHEETS_EVENTS',
  'GSHEETS_API_KEY',
]);

const eventSheets = JSON.parse(process.env.GSHEETS_EVENTS);
const batchGetAsync = BPromise.promisify(sheets.spreadsheets.values.batchGet);
const cities = {};

getEvents()
.then(() => {
  logger.info("Event data updated");
  process.exit();
})
.catch(err => {
  logger.error("Updating events errored", err);
  process.exit(1);
});

function getEvents() {
  logger.info("Updating events data");
  return knex('cities').select('*').then(rows => {
    rows.forEach(city => {
      cities[city.name] = city.id;
    });
  })
  .then(() => BPromise.map(eventSheets, eventSheet => {
    const request = {<commit_msg>Renamed function for better clarity<commit_after>#!/usr/bin/env node
import _ from 'lodash';
import google from 'googleapis';
import util from '../util/seeds'
import BPromise  from 'bluebird';
import requireEnvs from '../util/require-envs';
const {knex} = require('../util/database').connect();
const logger = require('../util/logger')(__filename);
const sheets = google.sheets('v4');

requireEnvs([
  'GSHEETS_EVENTS',
  'GSHEETS_API_KEY',
]);

const eventSheets = JSON.parse(process.env.GSHEETS_EVENTS);
const batchGetAsync = BPromise.promisify(sheets.spreadsheets.values.batchGet);
const cities = {};

_fetchEvents()
.then(() => {
  logger.info("Event data updated");
  process.exit();
})
.catch(err => {
  logger.error("Updating events errored", err);
  process.exit(1);
});

function _fetchEvents() {
  logger.info("Updating events data");
  return knex('cities').select('*').then(rows => {
    rows.forEach(city => {
      cities[city.name] = city.id;
    });
  })
  .then(() => BPromise.map(eventSheets, eventSheet => {
    const request = {
{'fraction_non_alphanumeric': 0.1827852998065764, 'fraction_numerical': 0.0019342359767891683, 'mean_word_length': 4.637602179836512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7558805', 'n_tokens_mistral': 699, 'n_tokens_neox': 691, 'n_words': 140}