Skip to content

Commit

Permalink
Extended user validity check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Sheiko committed Aug 10, 2020
1 parent c83d479 commit a1bf646
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ func GetProfile(username string) (Profile, error) {
return Profile{}, err
}

// parse location, also check is username valid
// parse location
location := strings.TrimSpace(doc.Find(".ProfileHeaderCard-locationText.u-dir").First().Text())
if location == "" {
return Profile{}, fmt.Errorf("either @%s does not exist or is private", username)
}

// parse join date text
joined, _ := time.Parse("3:4 PM - 2 Jan 2006", doc.Find(".ProfileHeaderCard-joinDateText.u-dir").First().AttrOr("title", ""))

// check is username valid
if location == "" && joined.IsZero() {
return Profile{}, fmt.Errorf("either @%s does not exist or is private", username)
}

return Profile{
Avatar: doc.Find(".ProfileAvatar-image").First().AttrOr("src", ""),
Banner: doc.Find(".ProfileCanopy-headerBg img").First().AttrOr("src", ""),
Expand Down

0 comments on commit a1bf646

Please sign in to comment.