def report_to_dashboard(serviceType, oldReqUnprocessed): try: record = DashboardServiceRecord.objects.get(service_type=serviceType) except DashboardServiceRecord.DoesNotExist: log.debug('create a new entry in dashboard service record table %s' % serviceType) record = DashboardServiceRecord.objects.create(service_type=serviceType, service_status=True, latest_checkedtime=current_time) if oldReqUnprocessed: log.debug('there are unprocessed jobs pending in %s' % serviceType) error_record = record error_record.service_status = False error_record.latest_checkedtime = current_time error_record.save() try: add_to_mail_queue( '*****@*****.**', '*****@*****.**', '[STATUS UPDATE] %s -Slow/Not Working' % serviceType, 'You need to check db table of: %s . Service found Slow/Not Working at %s.' % (serviceType, error_record.latest_checkedtime)) except Exception, e: log.debug(e) log.debug('email service is down')
def send_invitations(user, invitees, personal_message=""): sender_email = user.email subject = "%s has invited you try Flowgram.com" % sender_email t = get_template('emails/invite.txt') use_regcode = FEATURE['use_regcode'] successes = [] failures = [] for email in invitees: r = Regcode.objects.create(sender=user) c = Context({ 'user' : user, 'regcode': r.code, 'use_regcode': use_regcode, 'to': email, 'URL_BASE' : URL_BASE, 'personal_message' : personal_message }) body = t.render(c) try: log.debug("send_mail from send_invitations to " + email) add_to_mail_queue(sender_email, email, subject, body) successes.append(email) except: failures.append(email) return successes, failures
def fetch(self): tasksUnprocessed = models.PptImportRequest.objects.filter(status_code=models.StatusCode.UNPROCESSED).filter(uploaded_to_s3=True) tasksProcessing = models.PptImportRequest.objects.filter(status_code=models.StatusCode.PROCESSING) tasksTimedOut = tasksProcessing.filter(started_at__lte=datetime.now() - RETRY_TIME) tasks = tasksUnprocessed | tasksTimedOut if self.last_time: tasks = tasks.exclude(timestamp__gte=self.last_time) count = tasks.count() if self.last_time: if self.last_count <= count: add_to_mail_queue( '*****@*****.**', '*****@*****.**', '[STATUS UPDATE] Doc Import Service - Slow/Not Working', 'Doc Import Service - Slow/Not Working\n\nSincerely,\n- Flowgram') self.last_time = datetime.now() self.last_count = count time.sleep(300)
def announce_feedback(feedback): sender = DEFAULT_SENDER recipients = [FEEDBACK_RECIPIENT] subject = "" text = "URL: %s\nEmail: %s\nSystem info:\n%s\nComments: %s\n" % (feedback.url, feedback.email, feedback.sys_info, feedback.comments) try: log.debug("send_mail from announce_feedback to " + FEEDBACK_RECIPIENT) for recipient in recipients: add_to_mail_queue(sender, recipient, subject, text) except: log.error("Failure in announce_feedback:") log.trace()
def announce_flag(request, flowgram): flagger = request.user.username or request.META['REMOTE_ADDR'] subect = "%s FLAGGED by %s" % (flowgram.title, flagger) sender = DEFAULT_SENDER text = "See the flagged flowgram at %s" % flowgram.url() recipients = ['*****@*****.**'] try: log.debug("send_mail from announce_flag to " + '*****@*****.**') for recipient in recipients: add_to_mail_queue(sender, recipient, subject, text) except: log.error("Failure in announce_flag:") log.trace()
def fetch(self): user_profiles = UserProfile.objects.filter(notify_by_email=True).exclude(notification_freq='') print("got %d user profiles" % len(user_profiles)) for user_profile in user_profiles: user = user_profile.user email_digest_record = None now = datetime.datetime.now() timestamp = None try: email_digest_record = EmailDigestRecord.objects.get(user=user) timestamp = now if user_profile.notification_freq == 'I': timestamp -= datetime.timedelta(seconds=600) elif user_profile.notification_freq == 'D': timestamp -= datetime.timedelta(seconds=86400) elif user_profile.notification_freq == 'W': timestamp -= datetime.timedelta(seconds=604800) if email_digest_record.timestamp > timestamp: continue timestamp = email_digest_record.timestamp email_digest_record.timestamp = now email_digest_record.save() print("user=%s has timestamp=%s" % (user.id, str(now))) except: EmailDigestRecord.objects.create(user=user, timestamp=now) print("user=%s had no EmailDigestRecord so made one with timetsamp=%s" % (user.id, str(now))) content = newsfeed.get_rendered_news_feed(user, user, 'E', timestamp) if content: print("sending email to %s" % user.id) add_to_mail_queue( '*****@*****.**', user.email, '[Flowgram] Your subscription updates', '', content, 'text/html') time.sleep(600)
def contact_us_email(request): if request.method != 'POST': return req_render_to_response(request, 'about_us/contact_us_email.html') name = request.POST.get('name', '') if name == '': name='Anonymous' email = request.POST.get('email', '') subject = request.POST.get('subject', '') if subject == '': subject='I am not big on typing or words.' comments = request.POST.get('comments', '') controller.record_stat(request, 'add_feedback_website', '0', '') add_to_mail_queue( '*****@*****.**', '*****@*****.**', 'Contact via FG Contact Us/Feedback form', 'FROM: %s <%s> | SUBJECT: %s | COMMENTS: %s' % (name, email, subject, comments)) return HttpResponseRedirect('/about_us/contact_us_confirm/')
def inviter(request, enc, recipients, email_body): from django.template import Context, Template from flowgram.queueprocessors.sendemailrequestprocessor import add_to_mail_queue if request.method == 'GET': context = {'from_email' : request.user.email, 'default_email' : DEFAULT_INVITATION + request.user.username} return helpers.req_render_to_response(request, 'admin/inviter.html', context) for recipient in helpers.get_email_addresses_from_comma_separated_string(recipients): context = {} if localsettings.FEATURE['use_regcode']: context['regcode'] = models.Regcode.objects.create(sender=request.user).code # TODO(westphal): Figure out and remove or document: Why are we using unicode and then a # non-unicode string. body = '%s' % unicode(Template(email_body).render(Context(context))) add_to_mail_queue(request.user.email, recipient, "Invitation to Flowgram.com", body) helpers.add_good_message(request, 'Emails added to queue.') return HttpResponseRedirect('/a/inviter/')
def toolbar_share(request, w, recipients, message, from_name = '', from_email = '', cc_self = 'false', subject = '', template = 'share'): from flowgram.core.models import ShareLink if request.user.is_anonymous(): sender = None senderName = from_name if senderName == '': senderName = 'Someone' senderEmail = from_email else: sender = request.user senderName = sender.username senderEmail = sender.email # Filters email addresses when they're given like "Some Name" <*****@*****.**> emailPattern = re.compile('(?:"[^"]*"\s+)?<([^>]+)>') recipients = emailPattern.sub(r'\1', recipients) # Adding sender email to recipients list if cc self is enabled. if cc_self == 'true' and senderEmail != '': recipients += ',' + senderEmail successes = [] failures = [] for recipient in recipients.split(','): recipient = recipient.strip() name = randname() #create ShareLink object sl = ShareLink.objects.create(name=name, flowgram=w, sender=sender, recipient=recipient) #send ascii user email if(subject == ''): subject = "%s (shared Flowgram from %s)" % (w.title, senderName) t = loader.get_template("emails/%s.txt" % template) h = loader.get_template("emails/%s.html" % template) if template == "talking_email": thumbs_list = w.page_set.all()[1:4] else: thumbs_list = w.page_set.all()[:3] c = Context({ #'recipient': recipient, 'sender': sender, 'url': sl.url(), 'message': message, 'w': w, 'owner': w.owner, 'title': w.title, 'from_name': from_name, 'senderName': senderName, 'thumbs_list': thumbs_list, 'thumbs_list_length': len(thumbs_list) }) text = t.render(c) html = h.render(c) # increment share_email counter w.share_emails += 1 w.save() try: add_to_mail_queue(senderEmail, recipient, subject, text, html, 'text/html') except: failures.append(recipient) else: successes.append(recipient) return (successes, failures)
def email_user_html(recipient, subject, html, sender=DEFAULT_SENDER): """Emails a user. If you call email_user, it is your responsibility to try/except""" if isinstance(sender, User): sender = "\"%s @ Flowgram\" <%s>" % (sender.username, sender.email) log.debug("send_mail from email_user to %s" % sender) add_to_mail_queue(sender, recipient.email, subject, '', html, 'text/html')
def process(self, task): print ("processing %s" % task.id) task.attempts += 1 task.started_at = datetime.datetime.now() task.save() success = False title = task.flowgram.title or "Untitled" try: output_dir = tempfile.mkdtemp("", "", os.path.join(tempfile.gettempdir(), "exporttovideo")) + os.sep print ("output_dir = %s" % output_dir) if os.path.isdir(output_dir): shutil.rmtree(output_dir) helpers._mkdir(output_dir) # Rendering the video. Flowgram2Video().run(task.flowgram.id, 640, 480, output_dir, task.use_highlight_popups) copy_to_uploads_directory(task, "%svideo.wmv" % output_dir) save_video_file_to_s3(task, "%svideo.wmv" % output_dir) # Closing out, and notifying corresponding users, open requests for the same video and # options. similar_tasks = ExportToVideoRequest.objects.filter( flowgram=task.flowgram, use_highlight_popups=task.use_highlight_popups, status_code__in=(StatusCode.UNPROCESSED, StatusCode.PROCESSING), ) for close_task in similar_tasks: preview_url = "http://%s/%s.wmv" % (localsettings.S3_BUCKETS[localsettings.S3_BUCKET_UPLOAD], task.id) export_url = "%sexport/youtube/%s/" % (localsettings.my_URL_BASE, task.id) recipient = close_task.request_user.username if close_task.request_user else "" subject = "Your Flowgram Video is now ready" template = loader.get_template("emails/video_export.html") context = Context( { "recipient": recipient, "recipient_url": localsettings.my_URL_BASE + recipient, "recipient_email": close_task.request_email, "title": title, "fg_url": "%sp/%s/" % (localsettings.my_URL_BASE, task.flowgram.id), "fg_owner": task.flowgram.owner, "fg_owner_url": "%s%s" % (localsettings.my_URL_BASE, task.flowgram.owner), "preview_url": preview_url, "export_url": export_url, "contact_us": localsettings.my_URL_BASE + "about_us/contact_us/", "image_url": "%sapi/getthumbbydims/fg/%s/%d/%d/" % (localsettings.my_URL_BASE, task.flowgram.id, 150, 100), } ) print "Notice: %sapi/getthumbbydims/fg/%s/%d/%d/" % ( localsettings.my_URL_BASE, task.flowgram.id, 150, 100, ) html_content = template.render(context) add_to_mail_queue( "*****@*****.**", close_task.request_user.email if close_task.request_user != ANONYMOUS_USER_OBJECT else close_task.request_email, subject, "", html_content, "text/html", ) close_task.status_code = StatusCode.DONE close_task.save() success = True except: traceback.print_exc(file=sys.stdout) print ("Failed attempt to encode video for Flowgram: %s" % task.flowgram.id) finally: if not success: if task.attempts >= MAX_ATTEMPTS: add_to_mail_queue( "*****@*****.**", task.request_user.email if task.request_user else task.request_user.email, 'Flowgram Video "%s" Processing Error' % (task.flowgram.title or "Untitled"), 'The video of the Flowgram "%s" could not be processed at this time. We have recorded this problem and will look into the cause. Sorry for the inconvenience.' % title, ) task.status_code = StatusCode.ERROR task.save() if localsettings.VIDEO["delete_temp_files"]: shutil.rmtree(output_dir)