diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c14a297 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +go.sum \ No newline at end of file diff --git a/go.mod b/go.mod index ec28d39..189b1b4 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,12 @@ module github.com/mrahbar/my-bloody-hetzner-sb-notifier + +require ( + cloud.google.com/go v0.31.0 + github.com/golang/protobuf v1.2.0 + github.com/googleapis/gax-go v2.0.0+incompatible // indirect + go.opencensus.io v0.18.0 // indirect + golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 // indirect + google.golang.org/api v0.0.0-20181021000519-a2651947f503 // indirect + google.golang.org/genproto v0.0.0-20181016170114-94acd270e44e + google.golang.org/grpc v1.16.0 // indirect +) diff --git a/instrumentation/instrumentation.go b/instrumentation/instrumentation.go new file mode 100644 index 0000000..0a79ce7 --- /dev/null +++ b/instrumentation/instrumentation.go @@ -0,0 +1,11 @@ +package instrumentation + +type Instrumenter struct{ + projectId string +} + +func NewInstrumenter(projectId string) *Instrumenter { + return &Instrumenter{ + projectId: projectId, + } +} \ No newline at end of file diff --git a/main.go b/main.go index b6d3f02..03a5c5b 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "github.com/mrahbar/my-bloody-hetzner-sb-notifier/client" c "github.com/mrahbar/my-bloody-hetzner-sb-notifier/crawler" "github.com/mrahbar/my-bloody-hetzner-sb-notifier/hetzner" - n "github.com/mrahbar/my-bloody-hetzner-sb-notifier/notifier" ) var ( @@ -106,8 +105,7 @@ func main() { fmt.Printf("Got %d offers. Filtered offers: %d\n", len(offers.Server), len(servers)) crawler.Print(servers) - notifier := n.NewNotifier(*notifierRecipient, *notifierSender, *notifierPassword) - notifier.Act(servers) + //notifier := n.NewInstrumenter(*notifierRecipient, *notifierSender, *notifierPassword) } else { fmt.Println("Got no offers.") } diff --git a/notifier/notifier.go b/notifier/notifier.go deleted file mode 100644 index ccab034..0000000 --- a/notifier/notifier.go +++ /dev/null @@ -1,95 +0,0 @@ -package notifier - -import ( - "bytes" - "fmt" - "github.com/mrahbar/my-bloody-hetzner-sb-notifier/hetzner" - "mime/quotedprintable" - "net/smtp" - "strings" -) - -const ( - gmailSmtpServer = "smtp.gmail.com" - contentTypeHtml = "text/html" - contentTypePlain = "text/plain" -) - -type Notifier struct { - to string - contentType string - user string - password string - server string - port int - history map[string]float64 -} - -func NewNotifier(Recipient, Username, Password string) Notifier { - notifier := Notifier{ - Recipient, - contentTypePlain, - Username, - Password, - gmailSmtpServer, - 587, - make(map[string]float64), - } - return notifier -} - -func (n Notifier) Act(servers []hetzner.Server) { - //absentFromHistory := false - // - //for _, s := range servers { - // // TODO check if server in history, if a single server is missing send email and store state - //} -} - -func (n Notifier) sendMail(Dest []string, Subject, bodyMessage string) { - - msg := "From: " + n.user + "\n" + - "To: " + strings.Join(Dest, ",") + "\n" + - "Subject: " + Subject + "\n" + bodyMessage - - err := smtp.SendMail(fmt.Sprintf("%s:%d", n.server, n.port), - smtp.PlainAuth("", n.user, n.password, n.server), - n.user, Dest, []byte(msg)) - - if err != nil { - - fmt.Printf("smtp error: %s", err) - return - } - - fmt.Println("Mail sent successfully!") -} - -func (n Notifier) writeEmail(subject, bodyMessage string) string { - - header := make(map[string]string) - header["From"] = n.user - - header["To"] = n.to - header["Subject"] = subject - header["MIME-Version"] = "1.0" - header["Content-Type"] = fmt.Sprintf("%s; charset=\"utf-8\"", n.contentType) - header["Content-Transfer-Encoding"] = "quoted-printable" - header["Content-Disposition"] = "inline" - - message := "" - - for key, value := range header { - message += fmt.Sprintf("%s: %s\r\n", key, value) - } - - var encodedMessage bytes.Buffer - - finalMessage := quotedprintable.NewWriter(&encodedMessage) - finalMessage.Write([]byte(bodyMessage)) - finalMessage.Close() - - message += "\r\n" + encodedMessage.String() - - return message -} \ No newline at end of file