-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
66 lines (54 loc) · 1.28 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"log"
"os"
"os/signal"
"unsafe"
"github.com/ahmdrz/goinsta"
"github.com/ahmdrz/goinsta/utils"
"github.com/marcsantiago/gocron"
)
var (
insta *goinsta.Instagram
tgBot = flag.String("n", "", "Telegram bot api id")
tgID = flag.Int64("g", 0, "Telegram chat id")
targets = flag.String("t", "./targets", "Targets file")
logfile = flag.String("l", "./icrawler.log", "Log file")
outDir = flag.String("o", "./files", "Output directory or storing directory")
dbFile = flag.String("d", "./instagram.db", "Instagram database")
uptime = flag.Uint64("u", 15, "Update time in minutes")
)
func init() {
flag.Parse()
if *tgID == 0 {
panic("tgid must be specified")
}
if *tgBot == "" {
panic("tgbot must be specified")
}
os.MkdirAll(*outDir, 0700)
}
func main() {
// login
insta = utils.New()
conn := notDial(*tgBot)
defer conn.Close()
log.SetOutput(conn)
wc := watcherController{}
wc.do(*targets)
gocron.Every(*uptime).Minutes().Do(state, &wc, conn)
cron := gocron.Start()
log.Printf("Bot started\n")
go state(&wc, conn)
ch := make(chan os.Signal)
signal.Notify(ch, os.Interrupt)
<-ch
select {
case cron <- struct{}{}: // stops cron jobs
}
log.Print("Stopping bot")
}
func b2s(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}