From cd877b21e35eae5a2a0678853af005d5fc9922de Mon Sep 17 00:00:00 2001 From: jay Date: Fri, 21 Sep 2018 18:36:09 +0800 Subject: [PATCH] fix group read --- model/facebook_page.go | 3 ++- model/twitch_channel.go | 3 ++- model/youtube_channel.go | 3 ++- module/background/background.go | 2 +- module/background/facebook.go | 29 +++-------------------------- 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/model/facebook_page.go b/model/facebook_page.go index 8bdb84f..efda19e 100644 --- a/model/facebook_page.go +++ b/model/facebook_page.go @@ -62,7 +62,8 @@ func (p *FacebookPage) GetGroups() (err error) { left join "public"."line_group" g on g.id = rt."line" where - p.id = $1` + p.id = $1 + and rt.facebook is not null` err = x.Select(&p.Groups, query, p.ID) return } diff --git a/model/twitch_channel.go b/model/twitch_channel.go index b06f1f6..be6c230 100644 --- a/model/twitch_channel.go +++ b/model/twitch_channel.go @@ -119,7 +119,8 @@ func (p *TwitchChannel) GetGroups() (err error) { left join "public"."line_group" g on g.id = rt.line where - tw.id = $1` + tw.id = $1 + and rt.twitch is not null` err = x.Select(&p.Groups, query, p.ID) return } diff --git a/model/youtube_channel.go b/model/youtube_channel.go index f01deee..9e89fc0 100644 --- a/model/youtube_channel.go +++ b/model/youtube_channel.go @@ -73,7 +73,8 @@ func (p *YoutubeChannel) GetGroups() (err error) { left join "public"."line_group" g on g.id = rt.line where - yt.id = $1` + yt.id = $1 + and rt.youtube is not null` err = x.Select(&p.Groups, query, p.ID) return } diff --git a/module/background/background.go b/module/background/background.go index 067b5a3..083ba4b 100644 --- a/module/background/background.go +++ b/module/background/background.go @@ -9,7 +9,7 @@ var c *cron.Cron // SetBackground - func SetBackground() { c = cron.New() - c.AddFunc("0 * * * * *", readFacebookPage) + // c.AddFunc("0 * * * * *", readFacebookPage) c.AddFunc("*/20 * * * * *", getStreamStatus) c.AddFunc("*/5 * * * * *", checkOpay) c.AddFunc("0 0 */3 * * *", checkYoutubeSubscribe) diff --git a/module/background/facebook.go b/module/background/facebook.go index 57f7f8c..c7a4517 100644 --- a/module/background/facebook.go +++ b/module/background/facebook.go @@ -1,12 +1,8 @@ package background import ( - "bytes" "fmt" - "io" - "io/ioutil" "net/http" - "os" "regexp" "sort" "strconv" @@ -53,45 +49,26 @@ func readFacebookPage() { } func getPageHTML(page *model.FacebookPage) { - fmt.Println("run page ::::: ", page.ID) err := page.GetGroups() if err != nil { fmt.Println("get page group err ", err) return } - resp, err := http.Get(fmt.Sprintf("https://www.facebook.com/%s", page.ID)) + resp, err := http.Get(fmt.Sprintf("https://facebook.com/%s", page.ID)) if err != nil { fmt.Println("get page html err ", err) return } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - - fmt.Print("StatusCode:", resp.StatusCode) - fmt.Println(" ", resp.Request.URL) - - fmt.Println("page size ::::::: ", len(body)) - - rrr := bytes.NewReader(body) - f, err := os.Create("/tmp/" + page.ID + ".html") - if err == nil { - io.Copy(f, rrr) - f.Close() - rrr.Seek(0, 0) - } - - doc, err := goquery.NewDocumentFromReader(rrr) + doc, err := goquery.NewDocumentFromReader(resp.Body) if err != nil { fmt.Println("parse doc err ", err) return } - body = nil - var pageData []*PageData sel := doc.Find("div.userContentWrapper") - fmt.Println("select element length >>>>> ", sel.Length()) sel.Each(func(idx int, s *goquery.Selection) { timeEl := s.Find("abbr") time, timeExists := timeEl.Attr("data-utime") @@ -122,7 +99,7 @@ func getPageHTML(page *model.FacebookPage) { return } } - // fmt.Printf("Time: %s / Text: %s / ID: %s \n", time, text, postID) + fmt.Printf("Time: %s / Text: %s / ID: %s \n", time, text, postID) timeInt, err := strconv.ParseInt(time, 10, 32)