Extended user validity check

This commit is contained in:
Alexander Sheiko 2020-08-10 14:08:35 +03:00
parent b2f87b1d9d
commit c6f9351149

View file

@ -55,15 +55,17 @@ func GetProfile(username string) (Profile, error) {
return Profile{}, err return Profile{}, err
} }
// parse location, also check is username valid // parse location
location := strings.TrimSpace(doc.Find(".ProfileHeaderCard-locationText.u-dir").First().Text()) 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 // parse join date text
joined, _ := time.Parse("3:4 PM - 2 Jan 2006", doc.Find(".ProfileHeaderCard-joinDateText.u-dir").First().AttrOr("title", "")) 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{ return Profile{
Avatar: doc.Find(".ProfileAvatar-image").First().AttrOr("src", ""), Avatar: doc.Find(".ProfileAvatar-image").First().AttrOr("src", ""),
Banner: doc.Find(".ProfileCanopy-headerBg img").First().AttrOr("src", ""), Banner: doc.Find(".ProfileCanopy-headerBg img").First().AttrOr("src", ""),