Started adding query

This commit is contained in:
Riccardo
2022-07-16 11:31:09 +02:00
parent 54b2dda79a
commit a922a905c0
5 changed files with 46 additions and 7 deletions

13
main.go
View File

@@ -8,6 +8,7 @@ import (
"hackernewsletter/hackernews"
"hackernewsletter/params"
"log"
"time"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
@@ -38,12 +39,12 @@ func main() {
TableName: table,
}
newTable := db.Table{client, *table}
newsTable := db.Table{client, *table, conf.TableIndex}
resp, err := db.GetTableInfo(context.TODO(), client, input)
if err != nil {
println(("Table not found. Creating it..."))
_, new_err := db.CreateTable(newTable)
_, new_err := db.CreateTable(newsTable)
if new_err != nil {
panic("Failed creating table " + *table)
}
@@ -62,5 +63,11 @@ func main() {
newsBatch = append(newsBatch, myNews)
}
db.AddNewsBatch(newTable, newsBatch, conf.BatchSize)
db.AddNewsBatch(newsTable, newsBatch, conf.BatchSize)
timeEnd := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
timeStart := timeEnd.Add(-time.Hour * 24)
todayNews, _ := db.ReadTodayNews(newsTable, int(timeStart.Unix()), int(timeEnd.Unix()))
println("NEWS", todayNews)
}