Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from "fs";
- import { open } from "sqlite";
- import SQL from 'sql-template-strings';
- import sqlite3 from "sqlite3";
- const hydrus_path = "/path/to/your/hydrus/db/";
- const db = await open({ filename: `${hydrus_path}client.db`, driver: sqlite3.Database });
- const timestamps = await db.all(SQL`
- SELECT timestamp FROM current_files_3
- `);
- timestamps.sort((a, b) => a.timestamp - b.timestamp);
- const dates = {};
- const hours = {};
- for(const { timestamp } of timestamps) {
- const time = new Date(timestamp * 1000);
- const date = `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`;
- const hour = time.getHours();
- dates[date] ||= 0;
- dates[date]++;
- hours[hour] ||= 0;
- hours[hour]++;
- }
- let agg = 0;
- const datesText = Object.entries(dates)
- .map(([date, count]) => {
- agg += count;
- return date + "\t" + agg;
- })
- .join("\n");
- const hoursText = Object.entries(hours)
- .map(([hour, count]) => hour + "\t" + count)
- .sort()
- .join("\n");
- fs.writeFileSync("dates.tsv", datesText);
- fs.writeFileSync("hours.tsv", hoursText);
Advertisement
Add Comment
Please, Sign In to add comment