当前位置: 首页>>代码示例>>Golang>>正文


Golang ComplaintDB.GetComplaintsInSpanByEmailAddress方法代码示例

本文整理汇总了Golang中github.com/skypies/complaints/complaintdb.ComplaintDB.GetComplaintsInSpanByEmailAddress方法的典型用法代码示例。如果您正苦于以下问题:Golang ComplaintDB.GetComplaintsInSpanByEmailAddress方法的具体用法?Golang ComplaintDB.GetComplaintsInSpanByEmailAddress怎么用?Golang ComplaintDB.GetComplaintsInSpanByEmailAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skypies/complaints/complaintdb.ComplaintDB的用法示例。


在下文中一共展示了ComplaintDB.GetComplaintsInSpanByEmailAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: bksvSubmitUserHandler

func bksvSubmitUserHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	cdb := complaintdb.ComplaintDB{C: c, Memcache: true}
	start, end := date.WindowForYesterday()
	bksv_ok, bksv_not_ok := 0, 0

	email := r.FormValue("user")

	if cp, err := cdb.GetProfileByEmailAddress(email); err != nil {
		c.Errorf(" /bksv/submit-user(%s): getprofile: %v", email, err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return

	} else if complaints, err := cdb.GetComplaintsInSpanByEmailAddress(email, start, end); err != nil {
		c.Errorf(" /bksv/submit-user(%s): getcomplaints: %v", email, err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return

	} else {
		for i, complaint := range complaints {
			time.Sleep(time.Millisecond * 200)
			if debug, err := bksv.PostComplaint(urlfetch.Client(c), *cp, complaint); err != nil {
				//cdb.C.Infof("pro: %v", cp)
				//cdb.C.Infof("comp: %#v", complaint)
				cdb.C.Errorf("BKSV posting error: %v", err)
				cdb.C.Infof("BKSV Debug\n------\n%s\n------\n", debug)
				bksv_not_ok++
			} else {
				if i == 0 {
					cdb.C.Infof("BKSV [OK] Debug\n------\n%s\n------\n", debug)
				}
				bksv_ok++
			}
		}
	}

	c.Infof("bksv for %s, %d/%d", email, bksv_ok, bksv_not_ok)
	if bksv_not_ok > 0 {
		c.Errorf("bksv for %s, %d/%d", email, bksv_ok, bksv_not_ok)
	}
	w.Write([]byte("OK"))
}
开发者ID:hugoh,项目名称:complaints,代码行数:42,代码来源:email.go

示例2: bksvScanYesterdayHandler

// Examine all users. If they had any complaints, throw them in the queue.
func bksvScanYesterdayHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	cdb := complaintdb.ComplaintDB{C: c, Memcache: true}
	var cps = []types.ComplainerProfile{}
	cps, err := cdb.GetAllProfiles()
	if err != nil {
		c.Errorf(" /bksv/scan-yesterday: getallprofiles: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	start, end := date.WindowForYesterday()
	bksv_ok := 0

	for _, cp := range cps {
		if cp.CcSfo == false {
			continue
		}

		var complaints = []types.Complaint{}
		complaints, err = cdb.GetComplaintsInSpanByEmailAddress(cp.EmailAddress, start, end)
		if err != nil {
			c.Errorf(" /bksv/scan-yesterday: getbyemail(%s): %v", cp.EmailAddress, err)
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		if len(complaints) > 0 {
			t := taskqueue.NewPOSTTask("/bksv/submit-user", map[string][]string{
				"user": {cp.EmailAddress},
			})
			if _, err := taskqueue.Add(c, t, "submitreports"); err != nil {
				c.Errorf(" /bksv/scan-yesterday: enqueue: %v", err)
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			bksv_ok++
		}
	}
	c.Infof("enqueued %d bksv", bksv_ok)
	w.Write([]byte(fmt.Sprintf("OK, enqueued %d", bksv_ok)))
}
开发者ID:hugoh,项目名称:complaints,代码行数:42,代码来源:email.go

示例3: emailHandler

func emailHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	session := sessions.Get(r)
	cdb := complaintdb.ComplaintDB{C: c}

	cp, err := cdb.GetProfileByEmailAddress(session.Values["email"].(string))
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	start, end := date.WindowForYesterday()
	// end = time.Now()
	complaints, err2 := cdb.GetComplaintsInSpanByEmailAddress(cp.EmailAddress, start, end)
	if err2 != nil {
		http.Error(w, err2.Error(), http.StatusInternalServerError)
		return
	}

	var cap = types.ComplaintsAndProfile{
		Profile:    *cp,
		Complaints: complaints,
	}

	if err := templates.ExecuteTemplate(w, "email-update", map[string]interface{}{}); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	} else {
		return
	}

	msg, err3 := GenerateEmail(c, cap)
	if err3 != nil {
		http.Error(w, err3.Error(), http.StatusInternalServerError)
		return
	}
	cap.Profile.CcSfo = true
	if len(cap.Complaints) == 0 {
		http.Error(w, "No complaints found ?!", http.StatusInternalServerError)
		return
	}
	msg2, err4 := GenerateSingleComplaintEmail(c, cap.Profile, cap.Complaints[len(cap.Complaints)-1])
	if err4 != nil {
		http.Error(w, err4.Error(), http.StatusInternalServerError)
		return
	}

	var params = map[string]interface{}{
		"Cap":             cap,
		"EmailBundle":     msg,
		"EmailSingle":     msg2,
		"EmailBundleBody": template.HTML(msg.HTMLBody),
		"EmailSingleBody": template.HTML(msg2.HTMLBody),
	}

	/* if err4 := sendViaHTTPGateway(c, msg); err4 != nil {
		http.Error(w, err4.Error(), http.StatusInternalServerError)
		return
	} */

	if err := templates.ExecuteTemplate(w, "email-debug", params); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
开发者ID:hugoh,项目名称:complaints,代码行数:64,代码来源:email.go

示例4: SendComplaintsWithSpan

func SendComplaintsWithSpan(c appengine.Context, start, end time.Time) (err error) {
	c.Infof("--- Emails, %s -> %s", start, end)

	blacklist := map[string]bool{}
	for _, e := range blacklistAddrs {
		blacklist[e] = true
	}

	cdb := complaintdb.ComplaintDB{C: c, Memcache: true}
	var cps = []types.ComplainerProfile{}
	cps, err = cdb.GetAllProfiles()
	if err != nil {
		return
	}

	complaints_private, complaints_submitted, no_data, sent_ok, sent_fail := 0, 0, 0, 0, 0
	sent_single_ok, sent_single_fail := 0, 0

	for _, cp := range cps {
		var complaints = []types.Complaint{}
		complaints, err = cdb.GetComplaintsInSpanByEmailAddress(cp.EmailAddress, start, end)

		if err != nil {
			c.Errorf("Could not get complaints [%v->%v] for <%s>: %v", start, end, cp.EmailAddress, err)
			no_data++
			continue
		}
		if len(complaints) == 0 {
			no_data++
			continue
		}

		// Emailing disabled; last run was Fri Oct 9, 4am, with data for Oct 8. BKSV is now live.
		if false {
			if cp.CcSfo == true {
				for _, complaint := range complaints {
					if msg, err := GenerateSingleComplaintEmail(c, cp, complaint); err != nil {
						c.Errorf("Could not generate single email to <%s>: %v", cp.EmailAddress, err)
						sent_single_fail++
						continue
					} else {
						if blacklist[cp.EmailAddress] {
							sent_single_fail++
						} else {
							if err := mail.Send(c, msg); err != nil {
								c.Errorf("Could not send email to <%s>: %v", cp.EmailAddress, err)
								sent_single_fail++
								continue
							} else {
								sent_single_ok++
							}
						}
					}
				}
			}
		}

		var cap = types.ComplaintsAndProfile{
			Profile:    cp,
			Complaints: complaints,
		}

		var msg *mail.Message
		if msg, err = GenerateEmail(c, cap); err != nil {
			c.Errorf("Could not generate email to <%s>: %v", cp.EmailAddress, err)
			sent_fail++
			continue
		}

		useGateway := false

		if useGateway {
			if err = sendViaHTTPGateway(c, msg); err != nil {
				c.Errorf("Could not gateway email to <%s>: %v", cp.EmailAddress, err)
				sent_fail++
				continue
			}
		} else {
			if blacklist[cp.EmailAddress] {
				sent_fail++
			} else {
				if err = mail.Send(c, msg); err != nil {
					c.Errorf("Could not send email to <%s>: %v", cp.EmailAddress, err)
					sent_fail++
					continue
				}
			}
		}

		if cap.Profile.CcSfo == true {
			complaints_submitted += len(cap.Complaints)
		} else {
			complaints_private += len(cap.Complaints)
		}
		sent_ok++
	}

	subject := fmt.Sprintf("Daily report stats: users:%d/%d  reports:%d/%d  emails:%d:%d",
		sent_ok, (sent_ok + no_data),
		complaints_submitted, (complaints_submitted + complaints_private),
//.........这里部分代码省略.........
开发者ID:hugoh,项目名称:complaints,代码行数:101,代码来源:email.go


注:本文中的github.com/skypies/complaints/complaintdb.ComplaintDB.GetComplaintsInSpanByEmailAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。