Skip to content

Commit

Permalink
Capture a Twitter thread
Browse files Browse the repository at this point in the history
  • Loading branch information
AramZS committed Jan 28, 2022
1 parent 0441d53 commit a3e1e68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/tweet-archiver.js
Expand Up @@ -104,6 +104,7 @@ const getRepliedTo = (tweetData) => {
tweetData.referenced_tweets.length &&
tweetData.referenced_tweets[0].type == "replied_to"
) {
console.log("referenced_tweet 0", tweetData.referenced_tweets[0].id);
return tweetData.referenced_tweets[0].id;
} else {
return false;
Expand All @@ -128,7 +129,7 @@ const getTweetThread = async (tweetObj = defaultTweetObj) => {
let threadCheck = false;
let threadFirstCheck = false;
let conversation = false;
const promises = [];
// const promises = [];
const tweetData = tweetObj.data;
const tweetIncludes = tweetObj.includes;
if (tweetData.in_reply_to_user_id) {
Expand Down Expand Up @@ -158,21 +159,25 @@ const getTweetThread = async (tweetObj = defaultTweetObj) => {
} else {
console.dir(tweetData);
conversation = [tweetObj];

let nextTweet = true;
while (nextTweet) {
while (nextTweet != false) {
console.log("nextTweet", nextTweet);
if (nextTweet === true) {
nextTweet = getRepliedTo(tweetData);
console.log("nextTweet true", nextTweet);
}
var tweet = await getTwitterClient().singleTweet(
`${nextTweet}`,
tweetFields
);
// promises.push(tweet);
console.log("tweet true", tweet);
conversation.push(tweet);
nextTweet = getRepliedTo(tweet.data);
}
// await Promise.all(promises);
return conversation.reverse();
}
return conversation;
};

module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion test/twitter.test.js
Expand Up @@ -122,10 +122,13 @@ describe("The Twitter Archive Module", function () {
});
it("determine if the bottom tweet is in a thread", async function () {
const gotTweet = await linkModule.getTweetByUrl(
"https://twitter.com/Chronotope/status/1485621494365528072"
"https://twitter.com/Chronotope/status/1485625441230770181"
);
console.log("gotTweet", gotTweet);
const threadCheck = await linkModule.getTweetThread(gotTweet);
expect(threadCheck).to.have.length(6);
threadCheck[0].data.text.should.equal(
"This is fkin nonsense. Once again: every other browser has already done this. Get rid of the third party cookie. Trying to sue Google to stop this is confused nonsense. https://t.co/UTK0OfeMxg"
);
});
});

0 comments on commit a3e1e68

Please sign in to comment.