From 86e60cb25d32cfe7eb653c01a79687a475a3a1ef Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sat, 21 Dec 2024 01:04:22 -0500 Subject: [PATCH] Fix all dates --- dist/db/index.js | 16 ++++++++++++++++ dist/db/index.js.map | 2 +- dist/fix.js | 32 ++++++++++++++++++++++++++++++++ dist/fix.js.map | 1 + src/db/index.ts | 17 +++++++++++++++++ src/fix.ts | 31 +++++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 dist/fix.js create mode 100644 dist/fix.js.map create mode 100644 src/fix.ts diff --git a/dist/db/index.js b/dist/db/index.js index 7fc83c3..7e05034 100644 --- a/dist/db/index.js +++ b/dist/db/index.js @@ -99,6 +99,22 @@ class DB { } return rows; } + async update(photo, fields) { + if (fields.indexOf('updated') === -1) { + fields.push('updated'); + photo.updated = Date.now(); + } + const values = fields.map(el => photo[el]); + const query = `UPDATE photos SET ${fields.map(el => { return el + ' = ?'; }).join(',')} WHERE id = ?;`; + values.push(photo.id); + try { + await this.run(query, values); + } + catch (err) { + this.log.error(`Error updating photo with columns: ${fields.join(', ')}`, err); + this.log.info(query); + } + } async getBsky(random = false) { const order = random ? 'RANDOM()' : 'score ASC, created DESC'; const query = `SELECT * FROM photos WHERE bsky = 0 ORDER BY ${order} LIMIT 1;`; diff --git a/dist/db/index.js.map b/dist/db/index.js.map index 59d7492..f23e5a7 100644 --- a/dist/db/index.js.map +++ b/dist/db/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";;;AAAA,yBAAuB;AAEvB,gCAAmC;AAEnC,qCAAmC;AACnC,gCAAmC;AA6BnC,MAAa,EAAE;IAId;QACC,MAAM,YAAY,GAAY,IAAA,eAAS,EAAC,IAAI,EAAE,cAAc,CAAC,CAAC;QAC9D,IAAI,CAAC,GAAG,GAAG,IAAA,eAAS,EAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,EA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CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,QAAQ;QACT,CAAC;IACF,CAAC;IAEM,KAAK,CAAC,WAAW,CAAE,QAAiB;QAC1C,MAAM,KAAK,GAAa,qEAAqE,CAAC;QAC9F,IAAI,IAAI,GAAW,EAAE,CAAC;QACtB,IAAI,GAAG,GAAY,IAAI,CAAC;QACxB,IAAI,CAAC;YACJ,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,QAAQ;QACT,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,GAAG,GAAG;gBACL,QAAQ,EAAG,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ;gBAC3B,SAAS,EAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;aAC7B,CAAA;QACF,CAAC;QAED,OAAO,GAAG,CAAC;IACZ,CAAC;CAED;AAzKD,gBAyKC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/fix.js b/dist/fix.js new file mode 100644 index 0000000..08b0bbd --- /dev/null +++ b/dist/fix.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("dotenv/config"); +const log_1 = require("./log"); +const db_1 = require("./db"); +async function fixDates() { + const log = (0, log_1.createLog)('fixDates'); + const db = new db_1.DB(); + let rows; + let parts; + let d; + try { + rows = await db.getAll(); + } + catch (err) { + log.error(err); + } + for (let row of rows) { + parts = row.name.split('_'); + d = new Date(parseInt(parts[0]), parseInt(parts[1]) - 1, parseInt(parts[2])); + row.created = +d; + try { + await db.update(row, ['created']); + log.info(`Updated row ${row.id}: created == ${row.created}`); + } + catch (err) { + log.error('Error updating row', err); + } + } +} +fixDates(); +//# sourceMappingURL=fix.js.map \ No newline at end of file diff --git a/dist/fix.js.map b/dist/fix.js.map new file mode 100644 index 0000000..2884405 --- /dev/null +++ b/dist/fix.js.map @@ -0,0 +1 @@ +{"version":3,"file":"fix.js","sourceRoot":"","sources":["../src/fix.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AACvB,+BAAkC;AAElC,6BAA0B;AAE1B,KAAK,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAY,IAAA,eAAS,EAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,EAAE,GAAQ,IAAI,OAAE,EAAE,CAAC;IACzB,IAAI,IAAY,CAAC;IACjB,IAAI,KAAgB,CAAC;IACrB,IAAI,CAAQ,CAAC;IAEb,IAAI,CAAC;QACJ,IAAI,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IACD,KAAK,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QACtB,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC3B,CAAC,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3E,GAAG,CAAC,OAAO,GAAG,CAAE,CAAC,CAAC;QAClB,IAAI,CAAC;YACJ,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;YAClC,GAAG,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,gBAAgB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,GAAG,CAAC,KAAK,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;QACtC,CAAC;IACF,CAAC;AACF,CAAC;AAED,QAAQ,EAAE,CAAC"} \ No newline at end of file diff --git a/src/db/index.ts b/src/db/index.ts index 2f99cd6..8799efa 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -11,6 +11,7 @@ interface LatLng { } interface Photo { + [key: string] : any; id : string; name : string; description : string; @@ -131,6 +132,22 @@ export class DB { return rows; } + public async update (photo : Photo, fields : string[]) { + if (fields.indexOf('updated') === -1) { + fields.push('updated'); + photo.updated = Date.now(); + } + const values : any[] = fields.map(el => photo[el]); + const query : string = `UPDATE photos SET ${fields.map(el => { return el + ' = ?'}).join(',')} WHERE id = ?;`; + values.push(photo.id); + try { + await this.run(query, values); + } catch (err) { + this.log.error(`Error updating photo with columns: ${fields.join(', ')}`, err); + this.log.info(query); + } + } + public async getBsky (random : boolean = false) : Promise { const order : string = random ? 'RANDOM()' : 'score ASC, created DESC'; const query : string = `SELECT * FROM photos WHERE bsky = 0 ORDER BY ${order} LIMIT 1;`; diff --git a/src/fix.ts b/src/fix.ts new file mode 100644 index 0000000..2761ae0 --- /dev/null +++ b/src/fix.ts @@ -0,0 +1,31 @@ +import 'dotenv/config'; +import { createLog } from './log'; +import type { Logger } from 'winston'; +import { DB } from './db'; + +async function fixDates () { + const log : Logger = createLog('fixDates'); + const db : DB = new DB(); + let rows : any[]; + let parts : string[]; + let d : Date; + + try { + rows = await db.getAll(); + } catch (err) { + log.error(err); + } + for (let row of rows) { + parts = row.name.split('_') + d = new Date(parseInt(parts[0]), parseInt(parts[1])-1, parseInt(parts[2])); + row.created = + d; + try { + await db.update(row, ['created']); + log.info(`Updated row ${row.id}: created == ${row.created}`); + } catch (err) { + log.error('Error updating row', err); + } + } +} + +fixDates(); \ No newline at end of file