def handle(self, **options):
     
     dry_run = options['dry_run']
     log_file = options['file']
     poll_pk = options['poll']
     
     if not poll_pk:
         poll_pk = raw_input('Poll ID:')
         
     if not log_file:
         log_file = raw_input('Access log to be processed:')
     if not log_file:
         log_file = "/Users/asseym/Public/rapidsms/ureport/ureport_project/rapidsms_ureport/ureport/ureport_prod.access.log.1"
     
     try:
         poll = Poll.objects.get(pk=poll_pk)
     except Poll.DoesNotExist:
         pass
     file_handle=open(log_file)
     lines=file_handle.readlines()
     for line in lines:
         parts = line.strip().rsplit(' ')
         http_status = parts[6]
         query_string = parts[4]
         query_parts = query_string.split('=')
         try:
             count = 0
             backend_name = query_parts[2][:-7]
             connection = query_parts[3]
             message = urllib2.unquote(query_parts[4]).replace('+', ' ')
             if connection.endswith('&message'):
                 if not http_status in ['200', '400']:
                     if backend_name in ['dmark', 'zain']:
                         identity = connection[3:15] if connection.startswith('%') else connection[:12]
                         if not identity == 'Warid&messag':
                             try:
                                 conn=Connection.objects.get(identity=identity, backend__name=backend_name)
                                 msg=Message.objects.filter(connection=conn, text=message, direction="I")
                                 if msg.exists():
                                     print msg, ' --- exists!'
                                 else:
                                     if not dry_run:
                                         msg=Message.objects.create(connection=conn, text=message, direction="I")
                                         print "created: "+msg.text
                                         try:
                                             if poll.contacts.filter(pk=conn.contact.pk):
                                                 poll.process_response(msg)
                                         except AttributeError:
                                             pass
                                     else:
                                         print message, ' --- to be created'
                             except Connection.DoesNotExist:
                                 print identity, ' --- connection does not exists'
         except IndexError:
             pass
Exemplo n.º 2
0
    def handle(self, **options):

        dry_run = options['dry_run']
        log_file = options['file']

        if not log_file:
            log_file = raw_input('Access log to be processed:')
        if not log_file:
            log_file = "/Users/asseym/Public/rapidsms/ureport/ureport_project/rapidsms_ureport/ureport/ureport_prod.access.log.1"

        file_handle = open(log_file)
        lines = file_handle.readlines()
        for line in lines:
            parts = line.strip().rsplit(' ')
            query_string = parts[4]
            query_parts = query_string.split('=')
            try:
                backend_name = query_parts[2][:-7]
                connection = query_parts[3]
                message = urllib2.unquote(query_parts[4]).replace('+', ' ')
                if connection.endswith('&message'):
                    #                    if not http_status in ['200', '400']:
                    if backend_name in ['dmark', 'zain']:
                        identity = connection[3:15] if connection.startswith(
                            '%') else connection[:12]
                        if not identity == 'Warid&messag':
                            try:
                                conn = Connection.objects.get(
                                    identity=identity,
                                    backend__name=backend_name)
                                msg = Message.objects.filter(connection=conn,
                                                             text='txt',
                                                             direction="I")
                                if msg.exists():
                                    if dry_run:
                                        print msg, message
                                    else:
                                        m = msg[0]
                                        m.text = message
                                        m.save()
                                        print m.text
                            except Connection.DoesNotExist:
                                print identity, ' --- connection does not exists'
            except IndexError:
                pass
Exemplo n.º 3
0
    def handle(self, **options):
        
        dry_run = options['dry_run']
        log_file = options['file']
        
        if not log_file:
            log_file = raw_input('Access log to be processed:')
        if not log_file:
            log_file = "/Users/asseym/Public/rapidsms/ureport/ureport_project/rapidsms_ureport/ureport/ureport_prod.access.log.1"
        
        file_handle=open(log_file)
        lines=file_handle.readlines()
        for line in lines:
            parts = line.strip().rsplit(' ')
            query_string = parts[4]
            query_parts = query_string.split('=')
            try:
                backend_name = query_parts[2][:-7]
                connection = query_parts[3]
                message = urllib2.unquote(query_parts[4]).replace('+', ' ')
                if connection.endswith('&message'):
#                    if not http_status in ['200', '400']:
                    if backend_name in ['dmark', 'zain']:
                        identity = connection[3:15] if connection.startswith('%') else connection[:12]
                        if not identity == 'Warid&messag':
                            try:
                                conn = Connection.objects.get(identity=identity, backend__name=backend_name)
                                msg = Message.objects.filter(connection=conn, text='txt', direction="I")
                                if msg.exists():
                                    if dry_run:
                                        print msg, message
                                    else:
                                        m = msg[0]
                                        m.text = message
                                        m.save()
                                        print m.text
                            except Connection.DoesNotExist:
                                print identity, ' --- connection does not exists'
            except IndexError:
                pass
Exemplo n.º 4
0
    def handle(self, **options):

        dry_run = options['dry_run']
        log_file = options['file']
        poll_pk = options['poll']

        if not poll_pk:
            poll_pk = raw_input('Poll ID:')

        if not log_file:
            log_file = raw_input('Access log to be processed:')
        if not log_file:
            log_file = "/Users/asseym/Public/rapidsms/ureport/ureport_project/rapidsms_ureport/ureport/ureport_prod.access.log.1"

        try:
            poll = Poll.objects.get(pk=poll_pk)
        except Poll.DoesNotExist:
            pass
        file_handle = open(log_file)
        lines = file_handle.readlines()
        for line in lines:
            parts = line.strip().rsplit(' ')
            http_status = parts[6]
            query_string = parts[4]
            query_parts = query_string.split('=')
            try:
                count = 0
                backend_name = query_parts[2][:-7]
                connection = query_parts[3]
                message = urllib2.unquote(query_parts[4]).replace('+', ' ')
                if connection.endswith('&message'):
                    if not http_status in ['200', '400']:
                        if backend_name in ['dmark', 'zain']:
                            identity = connection[
                                3:15] if connection.startswith(
                                    '%') else connection[:12]
                            if not identity == 'Warid&messag':
                                try:
                                    conn = Connection.objects.get(
                                        identity=identity,
                                        backend__name=backend_name)
                                    msg = Message.objects.filter(
                                        connection=conn,
                                        text=message,
                                        direction="I")
                                    if msg.exists():
                                        print msg, ' --- exists!'
                                    else:
                                        if not dry_run:
                                            msg = Message.objects.create(
                                                connection=conn,
                                                text=message,
                                                direction="I")
                                            print "created: " + msg.text
                                            try:
                                                if poll.contacts.filter(
                                                        pk=conn.contact.pk):
                                                    poll.process_response(msg)
                                            except AttributeError:
                                                pass
                                        else:
                                            print message, ' --- to be created'
                                except Connection.DoesNotExist:
                                    print identity, ' --- connection does not exists'
            except IndexError:
                pass