def handle(self, *args, **options): Connection = subscribe_connection() for email in CustomMailMulti.objects.filter(status = "created"): text_content = strip_tags(email.Text) for item in UserCustomSettings.objects.filter(setting__title = "news_notify" ): if item.value == "yes" and item.user.email!='': print "send message to %s email %s" % (item.user.username, item.user.email) msg = EmailMultiAlternatives(email.Subject, text_content, email.From, [item.user.email], connection = Connection) msg.attach_alternative(email.Text, "text/html") msg.send() time.sleep(1) email.status="processed" email.save()
def handle(self, *args, **options): BaseUrl = crypton.settings.BASE_URL ##using it's own api Decoder = json.JSONDecoder() Url = BaseUrl + "api/trades/sell/btc_uah?_=%s" % (str(time.localtime())) Str = None try: D = urllib2.urlopen(Url) Str = D.read() except: sys.exit(0) Url = BaseUrl + "api/trades/buy/btc_uah?_=%s" % (str(time.localtime())) StrBuy = None try: D = urllib2.urlopen(Url) StrBuy = D.read() except: sys.exit(0) ResBuy = Decoder.decode(StrBuy) Res = Decoder.decode(Str) # ResList = [] #for item in Res["list"]: Dict = {"orders": Res["list"], "whole_sum": Res["orders_sum"], "whole_sum_buy": ResBuy["orders_sum"], "buy_orders": ResBuy["list"] } tmpl = loader.get_template("rates_subscribe.html") c = Context( Dict ) Connection = subscribe_connection() text_content = tmpl.render(c) for item in UserCustomSettings.objects.filter(setting__title="rate_notify"): if item.value == "yes" and item.user.email != '': print "send message to %s email %s " % (item.user.username, item.user.email) msg = EmailMultiAlternatives(_(u"Уведомление о курсах BTC TRADE UA"), text_content, crypton.settings.SERVER_EMAIL, [item.user.email], connection=Connection) msg.attach_alternative(text_content, "text/html") try: msg.send() except: print "Unexpected error:", sys.exc_info()[0] time.sleep(1)