Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
feat(tweet-getter): prevent requests when tweet is already synced (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgrasset authored Aug 25, 2023
1 parent 959addf commit 0aaa54c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/helpers/tweet/get-eligible-tweet.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { Tweet } from '@the-convocation/twitter-scraper';

import { DEBUG } from '../../constants.js';
import { Cache } from '../../types/index.js';
import { getPostExcerpt } from '../post/get-post-excerpt.js';
import { isTweetCached, keepRecentTweets, keepSelfQuotes, keepSelfReplies } from './index.js';
import { keepRecentTweets, keepSelfQuotes, keepSelfReplies } from './index.js';

export const getEligibleTweet = async (tweet: Tweet, cache: Cache): Promise<Tweet | undefined> => {
const notCached = !isTweetCached(tweet, cache);
export const getEligibleTweet = async (tweet: Tweet): Promise<Tweet | undefined> => {
const notRetweet = !tweet.isRetweet;

const isSelfReply = await keepSelfReplies(tweet);
const isSelfQuote = await keepSelfQuotes(tweet);

const isRecentTweet = keepRecentTweets(tweet);

const keep = notCached && notRetweet && isSelfReply && isSelfQuote && isRecentTweet;
const keep = notRetweet && isSelfReply && isSelfQuote && isRecentTweet;

// Remove quote & reply tweets data if not self-made
const eligibleTweet = {
Expand Down
6 changes: 3 additions & 3 deletions src/services/tweets-getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TWITTER_HANDLE } from '../constants.js';
import { getCache } from '../helpers/cache/index.js';
import { oraPrefixer } from '../helpers/logs/ora-prefixer.js';
import { getEligibleTweet } from '../helpers/tweet/get-eligible-tweet.js';
import { formatTweetText,getTweetIdFromPermalink } from '../helpers/tweet/index.js';
import { formatTweetText, getTweetIdFromPermalink, isTweetCached } from '../helpers/tweet/index.js';

const pullContentStats = (tweets: Tweet[], title: string) => {
const stats = {
Expand All @@ -28,7 +28,7 @@ export const tweetsGetterService = async (twitterClient: Scraper): Promise<Tweet
const tweetsIds = twitterClient.searchTweets(`from:@${TWITTER_HANDLE}`, 50, SearchMode.Latest);

for await(const tweet of tweetsIds) {
if (tweet) {
if (tweet && !isTweetCached(tweet, cache)) {
const t: Tweet = {
...tweet,
id: getTweetIdFromPermalink(tweet.id || ''),
Expand All @@ -52,7 +52,7 @@ export const tweetsGetterService = async (twitterClient: Scraper): Promise<Tweet
}
}

const eligibleTweet = await getEligibleTweet(t, cache);
const eligibleTweet = await getEligibleTweet(t);
if (eligibleTweet) {
tweets.unshift(eligibleTweet);
}
Expand Down

0 comments on commit 0aaa54c

Please sign in to comment.