Code: Alles auswählen
# -*- coding: utf-8 -*-
# SnakelogAnalyzer.py
import re
import os
import os.path
from pysqlite2 import dbapi2 as sqlite
SNAKELOG = file('E:\\server.log', 'r')
class SnakelogAnalyzer(object):
'''
Class for cleaving a Snakelog.
'''
def __init__(self, line):
self.line = line
def cleaveLine(self):
'''
Method to cleave one line of the Snakelog and group them.
'''
parser = re.compile('\[[0-3][0-9]\/[[0-3][0-9]\/0[0-9] [0-3][0-9]\:[0-5][0-9]\:[0-5][0-9]\,_*')
result = parser.match(self.line)
for i in range(result.lastindex):
print result.group(i+1)
def writeIntoDB(self):
'''
Method to write the grouped line into the DB.
'''
pass
def createDB():
'''
Function to create the DB.
'''
pass
if __name__ == '__main__':
createDB()
while True:
# read on line
line = SNAKELOG.readline()
if not line: break
print line
analyzer = SnakelogAnalyzer(line)
g = analyzer.cleaveLine()