diff --git a/package.json b/package.json index a7930ad..2f1ac87 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "build": "tsc", "lint": "tslint --project ./tsconfig.json -t stylish", "start": "ts-node src/index.ts", + "daily": "ts-node src/index.ts | tee -a log_`date --iso-8601`.txt", "test": "doctest-ts-improved src/ && mocha --require ts-node/register \"./**/*.doctest.ts\" && (find . -type f -name \"*.doctest.ts\" | xargs rm)" }, "dependencies": { diff --git a/src/Postbuilder.ts b/src/Postbuilder.ts index 5fad541..bc23bbe 100644 --- a/src/Postbuilder.ts +++ b/src/Postbuilder.ts @@ -205,7 +205,7 @@ export class Postbuilder { return result } - public async buildMessage(): Promise { + public async buildMessage(date:string): Promise { const changesets = this._changesetsMade const perContributor = new Histogram(changesets, cs => cs.properties.uid) @@ -226,7 +226,7 @@ export class Postbuilder { const {totalImagesCreated, attachmentIds, imgAuthors, totalImageContributorCount} = await this.prepareImages(changesets, 12) let toSend: string[] = [ - "Today, " + perContributor.keys().length + " different persons made " + totalStats.total + " changes to #OpenStreetMap using https://mapcomplete.osm.be .\n", + "Yesterday, " + perContributor.keys().length + " different persons made " + totalStats.total + " changes to #OpenStreetMap using https://mapcomplete.osm.be .\n", ] for (let i = 0; i < this._config.postSettings.topContributorsNumberToShow - 1 && i < topContributors.length; i++) { @@ -270,7 +270,9 @@ export class Postbuilder { await this._poster.writeMessage([ "In total, "+totalImageContributorCount+" different contributors uploaded "+totalImagesCreated+" images.\n", "Images in this thread are randomly selected from them and were made by: ", - ...Array.from(new Set(imgAuthors)).map(auth => "- "+auth ) + ...Array.from(new Set(imgAuthors)).map(auth => "- "+auth ), + "", + "Changeset of "+date ].join("\n"),{ inReplyToId: secondPost["id"], @@ -302,6 +304,10 @@ export class Postbuilder { const attachmentIds: string[] = [] const imgAuthors: string[] = [] for (const randomImage of randomImages) { + if(this._config.mastodonAuth.dryrun){ + console.log("Not uploading/downloading image:"+randomImage.image+" dryrun") + continue + } const id = randomImage.image.substring(randomImage.image.lastIndexOf("/") + 1) const path = this._config.cacheDir + "/image_" + id await Utils.DownloadBlob(randomImage.image, path) diff --git a/src/index.ts b/src/index.ts index 9fea7f8..e8c9211 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,7 @@ export class Main { let changesets: ChangeSetData[] = await osmcha.DownloadStatsForDay(today.getUTCFullYear(), today.getUTCMonth() + 1, today.getUTCDate() - 1) console.log("Building post...") - await new Postbuilder(this._config, poster, changesets).buildMessage() + await new Postbuilder(this._config, poster, changesets).buildMessage(today.getUTCFullYear()+"-"+ (today.getUTCMonth() + 1) + (today.getUTCDate() - 1)) }