From 3424a42f605f7a683a2d4601b32afcdf37e449cd Mon Sep 17 00:00:00 2001 From: mattmcw Date: Sat, 21 Dec 2024 00:13:39 -0500 Subject: [PATCH] Fixed post, but dates are wrong --- dist/db/index.js | 5 +++-- dist/db/index.js.map | 2 +- dist/post.js | 24 +++++++++++++++++++++--- dist/post.js.map | 2 +- scripts/post.sh | 2 +- src/db/index.ts | 5 +++-- src/post.ts | 23 ++++++++++++++++++++--- 7 files changed, 50 insertions(+), 13 deletions(-) diff --git a/dist/db/index.js b/dist/db/index.js index 60a5a10..7fc83c3 100644 --- a/dist/db/index.js +++ b/dist/db/index.js @@ -99,8 +99,9 @@ class DB { } return rows; } - async getBsky() { - const query = `SELECT * FROM photos WHERE bsky = 0 ORDER BY score ASC, created DESC LIMIT 1;`; + 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;`; let rows = []; try { rows = await this.all(query); diff --git a/dist/db/index.js.map b/dist/db/index.js.map index a9b486d..59d7492 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,EAAE,GAAG,IAAI,kBAAQ,CAAC,YAAY,CAAC,CAAC;QACrC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAE,4BAA4B,CAAC,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,YAAY,EAAE,CAAC,CAAC;IACtC,CAAC;IAEO,KAAK,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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;AAzJD,gBAyJC;AAED,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/post.js b/dist/post.js index 300073d..a7dfdf8 100644 --- a/dist/post.js +++ b/dist/post.js @@ -1,10 +1,15 @@ "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); require("dotenv/config"); const log_1 = require("./log"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const api_1 = require("@atproto/api"); +const argparse_1 = require("argparse"); +const moment_1 = __importDefault(require("moment")); const db_1 = require("./db"); const env_1 = require("./env"); class Post { @@ -12,18 +17,31 @@ class Post { this.log = (0, log_1.createLog)('post'); this.db = new db_1.DB(); this.bskyAgent = new api_1.BskyAgent({ service: 'https://bsky.social' }); + this.random = false; + const parser = new argparse_1.ArgumentParser({ + description: 'Generate script' + }); + parser.add_argument('-r', '--random', { action: 'store_true', default: false, help: 'Choose one at random' }); + const args = parser.parse_args(); + this.random = args.random; this.post(); } async post() { await this.bsky(); } bskyDescription(photo) { - return `${photo.description} + let str = `${photo.description} ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; + const created = moment_1.default.unix(photo.created / 1000); + const now = (0, moment_1.default)(); + if (now.format('YYYY') !== created.format('YYYY')) { + str += '\n' + created.format('MMMM YYYY'); + } + return str; } async bsky() { - const photo = await this.db.getBsky(); + const photo = await this.db.getBsky(this.random); const identifier = (0, env_1.envString)('BSKY_USER', null); const password = (0, env_1.envString)('BSKY_PASSWORD', null); let text; @@ -60,6 +78,7 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; $type: "app.bsky.embed.images", }, */ + this.log.info(text); imagePath = (0, path_1.join)((0, env_1.envString)('WWW', './www'), 'img', `${photo.id}_full.jpg`); try { imageData = await (0, promises_1.readFile)(imagePath); @@ -87,7 +106,6 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; try { await this.bskyAgent.post(postData); this.log.info(`Posted ${photo.description} (${photo.name})`); - console.dir(photo); } catch (err) { this.log.error(`Error making Bluesky post`, err); diff --git a/dist/post.js.map b/dist/post.js.map index 2e5e1f6..162b1bd 100644 --- a/dist/post.js.map +++ b/dist/post.js.map @@ -1 +1 @@ -{"version":3,"file":"post.js","sourceRoot":"","sources":["../src/post.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AAEvB,+BAAkC;AAElC,0CAAuC;AACvC,+BAA4B;AAC5B,sCAAyC;AAGzC,6BAA0B;AAE1B,+BAAkC;AAElC,MAAM,IAAI;IAKT;QAJQ,QAAG,GAAY,IAAA,eAAS,EAAC,MAAM,CAAC,CAAC;QACjC,OAAE,GAAQ,IAAI,OAAE,EA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AC,CAAA;QAChG,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAC;YACvD,OAAO;QACR,CAAC;QAED,QAAQ,GAAG;YACV,IAAI;YACJ,KAAK,EAAE;gBACP,KAAK,EAAE,uBAAuB;gBAC9B,MAAM,EAAE,CAAC;wBACP,GAAG,EAAE,KAAK,CAAC,WAAW;wBACtB,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI;qBAC7B,CAAC;aACF;SACD,CAAA;QAED,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;QAC9D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;YACjD,OAAO;QACR,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,gCAAgC,KAAK,CAAC,IAAI,aAAa,EAAE,GAAG,CAAC,CAAC;YAC7E,OAAO;QACR,CAAC;IAEF,CAAC;CACD;AAED,IAAI,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/scripts/post.sh b/scripts/post.sh index 3963f0b..2cafa06 100644 --- a/scripts/post.sh +++ b/scripts/post.sh @@ -4,4 +4,4 @@ set -e source .env -node dist/post \ No newline at end of file +node dist/post "${@}" \ No newline at end of file diff --git a/src/db/index.ts b/src/db/index.ts index cc804ac..2f99cd6 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -131,8 +131,9 @@ export class DB { return rows; } - public async getBsky () : Promise { - const query : string = `SELECT * FROM photos WHERE bsky = 0 ORDER BY score ASC, created DESC LIMIT 1;`; + 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;`; let rows : Photo[] = []; try { rows = await this.all(query); diff --git a/src/post.ts b/src/post.ts index 234809e..f1d9e6b 100644 --- a/src/post.ts +++ b/src/post.ts @@ -6,6 +6,9 @@ import { readFile } from 'fs/promises'; import { join } from 'path'; import { BskyAgent } from '@atproto/api'; import type CallOptions from '@atproto/api'; +import { ArgumentParser } from 'argparse'; +import moment from 'moment'; +import type { Moment } from 'moment'; import { DB } from './db'; import type { Photo } from './db'; @@ -15,8 +18,15 @@ class Post { private log : Logger = createLog('post'); private db : DB = new DB(); private bskyAgent : BskyAgent = new BskyAgent({ service: 'https://bsky.social' }); + private random : boolean = false; constructor () { + const parser = new ArgumentParser({ + description: 'Generate script' + }); + parser.add_argument('-r', '--random', { action : 'store_true', default : false, help: 'Choose one at random' }); + const args : any = parser.parse_args(); + this.random = args.random; this.post(); } @@ -25,13 +35,19 @@ class Post { } private bskyDescription (photo : Photo) : string { - return `${photo.description} + let str : string = `${photo.description} ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; + const created : Moment = moment.unix(photo.created / 1000); + const now : Moment = moment(); + if (now.format('YYYY') !== created.format('YYYY')) { + str += '\n' + created.format('MMMM YYYY'); + } + return str; } private async bsky () { - const photo : Photo = await this.db.getBsky(); + const photo : Photo = await this.db.getBsky(this.random); const identifier : string = envString('BSKY_USER', null); const password : string = envString('BSKY_PASSWORD', null); let text : string; @@ -71,6 +87,8 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; $type: "app.bsky.embed.images", }, */ + this.log.info(text); + imagePath = join(envString('WWW', './www'), 'img', `${photo.id}_full.jpg`); try { @@ -100,7 +118,6 @@ ${photo.format}${photo.filmstock !== 'Unknown' ? ' - ' + photo.filmstock : ''}`; try { await this.bskyAgent.post(postData); this.log.info(`Posted ${photo.description} (${photo.name})`); - console.dir(photo); } catch (err) { this.log.error(`Error making Bluesky post`, err); return;