forked from tjhowse/cacheodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (66 loc) · 1.44 KB
/
main.go
File metadata and controls
74 lines (66 loc) · 1.44 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"math/rand"
"os"
"time"
log "github.com/sirupsen/logrus"
)
func main() {
var err error
verbose := flag.Bool("v", false, "Verbose logging")
flag.Parse()
if *verbose {
// Set the log level to debug
log.SetLevel(log.DebugLevel)
}
// Set the log format to include a leading timestamp in ISO8601 format
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
config, err := NewDatastore("config.toml")
if err != nil {
log.Fatal(err)
os.Exit(1)
}
var api GeocachingAPIer
if api, err = NewGeocachingAPI(config.Store.Configuration); err != nil {
log.Fatal(err)
os.Exit(1)
}
var g *Geocaching
if g, err = NewGeocaching(config.Store, api); err != nil {
log.Fatal(err)
os.Exit(1)
}
defer g.Close()
var m *Mastodon
for {
if posts, err := g.Update(); err == nil {
for _, post := range posts {
if m == nil {
m, err = NewMastodon()
if err != nil {
log.Println(err)
}
}
if post.NewCache {
// Don't post about new caches yet.
continue
}
postString := post.toString()
// log.Println("Posted to Mastodon: " + postString)
if err := m.PostStatus(postString); err != nil {
log.Println(err)
m = nil
} else {
log.Println("Posted to Mastodon: " + postString)
}
}
} else {
log.Println(err)
}
// Wait a random number of minutes between 3 and 8
time.Sleep(time.Duration(rand.Intn(5*60)+3*60) * time.Second)
}
}