Publish generated Twitter images for the schedule and gear tweets

#21
This commit is contained in:
Matt Isenhower
2019-01-07 11:25:08 -08:00
parent 61271483fb
commit 527542d4cc
3 changed files with 24 additions and 0 deletions

View File

@@ -31,6 +31,10 @@ class GearTweet extends TwitterPostBase {
return captureGearScreenshot(now);
}
getPublicImageFilename(data) {
return 'gear.png';
}
getText(data) {
return `Up now on SplatNet: ${data.gear.name} with ${data.skill.name} #splatnet2`;
}

View File

@@ -39,6 +39,10 @@ class ScheduleTweet extends TwitterPostBase {
return captureScheduleScreenshot(data.regular.start_time, this.globalSplatfestOpenInAllRegions());
}
getPublicImageFilename(data) {
return 'schedule.png';
}
globalSplatfestOpenInAllRegions() {
let festivals = readData('festivals.json');
let time = this.getDataTime();

View File

@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const mkdirp = require('mkdirp').sync;
const { postMediaTweet } = require('../client');
const { getTopOfCurrentHour, readJson, writeJson } = require('@/common/utilities');
@@ -28,6 +29,9 @@ class TwitterPostBase {
let text = await this.getText(data);
let image = await this.getImage(data);
// Maybe save the image
this.maybeSavePublicImage(data, image);
// Post to Twitter
let tweet = await postMediaTweet(text, image);
@@ -42,6 +46,15 @@ class TwitterPostBase {
}
}
maybeSavePublicImage(data, image) {
let filename = this.getPublicImageFilename(data);
if (filename) {
let outputFilename = path.resolve(`dist/twitter-images/${filename}`);
mkdirp(path.dirname(outputFilename));
fs.writeFileSync(outputFilename, image);
}
}
async saveTestScreenshot() {
try {
let data = this.getTestData();
@@ -141,6 +154,9 @@ class TwitterPostBase {
// The image data to be posted with the Tweet
getImage(data) { }
// The filename to store the image as (optional)
getPublicImageFilename(data) { }
// The text body of the Tweet
getText(data) { }