From 5a6607f6c4672e9af14ac18cd35202f9f90634c5 Mon Sep 17 00:00:00 2001 From: Alexander Sheiko Date: Mon, 15 Jun 2020 14:58:18 +0300 Subject: [PATCH] Add IsPrivate and IsVerified for profile --- profile.go | 5 +++++ profile_test.go | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/profile.go b/profile.go index 6d1af96..0528f1c 100644 --- a/profile.go +++ b/profile.go @@ -17,12 +17,15 @@ type Profile struct { Birthday string FollowersCount int FollowingCount int + IsPrivate bool + IsVerified bool Joined *time.Time LikesCount int Location string Name string TweetsCount int URL string + UserID string Username string Website string } @@ -66,6 +69,8 @@ func GetProfile(username string) (Profile, error) { Birthday: strings.ReplaceAll(strings.TrimSpace(doc.Find(".ProfileHeaderCard-birthdateText.u-dir").First().Text()), "Born ", ""), FollowersCount: parseCount(doc.Find(".ProfileNav-item--followers > a > span.ProfileNav-value").First()), FollowingCount: parseCount(doc.Find(".ProfileNav-item--following > a > span.ProfileNav-value").First()), + IsPrivate: doc.Find(".ProfileHeaderCard-badges .Icon--protected").First().Text() != "", + IsVerified: doc.Find(".ProfileHeaderCard-badges .Icon--verified").First().Text() != "", Joined: &joined, LikesCount: parseCount(doc.Find(".ProfileNav-item--favorites > a > span.ProfileNav-value").First()), Location: location, diff --git a/profile_test.go b/profile_test.go index 6bb3756..2349246 100644 --- a/profile_test.go +++ b/profile_test.go @@ -12,15 +12,17 @@ func TestGetProfile(t *testing.T) { loc := time.FixedZone("UTC", 0) joined := time.Date(2007, 02, 20, 6, 35, 0, 0, loc) sample := Profile{ - Avatar: "https://pbs.twimg.com/profile_images/1270500941498912768/W-80pLvu_400x400.jpg", - Biography: "Black queer lives matter.\nBlack trans lives matter.\n#BlackLivesMatter", - Birthday: "March 21", - Joined: &joined, - Location: "Everywhere", - Name: "Twitter", - URL: "https://twitter.com/Twitter", - Username: "Twitter", - Website: "https://about.twitter.com/", + Avatar: "https://pbs.twimg.com/profile_images/1270500941498912768/W-80pLvu_400x400.jpg", + Biography: "Black queer lives matter.\nBlack trans lives matter.\n#BlackLivesMatter", + Birthday: "March 21", + IsPrivate: false, + IsVerified: true, + Joined: &joined, + Location: "Everywhere", + Name: "Twitter", + URL: "https://twitter.com/Twitter", + Username: "Twitter", + Website: "https://about.twitter.com/", } profile, err := GetProfile("Twitter")