-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (41 loc) · 1019 Bytes
/
main.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
package main
import (
"flag"
"log"
"time"
)
func main() {
var db_path, last_path, token string
var chat0, chat1 string
var sleep_time int
flag.StringVar(&db_path, "db", "/tmp/db.db", "database dump path")
flag.StringVar(&last_path, "last", "last", "last save path")
flag.StringVar(&token, "token", "", "telegram token")
flag.StringVar(&chat0, "chat0", "", "chatid 0")
flag.StringVar(&chat1, "chat1", "", "chatid 1")
flag.IntVar(&sleep_time, "sleep", 10, "sleep time in second")
flag.Parse()
bot := TGBOT{}
bot.Init(token, chat0, chat1)
db := Database{last_path: last_path, db_path: db_path}
db.Init()
for {
log.Println("Start pull and read database.")
smses, err := db.Read()
log.Printf("%d sms read.\n", len(smses))
if err == nil {
var last int64
for _, sms := range smses {
if bot.Send(sms) != nil {
log.Println(err)
} else {
last = sms.date
}
}
db.Save(last)
} else {
log.Println(err)
}
time.Sleep(time.Duration(sleep_time) * time.Second)
}
}