If a tweet doesn’t exist, provide a way to explicitly mark it as such in backup.

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-03-06 19:32:39 -08:00
parent 53a8378bd3
commit 92a982eeb8
2 changed files with 15 additions and 6 deletions

View File

@ -4,6 +4,7 @@ const { resolve } = require('./resolve');
const log = require('fancy-log');
const tweetparse = require('./lib/tweetparse');
const Twitter = require('twitter-lite');
const { hasOwn } = require('./lib/util');
module.exports = exports = async function tweets (pages) {
@ -46,12 +47,18 @@ module.exports = exports = async function tweets (pages) {
const absent = difference(tweetsRequested, loaded);
for (const id of absent) {
if (twitterBackup[id]) {
log('Pulled tweet from backup ' + id);
twitterCache[id] = tweetparse(twitterBackup[id]);
if (!hasOwn(twitterBackup, id)) {
log.error('Could not find tweet ' + id);
continue;
}
log.error('Could not find tweet ' + id);
const tweet = twitterBackup[id];
if (tweet) {
log('Pulled tweet from backup ' + id);
twitterCache[id] = tweetparse(twitterBackup[id]);
} else {
twitterCache[id] = false;
}
}
}
@ -60,11 +67,12 @@ module.exports = exports = async function tweets (pages) {
const twitterMedia = [];
function attachTweet (dict, tweetid) {
const tweet = twitterCache[tweetid];
if (!tweet) {
if (!hasOwn(twitterCache, tweetid) && twitterBackup[tweetid]) {
log.error(`Tweet ${tweetid} is missing from the cache.`);
return;
}
const tweet = twitterCache[tweetid];
if (!tweet) return;
dict[tweetid] = tweet;
twitterMedia.push( ...tweet.media );

View File

@ -1,4 +1,5 @@
{
"1215734983840673793": false,
"1228717614630940672": {
"created_at": "Sat Feb 15 16:28:02 +0000 2020",
"id": 1228717614630940700,