Extended user validity check
This commit is contained in:
parent
b2f87b1d9d
commit
c6f9351149
1 changed files with 6 additions and 4 deletions
10
profile.go
10
profile.go
|
|
@ -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", ""),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue