Пример #1
0
func main() {

	fmt.Println("Start mailagent")

	user := flag.String("user", "", "Smtp user")
	pass := flag.String("pass", "", "Smtp password")
	timer := flag.Int("timer", 5, "timer in minutes")

	cfg := common.NewConfig()
	delay := time.Duration(*timer) * time.Minute

	db := common.NewDbClient(cfg.Service.Redis)

	if *user == "" || *pass == "" {
		fmt.Println("No user or password")
		return
	}

	execMe := func() {
		incomingFile := dumpIncoming(db)
		//acceptedFile := dumpAccepted(db)
		defer os.Remove(incomingFile)
		//		defer os.Remove(acceptedFile)

		md5Hash, err := ComputeMd5(incomingFile)
		if err == nil {
			if md5Hash != "" && prevMd5Hash == md5Hash {
				common.Trace.Println("Ignore sendign file. hashes the same: " + md5Hash)
				return
			}
			prevMd5Hash = md5Hash
		}
		err = sendEmail(*user, *pass, incomingFile /*, acceptedFile*/)
		if err != nil {
			fmt.Println("Send message error", err)
			return
		}
	}

	execMe()

	ticker := time.NewTicker(delay)
	go func() {
		for {
			select {
			case <-ticker.C:
				execMe()
			}
		}
	}()

	fmt.Println("press Ctrl+C")
	common.WaitCtrlC()

	ticker.Stop()
}
Пример #2
0
import (
	"encoding/json"
	"fmt"
	"gopkg.in/redis.v3"
	"tad-demo/common"
	"tad-demo/common/opencell-api"
	"time"
)

const (
	opencellUser   = "******"
	JSON_STATS_KEY = "json_stats"
)

var cfg = common.NewConfig()
var db = common.NewDbClient(cfg.Service.Redis)
var restcommApi = common.NewRestcommApi(cfg.Service.Restcomm, cfg.Auth.User, cfg.Auth.Pass)
var opencellApi = opencell_api.NewOpencellAPI(cfg.Opencell.Password, cfg.Opencell.Host)

type Caller struct {
	Sid         string  `json:"sid"`
	Time        float64 `json:"duration"`
	PhoneNumber string  `json:"to"`
}

func NewCaller(sid string, time float64, phoneNumber string) Caller {
	return Caller{
		Sid:         sid,
		Time:        time,
		PhoneNumber: phoneNumber}
}