Skip to content

Instantly share code, notes, and snippets.

@Interfiber
Last active April 5, 2021 20:43
Show Gist options
  • Save Interfiber/49fe5229ad147745c8e92a61c7808d59 to your computer and use it in GitHub Desktop.
Save Interfiber/49fe5229ad147745c8e92a61c7808d59 to your computer and use it in GitHub Desktop.
Main.js for something...
const fs = require('fs');
const dir = fs.opendirSync('json')
let dirent
let db_out = [];
while ((dirent = dir.readSync()) !== null) {
let json = JSON.parse(fs.readFileSync(`json/${dirent.name}`));
json.forEach((f) => {
let ts = new Date(f.ts * 1000);
// Get attachment title
if (f.attachments == undefined){
}else {
f.attachments.forEach((e) => {
db_out.push({
title: e.title,
run_date: `${ts.getMonth()}/${ts.getDay()}/${ts.getFullYear()}`
})
});
}
});
}
let occur = {};
db_out.forEach((g) => {
if (occur[g.title] == undefined){
occur[g.title] = {};
}
if (occur[g.title][g.run_date] == undefined){
occur[g.title][g.run_date] = 1;
}else {
occur[g.title][g.run_date] += 1;
}
});
fs.writeFileSync("out.json", JSON.stringify(occur));
dir.closeSync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment