Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2 more fields to Tweet object for richer parsing #57

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tweets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface Tweet {
isReply?: boolean;
isRetweet?: boolean;
isSelfThread?: boolean;
language?: string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Implement parsing for the new properties.

The new properties language and quotes are not being populated in the parsing functions. Consider updating the following functions to parse these properties:

  • parseTweetV2ToV1: Parse lang from tweetV2 for the language property
  • parseTweetV2ToV1: Parse quote_count from tweetV2.public_metrics for the quotes property

Apply this diff to implement the parsing:

   parsedTweet = {
     id: tweetV2.id,
     text: tweetV2.text ?? defaultTweetData?.text ?? '',
+    language: tweetV2.lang ?? defaultTweetData?.language,
     hashtags:
       tweetV2.entities?.hashtags?.map((tag) => tag.tag) ??
       defaultTweetData?.hashtags ??
       [],
     mentions:
       tweetV2.entities?.mentions?.map((mention) => ({
         id: mention.id,
         username: mention.username,
       })) ??
       defaultTweetData?.mentions ??
       [],
     urls:
       tweetV2.entities?.urls?.map((url) => url.url) ??
       defaultTweetData?.urls ??
       [],
     likes: tweetV2.public_metrics?.like_count ?? defaultTweetData?.likes ?? 0,
     retweets:
       tweetV2.public_metrics?.retweet_count ?? defaultTweetData?.retweets ?? 0,
+    quotes:
+      tweetV2.public_metrics?.quote_count ?? defaultTweetData?.quotes ?? 0,
     replies:
       tweetV2.public_metrics?.reply_count ?? defaultTweetData?.replies ?? 0,

Also applies to: 182-182

likes?: number;
name?: string;
mentions: Mention[];
Expand All @@ -178,6 +179,7 @@ export interface Tweet {
place?: PlaceRaw;
quotedStatus?: Tweet;
quotedStatusId?: string;
quotes?: number;
replies?: number;
retweets?: number;
retweetedStatus?: Tweet;
Expand Down