fix group read

This commit is contained in:
Jay 2018-09-21 18:36:09 +08:00
parent d6af7b3ccb
commit cd877b21e3
5 changed files with 10 additions and 30 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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)