{"size": 1256, "ext": "js", "max_stars_repo_path": "scripts/parse-servery-menu.js", "max_stars_repo_name": "Ilan-Sperber/mygann-minus", "max_stars_repo_stars_event_min_datetime": "2018-09-28T19:48:05.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-14T18:15:23.000Z", "max_issues_repo_path": "scripts/parse-servery-menu.js", "max_issues_repo_name": "Ilan-Sperber/mygann-minus", "max_issues_repo_issues_event_min_datetime": "2018-10-23T00:57:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T18:16:46.000Z", "max_forks_repo_path": "scripts/parse-servery-menu.js", "max_forks_repo_name": "Ilan-Sperber/mygann-minus", "max_forks_repo_forks_event_min_datetime": "2020-03-27T13:23:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-16T00:33:28.000Z"}
{"max_stars_count": 3, "max_issues_count": 18, "max_forks_count": 5, "avg_line_length": 25.6326530612, "max_line_length": 82, "alphanum_fraction": 0.5087579618}
const fs = require('fs');
const path = require('path');
const pdf = require('pdf-parse');

const MONTH = 'may';

let dataBuffer = fs.readFileSync(path.join(__dirname, `menus/${MONTH}-menu.pdf`));

pdf(dataBuffer).then((data) => {
  const { text } = data;
  const menuText = text.split('gluten-free')[1];
  const lines = menuText.split('\n').filter(x => Boolean(x.trim()));
  const menu = [];
  for (const line of lines) {
    if (!(Number.isNaN(Number(line)))) {
      const date = Number(line);
      menu.push({ date, items: [] });
    } else {
      let name = line.trim();
      let gf = false;
      let p = false;
      if (name.endsWith('p, gf')) {
        name = name.substring(0, name.length - 5);
        p = true;
        gf = true;
      } else {
        if (name.endsWith('gf')) {
          gf = true;
          name = name.substring(0, name.length - 2);
        }
        if (name.endsWith('p')) {
          name = name.substring(0, name.length - 1);
          p = true;
        }
      }
      if (menu[menu.length - 1]) {
        menu[menu.length - 1].items.push({
          name,
          gf,
          parve: p,
        });
      }
    }
  }
  console.log(JSON.stringify(menu));
}).catch((error) => {
  console.log('Error!', error);
});
