~email-tehk/irclogsearcher/trunk

« back to all changes in this revision

Viewing changes to parsers/logformats.py

  • Committer: tehk
  • Date: 2009-11-14 18:48:35 UTC
  • Revision ID: tehk@tehk-desktop-20091114184835-2vmzrhx2t3ucat4m
* fixed naming conventions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
 
3
 
 
4
class Message(object):
 
5
    """
 
6
    A Message object that holds a few important strings
 
7
    """
 
8
    Channel = str() # the channel in which the message was found
 
9
    Time = str() # the time where which the message was sent
 
10
    User = str() # the user who sent the message
 
11
    Message = str() # the message part of the raw line
 
12
    Raw_Message = str() # the raw line unparsed and unchanged
 
13
 
 
14
    def __init__(self, string, filename, *args, **kwargs):
 
15
        self.create_from_string(string, filename)
 
16
 
 
17
    def create_from_string(self, string, filename):
 
18
        self.Raw_Message = string
 
19
        self.Channel = os.path.basename(filename).replace(".log", "")
 
20
        self.Time = string[:15]
 
21
        self.User = string[string.find("<")+1:string.find(">")]
 
22
        self.Message = string[string.find(">")+2:]
 
23
 
 
24
 
 
25
class XChatMessage(Message):
 
26
    """
 
27
    A Message object that holds a few important strings that decodes xchat logs
 
28
    """
 
29
    Channel = str() # the channel in which the message was found
 
30
    Time = str() # the time where which the message was sent
 
31
    User = str() # the user who sent the message
 
32
    Message = str() # the message part of the raw line
 
33
    Raw_Message = str() # the raw line unparsed and unchanged
 
34
    xchat = {"TimeCharacters" : 15, "UserSeperators" : ["<",">"]}
 
35
 
 
36
    def __init__(self, string, filename, *args, **kwargs):
 
37
        self.create_from_string(string, filename)
 
38
 
 
39
    def create_from_string(self, string, filename):
 
40
        self.Raw_Message = string
 
41
        self.Channel = os.path.basename(filename).replace(".log", "")
 
42
        self.Time = string[:self.xchat["TimeCharacters"]]
 
43
        self.User = string[string.find(self.xchat["UserSeperators"][0])+1:string.find(self.xchat["UserSeperators"][1])]
 
44
        self.Message = string[string.find(self.xchat["UserSeperators"][1])+2:]
 
 
b'\\ No newline at end of file'