From 92a982eeb87011287744881308c4f09a4b8df386 Mon Sep 17 00:00:00 2001 From: "Jocelyn Badgley (Twipped)" Date: Fri, 6 Mar 2020 19:32:39 -0800 Subject: [PATCH] =?UTF-8?q?If=20a=20tweet=20doesn=E2=80=99t=20exist,=20pro?= =?UTF-8?q?vide=20a=20way=20to=20explicitly=20mark=20it=20as=20such=20in?= =?UTF-8?q?=20backup.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/page-tweets.js | 20 ++++++++++++++------ twitter-backup.json | 1 + 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build/page-tweets.js b/build/page-tweets.js index 2524c67..d073f26 100644 --- a/build/page-tweets.js +++ b/build/page-tweets.js @@ -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 ); diff --git a/twitter-backup.json b/twitter-backup.json index 157a035..b8ef091 100644 --- a/twitter-backup.json +++ b/twitter-backup.json @@ -1,4 +1,5 @@ { + "1215734983840673793": false, "1228717614630940672": { "created_at": "Sat Feb 15 16:28:02 +0000 2020", "id": 1228717614630940700,