Ejemplo n.º 1
0
    def test_ignore_garaz_in_zal(self):

        parsed = parse(html=self.testdata1, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_ignore_zal_garaz)

        self.assertNotIn("garaz", parsed, "Zone 'garaz' in the results, where it shouldn't be.")
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-

# to run:
# python parse-file.py filename [last-time]

import sys
import datetime

from settings import default as settings

from juwparser import parse

try:
    last_time = datetime.datetime.strptime(sys.argv[2], '%Y-%m-%d %H:%M:%S')
except ValueError:
    print 'Invalid time provided: ' + sys.argv[2] + '. Use "%Y-%m-%d %H:%M:%S" format.'
    sys.exit()
except IndexError:
    last_time = datetime.datetime.strptime('2014-04-21 00:00:00', '%Y-%m-%d %H:%M:%S')

try:
    with open(sys.argv[1], 'r') as l:
        log = l.read()
    print parse(html=log, last_time=last_time, settings=settings)
except IOError:
    print 'No such file: ' + sys.argv[1]
except IndexError:
    print 'No filename given.'

Ejemplo n.º 3
0
    def test_user_names(self):

        parsed = parse(html=self.testdata1, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_default)

        self.assertIn("ZALACZONO (Alice, John)", parsed, "No user 3 and 6 ZALACZONO action present or wrong contents of the input file.")
        self.assertIn("WYLACZONO (Alice)", parsed, "No user 3 ZALACZONO action present or wrong contents of the input file.")
Ejemplo n.º 4
0
    def test_garaz_in_zal(self):

        parsed = parse(html=self.testdata1, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_default)

        self.assertIn("garaz", parsed, "Zone 'garaz' should be in the results.")
Ejemplo n.º 5
0
    def test_napad(self):

        parsed = parse(html=self.testdata2, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_default)

        self.assertIn("NAPAD!", parsed, "No NAPAD action reported or wrong contents of the input file.")
Ejemplo n.º 6
0
    def test_wlamanie(self):

        parsed = parse(html=self.testdata2, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_default)

        self.assertIn("WLAMANIE: parter czujki", parsed, "No WLAMANIE action reported or wrong contents of the input file.")
Ejemplo n.º 7
0
    def test_parse_ignore_zal(self):

        parsed = parse(html=self.testdata1, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_ignore_zal)

        self.assertEqual(parsed, "WYLACZONO (Alice): garaz, parter czujki, parter okna, pietro okna, parter czujki, garaz, pietro czujki, parter okna, pietro okna, parter czujki, garaz, pietro czujki, parter okna, pietro okna, garaz, parter czujki, parter okna, pietro okna", "'zal' action not ignored or wrong contents of the input file.")
Ejemplo n.º 8
0
    def test_parse_ignore_user3(self):

        parsed = parse(html=self.testdata1, last_time=datetime.datetime.strptime(self.last_time, '%Y-%m-%d %H:%M:%S'), last_time_filename=self.lt_filename, settings=settings_ignore_user3)

        self.assertEqual(parsed, "ZALACZONO (John): garaz, parter czujki, parter okna, pietro okna, parter czujki, garaz, parter okna, pietro okna", "User's 3 actions not ignored or wrong contents of the input file.")
Ejemplo n.º 9
0
    from stop import dont_parse
except ImportError:
    dont_parse = False
from juwparser import parse, get_log, get_last_time

from importlib import import_module
import argparse


argparser = argparse.ArgumentParser(description="juwparser - parsing Juwentus logs")
argparser.add_argument('action', action='store', help="action (parse, getlog)", choices=('parse', 'getlog'))

action = argparser.parse_args().action

if action == 'parse':
    if dont_parse:
        print 'Parsing disabled with stop.dont_parse.'
    else:
        message_text = parse(html=get_log(settings=settings), last_time=get_last_time(), settings=settings)

        if message_text != '':
            sendermod = {}
            for sender in settings['SENDERS']:
                try:
                    sendermod[sender] = import_module('senders.%s' % sender)
                    sendermod[sender].send(message=message_text, settings=settings)
                except ImportError:
                    print 'No such sender: %s' % sender
elif action == 'getlog':
    print get_log(settings=settings)