本文整理汇总了Golang中github.com/kimxilxyong/intogooglego/post.Post.Score方法的典型用法代码示例。如果您正苦于以下问题:Golang Post.Score方法的具体用法?Golang Post.Score怎么用?Golang Post.Score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kimxilxyong/intogooglego/post.Post
的用法示例。
在下文中一共展示了Post.Score方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HackerNewsPostScraper
//.........这里部分代码省略.........
// Print out the crawled info
fmt.Println("----------- INSERT POST START -----------------")
fmt.Println(htmlpost.String("INSERT: "))
}
if err != nil {
return errors.New("insert into table " + dbmap.Dialect.QuoteField(tm.TableName) + " failed: " + err.Error())
}
if DebugLevel > 2 {
// Print out the end of the crawled info
fmt.Println("----------- INSERT POST END -------------------")
}
insertedPostsCount += dbmap.LastOpInfo.RowCount
insertedPostsCommentCount += dbmap.LastOpInfo.ChildInsertRowCount
} else {
// Post already exists, get the full post with its comments from the db
res, err := dbmap.GetWithChilds(post.Post{}, 9999999999, 0, dbpost.Id)
if err != nil {
return errors.New("get failed: " + err.Error())
}
if res == nil {
return errors.New(fmt.Sprintf("Get post for id %d did not return any rows ", dbpost.Id))
}
dbpost = res.(*post.Post)
// Check if an update is needed
var updateNeeded bool
updateNeeded, err = AddUpdatableChilds(htmlpost, dbpost, dbmap)
if err != nil {
return errors.New(fmt.Sprintf("CheckIfDataChanged for post '%s' failed: %s", htmlpost.WebPostId, err.Error()))
}
//if htmlpost.Score != dbpost.Score {
if updateNeeded {
// The post changed, do an update into the database
//fmt.Println("Post Date db: " + dbpost.PostDate.String() + ", html: " + htmlpost.PostDate.String())
//fmt.Printf("Post Score db: %d, html: %d\n", dbpost.Score, htmlpost.Score)
if DebugLevel > 2 {
fmt.Println("----------- UPDATE POST START -----------------")
fmt.Println(dbpost.String("UPDATE1: "))
fmt.Printf("From score %d to score %d\n", dbpost.Score, htmlpost.Score)
}
dbpost.Score = htmlpost.Score
dbpost.PostDate = htmlpost.PostDate
// Reset the rowcount info
dbmap.LastOpInfo.Reset()
// Update the posts together with its comments
affectedrows, err := dbmap.UpdateWithChilds(dbpost)
switch {
case err != nil:
return errors.New("update table " + tm.TableName + " failed: " + err.Error())
case affectedrows == 0:
return errors.New(fmt.Sprintf("update table %s for Id %d did not affect any lines", tm.TableName, dbpost.Id))
default:
updatedPostsCount += dbmap.LastOpInfo.RowCount
insertedPostsCommentCount += dbmap.LastOpInfo.ChildInsertRowCount
updatedPostsCommentCount += dbmap.LastOpInfo.ChildUpdateRowCount
dbpost.CommentCount += uint64(dbmap.LastOpInfo.ChildInsertRowCount)
_, err = dbmap.Update(dbpost)
if err != nil {
return errors.New(fmt.Sprintf("Update for post '%s' failed: %s", dbpost.WebPostId, err.Error()))
}
if DebugLevel > 2 {
// Print out the update info
fmt.Println("----------- UPDATE POST COMMIT -----------------")
fmt.Println(dbpost.String("UPDATE2: "))
fmt.Println("----------- UPDATE POST END -------------------")
}
}
}
}
}
if insertedPostsCount == 0 && updatedPostsCount == 0 {
if DebugLevel > 2 {
fmt.Println("No new posts found at " + geturl)
}
return
}
if DebugLevel > 2 {
fmt.Printf("%d new posts have been inserted from %s\n", insertedPostsCount, geturl)
fmt.Printf("%d posts have been updated from %s\n", updatedPostsCount, geturl)
fmt.Printf("%d new comments have been inserted from %s\n", insertedPostsCommentCount, geturl)
fmt.Printf("%d comments have been updated from %s\n", updatedPostsCommentCount, geturl)
fmt.Printf("%d comment errors\n", htmlCommentErrorCount)
}
return
}
示例2: RedditPostScraper
//.........这里部分代码省略.........
"post_id": htmlpost.WebPostId,
})
if err != nil {
return errors.New(fmt.Sprintf("Query: %s failed: %s\n", postcountsql, err.Error()))
}
if len(intSelectResult) == 0 {
return errors.New(fmt.Sprintf("Query: %s returned no result\n", postcountsql))
}
postcount = intSelectResult[0]
// DEBUG
if DebugLevel > 3 {
fmt.Println("HTMLpost.WebPostId: " + htmlpost.WebPostId)
fmt.Printf("HTMLpost.Id: %v\n", htmlpost.Id)
fmt.Printf("DBpost count: %v \n", postcount)
}
// New post? then insert
if postcount == 0 {
foundnewposts = true
err = dbmap.Insert(&htmlpost)
if DebugLevel > 2 {
// Print out the crawled info
fmt.Println("----------- INSERT POST START -----------------")
fmt.Println(htmlpost.String())
}
if err != nil {
return errors.New("insert into table " + dbmap.Dialect.QuoteField(tablename) + " failed: " + err.Error())
}
if DebugLevel > 2 {
// Print out the end of the crawled info
fmt.Println("----------- INSERT POST END -------------------")
}
} else {
// Post already exists, do an update
dbposts := make([]post.Post, 0)
getpostsql := "select * from " + dbmap.Dialect.QuoteField(tablename) + " where WebPostId = :post_id"
_, err := dbmap.Select(&dbposts, getpostsql, map[string]interface{}{
"post_id": htmlpost.WebPostId,
})
if err != nil {
return errors.New(fmt.Sprintf("Getting WebPostId %s from DB failes\n", htmlpost.WebPostId, err.Error()))
}
var dbpost post.Post
if len(dbposts) > 0 {
dbpost = dbposts[0]
} else {
return errors.New(fmt.Sprintf("Query: %s returned no result\n", getpostsql))
}
// DEBUG
if DebugLevel > 3 {
fmt.Printf("DBPOST: %s\n", dbpost.String())
fmt.Printf("DBpost.Id: %v\n", dbpost.Id)
fmt.Printf("DBpost.Score: %v\n", dbpost.Score)
}
if htmlpost.Score != dbpost.Score {
if DebugLevel > 2 {
// Print out the update info
fmt.Println("----------- UPDATE POST START -----------------")
fmt.Println("Title: " + dbpost.Title)
fmt.Printf("Id: %v\n", dbpost.Id)
fmt.Printf("From score %d to score %d\n", dbpost.Score, htmlpost.Score)
fmt.Println("----------- UPDATE POST END -------------------")
}
dbpost.Score = htmlpost.Score
affectedrows, err := dbmap.Update(&dbpost)
switch {
case err != nil:
return errors.New("update table " + tablename + " failed: " + err.Error())
case affectedrows == 0:
return errors.New(fmt.Sprintf("update table %s for Id %d did not affect any lines", tablename, dbpost.Id))
default:
updatedposts++
}
}
}
} else {
if DebugLevel > 1 {
fmt.Println("Single post error in " + geturl + ": " + htmlpost.Err.Error())
}
}
}
if !foundnewposts {
if DebugLevel > 2 {
fmt.Println("No new posts found at " + geturl)
}
}
if updatedposts > 0 {
if DebugLevel > 2 {
fmt.Printf("%d posts have been updated from %s\n", updatedposts, geturl)
}
}
return
}
示例3: HackerNewsPostScraper
//.........这里部分代码省略.........
intSelectResult := make([]int, 0)
postcountsql := "select count(*) from " + dbmap.Dialect.QuoteField(tablename) +
" where WebPostId = :post_id"
_, err := dbmap.Select(&intSelectResult, postcountsql, map[string]interface{}{
"post_id": htmlpost.WebPostId,
})
if err != nil {
return errors.New(fmt.Sprintf("Query: %s failed: %s\n", postcountsql, err.Error()))
}
if len(intSelectResult) == 0 {
return errors.New(fmt.Sprintf("Query: %s returned no result\n", postcountsql))
}
postcount := intSelectResult[0]
// New post? then insert
if postcount == 0 {
// Insert the new post into the database
err = dbmap.Insert(htmlpost)
if DebugLevel > 2 {
// Print out the crawled info
fmt.Println("----------- INSERT POST START -----------------")
fmt.Println(htmlpost.String())
}
if err != nil {
return errors.New("insert into table " + dbmap.Dialect.QuoteField(tablename) + " failed: " + err.Error())
}
if DebugLevel > 2 {
// Print out the end of the crawled info
fmt.Println("----------- INSERT POST END -------------------")
}
insertedPostsCount++
} else {
// Post already exists, do an update
// Create a slice of posts to select into
dbposts := make([]post.Post, 0)
getpostsql := "select * from " + dbmap.Dialect.QuoteField(tablename) + " where WebPostId = :post_id"
_, err := dbmap.Select(&dbposts, getpostsql, map[string]interface{}{
"post_id": htmlpost.WebPostId,
})
if err != nil {
return errors.New(fmt.Sprintf("Getting WebPostId %s from DB failed: %s\n", htmlpost.WebPostId, err.Error()))
}
var dbpost post.Post
if len(dbposts) > 0 {
dbpost = dbposts[0]
} else {
return errors.New(fmt.Sprintf("Query: %s returned no result\n", getpostsql))
}
if htmlpost.Score != dbpost.Score {
// The post score changed, do an update into the database
//fmt.Println("Post Date db: " + dbpost.PostDate.String() + ", html: " + htmlpost.PostDate.String())
//fmt.Printf("Post Score db: %d, html: %d\n", dbpost.Score, htmlpost.Score)
if DebugLevel > 2 {
fmt.Println("----------- UPDATE POST START -----------------")
fmt.Println(dbpost.String())
fmt.Printf("From score %d to score %d\n", dbpost.Score, htmlpost.Score)
}
dbpost.Score = htmlpost.Score
dbpost.PostDate = htmlpost.PostDate
affectedrows, err := dbmap.Update(&dbpost)
switch {
case err != nil:
return errors.New("update table " + tablename + " failed: " + err.Error())
case affectedrows == 0:
return errors.New(fmt.Sprintf("update table %s for Id %d did not affect any lines", tablename, dbpost.Id))
default:
updatedPostsCount++
if DebugLevel > 2 {
// Print out the update info
fmt.Println("----------- UPDATE POST COMMIT -----------------")
fmt.Println(dbpost.String())
fmt.Println("----------- UPDATE POST END -------------------")
}
}
}
}
}
if insertedPostsCount == 0 && updatedPostsCount == 0 {
if DebugLevel > 2 {
fmt.Println("No new posts found at " + geturl)
}
}
if updatedPostsCount > 0 && DebugLevel > 2 {
fmt.Printf("%d existing posts have been updated from %s\n", updatedPostsCount, geturl)
}
if insertedPostsCount > 0 && DebugLevel > 2 {
fmt.Printf("%d new posts have been inserted from %s\n", insertedPostsCount, geturl)
}
return
}