You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

52 lines
854 B

package main
import (
"context"
"database/sql"
"log"
"os"
"github.com/jessevdk/go-flags"
"github.com/joho/godotenv"
"github.com/vartanbeno/go-reddit/v2/reddit"
_ "modernc.org/sqlite"
)
var ctx = context.Background()
var opt *Options
func init() {
opt = &Options{}
_, err := flags.Parse(opt)
if err != nil {
os.Exit(1)
}
}
func main() {
if len(opt.Init) >= 1 {
if opt.Init[0] == true {
InitDb(opt.DB)
}
}
godotenv.Load()
subreddit := os.Getenv("SUB")
if err := run(subreddit); err != nil {
log.Fatal(err)
}
}
func run(subreddit string) (err error) {
posts, _, err := reddit.DefaultClient().Subreddit.NewPosts(ctx, subreddit, &reddit.ListOptions{Limit: 5})
if err != nil {
return
}
db, err := sql.Open("sqlite3", opt.DB+".db")
for i := 0; i < 5; i++ {
insert(db, posts[i])
}
getNewest()
getFiles()
return
}