<commit_before>'use strict';

import Koa from 'koa';
import 'babel-polyfill';
import Octokat from 'octokat';
import Router from 'koa-router';
import marked from 'marked';

const app = Koa();
const router = Router();
const octo = new Octokat();
const repo = octo.repos('japacible', 'Hackathon-Calendar');
const port = (process.env.PORT || 5000);

app
  .use(router.routes())
  .use(router.allowedMethods());

function getHackathonsFrom(markdown) {
  let tokens = marked.lexer(markdown);
  let hackathons = [];
  for (let key of Object.keys(tokens)) {
    if (tokens[key]['type'] === 'table') {
      let year = tokens[key]['header'][tokens[key]['header'].length - 1];
      hackathons.push.apply(hackathons, tokens[key]['cells']);
      for (let hackathon of hackathons) {
        hackathon.push(year);
      }
    }
  }
  return hackathons;
}

router
  .get('/', function *(next) {
    let message = `An API list of hackathons from
    https://github.com/japacible/Hackathon-Calendar

Endpoints:

- [/upcoming](/upcoming) | get a list of upcoming hackathons

- [/past](/past) | get a list of past hackathons

- [/ping](/ping) | Pong`;
    this.body = marked(message);
  })
  .get('/ping', function *(next) {
    this.body = 'PONG';
  })
  .get('/upcoming',function *(next) {
    this.body = yield repo.contents('README.md').read()
      .then((contents) => {
        return getHackathonsFrom(contents);
      });
  })
  .get('/past',function *(next) {
    this.body = yield repo.contents('Past-Hackathons.md').read()
      .then((contents) => {
        return getHackathonsFrom(contents);
      });
  });

app.listen(port);<commit_msg>Format response in key-value format<commit_after>'use strict';

import Koa from 'koa';
import 'babel-polyfill';
import Octokat from 'octokat';
import Router from 'koa-router';
import marked from 'marked';

const app = Koa();
const router = Router();
const octo = new Octokat();
const repo = octo.repos('japacible', 'Hackathon-Calendar');
const port = (process.env.PORT || 5000);

app
  .use(router.routes())
  .use(router.allowedMethods());

function getHackathonsFrom(markdown) {
  let tokens = marked.lexer(markdown);
  let hackathons = [];
  for (let key of Object.keys(tokens)) {
    if (tokens[key]['type'] === 'table') {
      let year = tokens[key]['header'][tokens[key]['header'].length - 1];
      hackathons.push.apply(hackathons, tokens[key]['cells']);
      for (let hackathon of hackathons) {
        hackathon.push(year);
      }
    }
  }
  return hackathons.map((hackathon) => {
    let name = hackathon[0].match(/\[([^\)]+)\]/i)[1];
    let url = hackathon[0].match(/\(([^\)]+)\)/i)[1];
    let location = hackathon[1];
    let date = `${hackathon[2]}, ${hackathon[3].match(/\(([^\)]+)\)/i)[1]}`;
    return {
      "name": name,
      "url": url,
      "location": location,
      "date": date
    };
  });
}

router
  .get('/', function *(next) {
    let message = `An API list of hackathons from
    https://github.com/japacible/Hackathon-Calendar

Endpoints:

- [/upcoming](/upcoming) | get a list of upcoming hackathons

- [/past](/past) | get a list of past hackathons

- [/ping](/ping) | Pong`;
    this.body = marked(message);
  })
  .get('/ping', function *(next) {
    this.body = 'PONG';
  })
  .get('/upcoming', function *(next) {
    this.body = yield repo.contents('README.md').read()
      .then((contents) => {
        return getHackathonsFrom(contents);
      });
  })
  .get('/past', function *(next) {
    this.body = yield repo.contents('Past-Hackathons.md').read()
      .then((contents) => {
        return getHackathonsFrom(contents);
      });
  });

app.listen(port);
{'fraction_non_alphanumeric': 0.1893523600439078, 'fraction_numerical': 0.004939626783754116, 'mean_word_length': 3.3392857142857144, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '4344646', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1261, 'n_words': 275}