forked from The-Eye-Team/reddit-dl
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpost.go
52 lines (42 loc) · 1.58 KB
/
post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
dbstorage "github.com/nektro/go.dbstorage"
"github.com/valyala/fastjson"
)
type tPost struct {
ID int64 `json:"id"`
IDS string
Subreddit string `json:"subreddit" sqlite:"text"`
PostID string `json:"post_id" sqlite:"text"`
Title string `json:"title" sqlite:"text"`
PostJson string `json:"json" sqlite:"text"`
Link string `json:"link" sqlite:"text"`
Author string `json:"author" sqlite:"text"`
Submitted int64 `json:"submitted_at" sqlite:"int"`
}
func insertPost(sub, post, title, pjson, link, author string, submittedAt int64) {
dbP.Build().Ins("posts").Lock()
id := dbP.QueryNextID("posts")
dbP.QueryPrepared(true, "insert into posts values (?, ?, ?, ?, ?, ?, ?, ?)", id, sub, post, title, pjson, link, author, submittedAt)
dbP.Build().Ins("posts").Unlock()
}
func doesPostExist(post string) bool {
return dbstorage.QueryHasRows(dbP.Build().Se("*").Fr("posts").Wh("post_id", post).Exe())
}
func postListingCb(t, name string, item *fastjson.Value) (bool, bool) {
id := string(item.GetStringBytes("data", "id"))
//
if doesPostExist(id) {
return true, true
}
title := string(item.GetStringBytes("data", "title"))
pjson := string(item.MarshalTo([]byte{}))
urlS := string(item.GetStringBytes("data", "url"))
sub := string(item.GetStringBytes("data", "subreddit"))
author := string(item.GetStringBytes("data", "author"))
postedAt := int64(item.GetFloat64("data", "created_utc"))
insertPost(sub, id, title, pjson, urlS, author, postedAt)
dir := DoneDir + "/" + sub
go downloadPost(t, name, id, urlS, dir, title)
return false, false
}