Fix some golangci-lint warnings
Minor changes
This commit is contained in:
parent
d0f72d53e4
commit
a34a14d25a
4 changed files with 20 additions and 17 deletions
16
profile.go
16
profile.go
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
// Profile of twitter user
|
||||
// Profile of twitter user.
|
||||
type Profile struct {
|
||||
Avatar string
|
||||
Biography string
|
||||
|
|
@ -27,26 +27,28 @@ type Profile struct {
|
|||
Website string
|
||||
}
|
||||
|
||||
// GetProfile return parsed user profile
|
||||
// GetProfile return parsed user profile.
|
||||
func GetProfile(username string) (Profile, error) {
|
||||
url := "https://twitter.com/" + username
|
||||
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
|
||||
if err != nil {
|
||||
return Profile{}, err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept-Language", "en-US")
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
|
||||
if res == nil {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if resp == nil {
|
||||
return Profile{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return Profile{}, fmt.Errorf("response status: %s", resp.Status)
|
||||
}
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(resp.Body)
|
||||
if err != nil {
|
||||
return Profile{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
func TestGetProfile(t *testing.T) {
|
||||
loc := time.FixedZone("UTC", 0)
|
||||
joined := time.Date(2007,02, 20,6,35,0,0, loc)
|
||||
joined := time.Date(2007, 02, 20, 6, 35, 0, 0, loc)
|
||||
sample := Profile{
|
||||
Avatar: "https://pbs.twimg.com/profile_images/1111729635610382336/_65QFl7B_400x400.png",
|
||||
Biography: "What’s happening?!",
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
const trendsURL = "https://twitter.com/i/trends"
|
||||
|
||||
// GetTrends return list of trends
|
||||
// GetTrends return list of trends.
|
||||
func GetTrends() ([]string, error) {
|
||||
req, err := http.NewRequest("GET", trendsURL, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
17
tweets.go
17
tweets.go
|
|
@ -13,13 +13,13 @@ import (
|
|||
|
||||
const ajaxURL = "https://twitter.com/i/profiles/show/%s/timeline/tweets"
|
||||
|
||||
// Video type
|
||||
// Video type.
|
||||
type Video struct {
|
||||
ID string
|
||||
Preview string
|
||||
}
|
||||
|
||||
// Tweet type
|
||||
// Tweet type.
|
||||
type Tweet struct {
|
||||
Hashtags []string
|
||||
HTML string
|
||||
|
|
@ -38,13 +38,13 @@ type Tweet struct {
|
|||
Videos []Video
|
||||
}
|
||||
|
||||
// Result of scrapping
|
||||
// Result of scrapping.
|
||||
type Result struct {
|
||||
Tweet
|
||||
Error error
|
||||
}
|
||||
|
||||
// GetTweets returns channel with tweets for a given user
|
||||
// GetTweets returns channel with tweets for a given user.
|
||||
func GetTweets(user string, pages int) <-chan *Result {
|
||||
channel := make(chan *Result)
|
||||
go func(user string) {
|
||||
|
|
@ -66,7 +66,7 @@ func GetTweets(user string, pages int) <-chan *Result {
|
|||
return channel
|
||||
}
|
||||
|
||||
// FetchTweets gets tweets for a given user, via the Twitter frontend API
|
||||
// FetchTweets gets tweets for a given user, via the Twitter frontend API.
|
||||
func FetchTweets(user string, last string) ([]*Tweet, error) {
|
||||
var tweets []*Tweet
|
||||
|
||||
|
|
@ -119,13 +119,14 @@ func FetchTweets(user string, last string) ([]*Tweet, error) {
|
|||
})
|
||||
s.Find(".ProfileTweet-actionCount").Each(func(i int, c *goquery.Selection) {
|
||||
txt := strings.TrimSpace(c.Text())
|
||||
if strings.HasSuffix(txt, "likes") {
|
||||
switch {
|
||||
case strings.HasSuffix(txt, "likes"):
|
||||
l := strings.Split(txt, " ")
|
||||
tweet.Likes, _ = strconv.Atoi(l[0])
|
||||
} else if strings.HasSuffix(txt, "replies") {
|
||||
case strings.HasSuffix(txt, "replies"):
|
||||
l := strings.Split(txt, " ")
|
||||
tweet.Replies, _ = strconv.Atoi(l[0])
|
||||
} else if strings.HasSuffix(txt, "retweets") {
|
||||
case strings.HasSuffix(txt, "retweets"):
|
||||
l := strings.Split(txt, " ")
|
||||
tweet.Retweets, _ = strconv.Atoi(l[0])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue