コード例 #1
0
 def get(self, date_from, date_to, rut):
     if date_from and date_to and rut:
         date_from = int(date_from)
         date_to = int(date_to)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         rut = str(rut)
         # parametros de datatables
         sEcho = self.request.get('sEcho')
         sEcho = int(sEcho, base=10)
         iDisplayStart = self.request.get('iDisplayStart')
         iDisplayStart = int(iDisplayStart, base=10)
         iDisplayLength = self.request.get('iDisplayLength')
         iDisplayLength = int(iDisplayLength, base=10)
         # hacer la consulta
         query = EmailModel.get_emails_by_rut_receptor(
             date_from, date_to, rut,
             display_start=iDisplayStart, display_length=iDisplayLength)
         context = {
             'sEcho': sEcho,
             'data': JSONEncoder().default(query['data']),
             'iTotalDisplayRecords': query['query_total'],
             'iTotalRecords': query['query_total'],
         }
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(json.dumps(context))
     else:
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(json.dumps({'message': 'error'}))
コード例 #2
0
 def post(self):
     correo = self.request.get('correo')
     numero_folio = self.request.get('numero_folio')
     tipo_dte = self.request.get('tipo_dte')
     # Valicacion de datos
     if (correo, numero_folio, tipo_dte):
         # Proceso de creación del objeto email
         my_email = EmailModel()
         email_result = my_email.search_email(
             correo, numero_folio, tipo_dte)
         if not email_result == None:
             # Iniciando el proceso de envío de correo
             sg_email = EmailClient()
             sg_email.send_sg_email(email_result)
         else:
             logging.info('Correo no existe')
     else:
         logging.error("PARAMETROS INCORRECTOS")
コード例 #3
0
	def get(self):
		http = decorator.http()
		param_from = int(self.request.get('from_date'))
		param_to = int(self.request.get('to_date'))
		param_from = datetime.datetime.fromtimestamp(param_from)
		param_to = datetime.datetime.fromtimestamp(param_to)
		graphData = EmailModel.get_count_statistic_by_dates(param_from, param_to)
		context = {'week': graphData,}
		logging.info(context)
		self.response.write(json.dumps(context))
コード例 #4
0
    def get(self, date_from, date_to, options):

        if date_from and date_to and options:
            date_from = int(date_from)
            date_to = int(date_to)
            date_from = datetime.datetime.fromtimestamp(date_from)
            date_to = datetime.datetime.fromtimestamp(date_to)
            # busqueda de datos
            data = EmailModel.get_statistic_by_dates(
                date_from, date_to, options)
            results = EmailModel.get_stats_by_dates(
                date_from, date_to, options)
            context = {
                'date_from': str(date_from),
                'date_to': str(date_to),
                'statistic': data,
                'results': results,
            }
            self.response.headers['Content-Type'] = 'application/json'
            self.response.write(json.dumps(context))
コード例 #5
0
ファイル: cron_controller.py プロジェクト: roofcat/etracking
	def get(self):
		query = EmailModel.get_email_lagging()
		if query:
			for qry in query:
				context = {
					'correo': qry.correo,
					'numero_folio': qry.numero_folio,
					'tipo_dte': qry.tipo_dte,
				}
				# Inicio taskqueue
				q = taskqueue.Queue('InputQueue')
				t = taskqueue.Task(url='/inputqueue', params=context)
				q.add(t)
		else:
			self.response.write("nada que enviar")
コード例 #6
0
ファイル: test.py プロジェクト: roofcat/etracking
    def get(self):
        logging.info(self.request.body)
        curs = Cursor(urlsafe=self.request.get('cursor_param'))
        query = EmailModel.query()
        emails, next_curs, more = query.fetch_page(50, start_cursor=curs)
        emails_array = []
        next_urlsafe = ''

        for email in emails:
            emails_array.append(JSONEncoder().default(email))

        if more and next_curs:
            next_urlsafe = next_curs.urlsafe()
        context = {
            'more': more,
            'next': next_urlsafe,
            'data': emails_array,
        }
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(context))
コード例 #7
0
 def get(self, folio):
     if folio:
         folio = str(folio)
         # parametros de datatables
         sEcho = self.request.get('sEcho')
         sEcho = int(sEcho, base=10)
         iDisplayStart = self.request.get('iDisplayStart')
         iDisplayStart = int(iDisplayStart, base=10)
         iDisplayLength = self.request.get('iDisplayLength')
         iDisplayLength = int(iDisplayLength, base=10)
         # hacer la consulta
         query = EmailModel.get_emails_by_folio(folio, 
             display_start=iDisplayStart, display_length=iDisplayLength)
         context = {
             'sEcho': sEcho,
             'data': JSONEncoder().default(query['data']),
             'iTotalDisplayRecords': query['query_total'],
             'iTotalRecords': query['query_total'],
         }
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(json.dumps(context))
     else:
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(json.dumps({'message': 'error'}))
コード例 #8
0
 def post(self):
     export_type = self.request.get("export_type")
     if export_type == "export_general_email":
         options = self.request.get("options")
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_all_emails_by_dates_async(date_from, date_to, options)
     elif export_type == "export_sended_email":
         options = self.request.get("options")
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_all_sended_emails_by_dates_async(date_from, date_to, options)
     elif export_type == "export_failure_email":
         options = self.request.get("options")
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_all_failure_emails_by_dates_async(date_from, date_to, options)
     elif export_type == "export_search_by_email":
         email = self.request.get("email")
         email = str(email).lower()
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_info_by_email_async(date_from, date_to, email)
     elif export_type == "export_search_by_folio":
         folio = self.request.get("folio")
         folio = str(folio).lower()
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         # Consulta
         data = EmailModel.get_emails_by_folio_async(folio)
     elif export_type == "export_search_by_rut":
         rut = self.request.get("rut")
         rut = str(rut).upper()
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_emails_by_rut_receptor_async(date_from, date_to, rut)
     elif export_type == "export_search_by_failure":
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_all_failure_emails_by_dates_async(date_from, date_to)
     elif export_type == "export_search_by_mount":
         mount_from = self.request.get("mount_from")
         mount_to = self.request.get("mount_to")
         mount_from = int(mount_from, base=10)
         mount_to = int(mount_to, base=10)
         user_email = self.request.get("user_email")
         file_name = self.request.get("file_name")
         date_from = self.request.get("date_from")
         date_to = self.request.get("date_to")
         date_from = int(date_from, base=10)
         date_to = int(date_to, base=10)
         date_from = datetime.datetime.fromtimestamp(date_from)
         date_to = datetime.datetime.fromtimestamp(date_to)
         # Consulta
         data = EmailModel.get_emails_by_mount_async(date_from, date_to, mount_from, mount_to)
         # Creación del documento
     doc_export = create_tablib_async(data)
     # Buscar el objeto usuario
     user = UserModel.get_user(user_email)
     logging.info(user)
     # Proceso de correo
     mail = EmailClient()
     mail_report = {
         "email": user.email,
         "user_name": user.first_name,
         "subject": REPORT_SUBJECT_MAIL,
         "html": REPORT_HTML_MAIL.format(user_name=user.first_name),
         "attach": {"name": file_name, "file": doc_export.xlsx},
     }
     mail.send_mail_to_user_attach(mail_report)
コード例 #9
0
    def post(self):
        """ Metodo que recibe los eventos generados al intentar enviar correos a SendGrid
        Los eventos capturados son (procesado, enviado, abierto, descartado, rebotado) """
        # se captura y se parsea a json el body del request recibido por el
        # webhook
        request_body = json.loads(self.request.body)

        for body in request_body:
            """ Evaluar el tipo de evento ya que trae campos diferentes """
            logging.info(request_body)
            try:
                event = str(body['event']).decode("utf-8")
                correo = str(body['email']).decode("utf-8")
                numero_folio = str(body['numero_folio']).decode("utf-8")
                tipo_dte = str(body['tipo_dte']).decode("utf-8")
                logging.info(event)
                if event and correo and numero_folio and tipo_dte:

                    if event == 'processed':
                        # instanciar objeto EmailModel
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            email_model.smtp_id = str(body['smtp-id']).decode('utf-8')
                            email_model.processed_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.processed_event = event
                            email_model.processed_sg_event_id = str(body['sg_event_id']).decode("utf-8")
                            email_model.processed_sg_message_id = str(body['sg_message_id']).decode("utf-8")
                            email_model.put()

                    elif event == 'delivered':
                        # instanciar objeto EmailModel
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            email_model.smtp_id = str(body['smtp-id']).decode('utf-8')
                            email_model.delivered_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.delivered_event = event
                            email_model.delivered_sg_event_id = str(body['sg_event_id']).decode("utf-8")
                            email_model.delivered_sg_message_id = str(body['sg_message_id']).decode("utf-8")
                            email_model.delivered_response = str(body['response']).decode("utf-8")
                            email_model.put()

                    elif event == 'open':
                        # instanciar objeto EmailModel
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            if email_model.opened_first_date == None:
                                email_model.opened_first_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.opened_last_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.opened_event = event
                            email_model.opened_ip = str(body['ip']).decode("utf-8")
                            email_model.opened_user_agent = str(body['useragent']).decode("utf-8")
                            email_model.opened_sg_event_id = str(body['sg_event_id']).decode("utf-8")
                            email_model.opened_sg_message_id = str(body['sg_message_id']).decode("utf-8")
                            e.email_add_count(email_model)
                            email_model.put()

                    elif event == 'dropped':
                        # instanciar objeto EmailModel
                        e = EmailModel()
                        email_model = e.search_email(
                            correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            email_model.smtp_id = str(body['smtp-id']).decode('utf-8')
                            email_model.dropped_date = datetime.datetime.fromtimestamp(
                                body['timestamp'])
                            email_model.dropped_sg_event_id = str(body['sg_event_id']).decode("utf-8")
                            email_model.dropped_sg_message_id = str(body['sg_message_id']).decode("utf-8")
                            email_model.dropped_reason = str(body['reason']).decode("utf-8")
                            email_model.dropped_event = event
                            email_model.put()

                    elif event == 'bounce':
                        # instanciar objeto EmailModel
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            email_model.smtp_id = str(body['smtp-id']).decode('utf-8')
                            email_model.bounce_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.bounce_event = event
                            email_model.bounce_sg_event_id = str(body['sg_event_id']).decode("utf-8")
                            email_model.bounce_sg_message_id = str(body['sg_message_id']).decode("utf-8")
                            email_model.bounce_reason = str(body['reason']).decode("utf-8")
                            email_model.bounce_status = str(body['status']).decode("utf-8")
                            email_model.bounce_type = str(body['type']).decode("utf-8")
                            email_model.put()

                    elif event == 'unsubscribe':
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:
                            email_model.unsubscribe_date = datetime.datetime.fromtimestamp(body['timestamp'])
                            email_model.unsubscribe_uid = str(body['uid']).decode("utf-8")
                            email_model.unsubscribe_purchase = str(body['purchase']).decode("utf-8")
                            email_model.unsubscribe_id = str(body['id']).decode("utf-8")
                            email_model.unsubscribe_event = str(body['event']).decode("utf-8")
                            email_model.put()
                    elif event == 'click':
                        e = EmailModel()
                        email_model = e.search_email(correo, numero_folio, tipo_dte)

                        if not email_model == None:                        
                            email_model.click_ip = str(body['ip']).decode("utf-8")
                            email_model.click_purchase = str(body['purchase']).decode("utf-8")
                            email_model.click_useragent = str(body['useragent']).decode("utf-8")
                            email_model.click_event = str(body['event']).decode("utf-8")
                            email_model.click_email = str(body['email']).decode("utf-8")
                            email_model.click_date = body['timestamp']
                            email_model.click_url = str(body['url']).decode("utf-8")
                            email_model.put()
                else:
                    logging.info('body con campos vacios')
            except Exception, e:
                logging.error(e)
コード例 #10
0
    def post(self):
        # registro de header y body del request
        #logging.info(self.request.headers)
        #logging.info(self.request.body)
        # seteo de parametros recibidos
        empresa = self.request.get('empresa')
        rut_receptor = self.request.get('rut_receptor')
        rut_emisor = self.request.get('rut_emisor')
        tipo_envio = self.request.get('tipo_envio')
        tipo_dte = self.request.get('tipo_dte')
        numero_folio = self.request.get('numero_folio')
        resolucion_receptor = self.request.get('resolucion_receptor')
        resolucion_emisor = self.request.get('resolucion_emisor')
        monto = self.request.get('monto')
        fecha_emision = self.request.get('fecha_emision')
        fecha_recepcion = self.request.get('fecha_recepcion')
        estado_documento = self.request.get('estado_documento')
        tipo_operacion = self.request.get('tipo_operacion')
        tipo_receptor = self.request.get('tipo_receptor')
        nombre_cliente = self.request.get('nombre_cliente')
        correo = self.request.get('correo')
        asunto = self.request.get('asunto')
        html = self.request.get('html')
        # seteo de adjuntos si es que lo hubiera
        adjunto1 = self.request.POST.get('adjunto1', None)
        adjunto2 = self.request.POST.get('adjunto2', None)
        adjunto3 = self.request.POST.get('adjunto3', None)

        if (correo and asunto and html and numero_folio and tipo_dte):
            # Proceso de creación del objeto email
            my_email = EmailModel()
            email_result = my_email.search_email(correo, numero_folio, tipo_dte)
            if email_result == None:
                #try:
                my_email.nombre_cliente = nombre_cliente
                my_email.correo = correo
                my_email.asunto = asunto
                my_email.html = html
                my_email.tipo_dte = tipo_dte
                my_email.numero_folio = numero_folio
                if empresa:
                    my_email.empresa = empresa
                if rut_receptor:
                    my_email.rut_receptor = rut_receptor
                if rut_emisor:
                    my_email.rut_emisor = rut_emisor
                if tipo_envio:
                    my_email.tipo_envio = tipo_envio
                if resolucion_receptor:
                    my_email.resolucion_receptor = resolucion_receptor
                if resolucion_emisor:
                    my_email.resolucion_emisor = resolucion_emisor
                if monto:
                    try:
                        my_email.monto = int(monto, base=10)
                    except:
                        pass
                if fecha_emision and not None:
                    my_email.fecha_emision = datetime.datetime.fromtimestamp(float(fecha_emision))
                if fecha_recepcion and not None:
                    my_email.fecha_recepcion = datetime.datetime.fromtimestamp(float(fecha_recepcion))
                if estado_documento:
                    my_email.estado_documento = estado_documento
                if tipo_operacion:
                    my_email.tipo_operacion = tipo_operacion
                if tipo_receptor:
                    my_email.tipo_receptor = tipo_receptor
                # Evaluar adjuntos
                if not adjunto1 == None:
                    att = AttachModel(
                        nombre=adjunto1.filename, archivo=adjunto1.file.read()).put()
                    my_email.attachs.append(att)
                if not adjunto2 == None:
                    att = AttachModel(
                        nombre=adjunto2.filename, archivo=adjunto2.file.read()).put()
                    my_email.attachs.append(att)
                if not adjunto3 == None:
                    att = AttachModel(
                        nombre=adjunto3.filename, archivo=adjunto3.file.read()).put()
                    my_email.attachs.append(att)
                my_email.put()
                context = {
                    'correo': correo,
                    'numero_folio': numero_folio,
                    'tipo_dte': tipo_dte,
                }
                # Inicio taskqueue
                q = taskqueue.Queue('InputQueue')
                t = taskqueue.Task(url='/inputqueue', params=context)
                q.add(t)
                self.response.write({'message': 'success'})
                #except Exception, e:
                #    logging.error(e)
            else:
                logging.info('objeto ya existe')
            # fin todo
        else:
            self.response.write({'message': 'error fields'})