feat(types): extend Twitter profile data structures

- Add new fields to Profile struct (IsBlueVerified, MediaCount, etc.)
- Extend legacyUser struct with additional Twitter API fields
- Add new types for extended profile, verification and highlights info
- Update profile parsing to include new metrics
This commit is contained in:
Brendan Playford 2025-01-22 11:05:38 -08:00
parent 152a0a1c2c
commit 7226460e05
No known key found for this signature in database
GPG key ID: 663CFC091C1BDFBD
4 changed files with 131 additions and 66 deletions

View file

@ -23,6 +23,7 @@ type Profile struct {
FriendsCount int
IsPrivate bool
IsVerified bool
IsBlueVerified bool
Joined *time.Time
LikesCount int
ListedCount int
@ -37,6 +38,12 @@ type Profile struct {
Sensitive bool
Following bool
FollowedBy bool
MediaCount int
FastFollowersCount int
NormalFollowersCount int
ProfileImageShape string
HasGraduatedAccess bool
CanHighlightTweets bool
}
type user struct {

View file

@ -68,6 +68,13 @@ type userResult struct {
IsBlueVerified bool `json:"is_blue_verified"`
ProfileImageShape string `json:"profile_image_shape"`
Legacy legacyUserV2 `json:"legacy"`
LegacyExtendedProfile legacyExtendedProfile `json:"legacy_extended_profile"`
IsProfileTranslatable bool `json:"is_profile_translatable"`
VerificationInfo verificationInfo `json:"verification_info"`
HighlightsInfo highlightsInfo `json:"highlights_info"`
UserSeedTweetCount int `json:"user_seed_tweet_count"`
PremiumGiftingEligible bool `json:"premium_gifting_eligible"`
CreatorSubscriptionsCount int `json:"creator_subscriptions_count"`
}
func (result *userResult) parse() Profile {

View file

@ -182,6 +182,21 @@ type (
Verified bool `json:"verified"`
FollowedBy bool `json:"followed_by"`
Following bool `json:"following"`
CanDm bool `json:"can_dm"`
CanMediaTag bool `json:"can_media_tag"`
DefaultProfile bool `json:"default_profile"`
DefaultProfileImage bool `json:"default_profile_image"`
FastFollowersCount int `json:"fast_followers_count"`
HasCustomTimelines bool `json:"has_custom_timelines"`
IsTranslator bool `json:"is_translator"`
MediaCount int `json:"media_count"`
NeedsPhoneVerification bool `json:"needs_phone_verification"`
NormalFollowersCount int `json:"normal_followers_count"`
PossiblySensitive bool `json:"possibly_sensitive"`
ProfileInterstitialType string `json:"profile_interstitial_type"`
TranslatorType string `json:"translator_type"`
WantRetweets bool `json:"want_retweets"`
WithheldInCountries []string `json:"withheld_in_countries"`
}
legacyUserV2 struct {
@ -246,4 +261,37 @@ type (
fetchProfileFunc func(query string, maxProfilesNbr int, cursor string) ([]*Profile, string, error)
fetchTweetFunc func(query string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error)
legacyExtendedProfile struct {
Birthdate struct {
Day int `json:"day"`
Month int `json:"month"`
Year int `json:"year"`
Visibility string `json:"visibility"`
YearVisibility string `json:"year_visibility"`
} `json:"birthdate"`
}
verificationInfo struct {
IsIdentityVerified bool `json:"is_identity_verified"`
Reason struct {
Description struct {
Text string `json:"text"`
Entities []struct {
FromIndex int `json:"from_index"`
ToIndex int `json:"to_index"`
Ref struct {
URL string `json:"url"`
URLType string `json:"url_type"`
} `json:"ref"`
} `json:"entities"`
} `json:"description"`
VerifiedSinceMsec string `json:"verified_since_msec"`
} `json:"reason"`
}
highlightsInfo struct {
CanHighlightTweets bool `json:"can_highlight_tweets"`
HighlightedTweets string `json:"highlighted_tweets"`
}
)

View file

@ -364,6 +364,9 @@ func parseProfile(user legacyUser) Profile {
Username: user.ScreenName,
FollowedBy: user.FollowedBy,
Following: user.Following,
MediaCount: user.MediaCount,
FastFollowersCount: user.FastFollowersCount,
NormalFollowersCount: user.NormalFollowersCount,
}
tm, err := time.Parse(time.RubyDate, user.CreatedAt)