Skip to content

Commit

Permalink
Use git to order welcome tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
rradczewski committed Oct 28, 2021
1 parent bdd0caf commit 8310dd1
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions scripts/print_welcome_tweets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node
require("@js-joda/timezone");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const glob = require("glob").sync;
const { resolve, basename, dirname } = require("path");
const { readFileSync, statSync } = require("fs");
Expand Down Expand Up @@ -28,27 +30,43 @@ const dateFormat = DateTimeFormatter.ofPattern(
"eeee 'at' HH:mm ('UTC'x)"
).withLocale(Locale.US);

glob(__dirname + "/../_data/**/.SCHEMA.json")
.sort()
.forEach((schemaFile) => {
const gitCreationDate = async (file) => {
const output = await exec(`git log --format=%at "${file}" | tail -1`);
if (!!output.stderr) throw output.stderr;
return Number(output.stdout.trim());
};

const run = async () => {
const schemas = glob(__dirname + "/../_data/**/.SCHEMA.json");
for (let schemaFile of schemas) {
console.log(
"EVENTS FOR",
dirname(schemaFile),
"\n--------------------------------"
);
const events = glob(dirname(schemaFile) + "/*.json").sort(
(file_1, file_2) => statSync(file_1).mtimeMs - statSync(file_2).mtimeMs
);
const events = (
await Promise.all(
glob(dirname(schemaFile) + "/*.json").map(async (event) => {
const creationTime = await gitCreationDate(event);
return { event, creationTime };
})
)
)
.sort((eventA, eventB) => eventA.creationTime - eventB.creationTime)
.map((e) => e.event);

for (let eventFile of events) {
const event = JSON.parse(readFileSync(eventFile).toString());

const date = ZonedDateTime.parse(event.date.start);
if(date.isBefore(ZonedDateTime.now())) continue;
if (date.isBefore(ZonedDateTime.now())) continue;
const tweet = `🌐 Welcome ${event.title}${toWelcomeTweetModerators(
event.moderators
)} on ${dateFormat.format(date)} to #gdcr21! ${event.url}`;
console.log(tweet);
}
console.log("");
});
}
};

run();

0 comments on commit 8310dd1

Please sign in to comment.