-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathimport.go
More file actions
46 lines (35 loc) · 1.01 KB
/
Copy pathimport.go
File metadata and controls
46 lines (35 loc) · 1.01 KB
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
package main
import (
"context"
"log"
"time"
"github.com/nbd-wtf/go-nostr"
)
const layout = "2006-01-02"
func importNotes(kind int) {
ctx := context.Background()
startDate := time.Now().Add(-3 * 24 * time.Hour)
startTime, _ := time.Parse(layout, startDate.Format(layout))
endTime := startTime.Add(24 * time.Hour)
for {
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
startTimestamp := nostr.Timestamp(startTime.Unix())
endTimestamp := nostr.Timestamp(endTime.Unix())
filters := []nostr.Filter{{
Kinds: []int{kind},
Since: &startTimestamp,
Until: &endTimestamp,
}}
for ev := range pool.SubManyEose(ctx, relays, filters) {
repository.SaveNostrEvent(ev.Event)
}
startTime = startTime.Add(24 * time.Hour)
endTime = endTime.Add(24 * time.Hour)
if startTime.After(time.Now()) {
log.Println("✅ imported notes of kind:", kind)
break
}
log.Println("importing notes of kind:", kind, "from", startTime.Format(layout), "to", endTime.Format(layout))
}
}