1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/usr/bin/env python
from django.core.management import setup_environ
import settings
import pickle
setup_environ(settings)
import sqlite
from bt.models import Event,Ban,Kick,Mark,Log,Operator,UserProfile,Comment
import re
from django.core.exceptions import *
DB = sqlite.connect('/home/bnrubin/devel/ircTrack/bans.db')
class LegacyComment:
def __init__(self,id,operator,text,time):
self.id = id
self.operator = operator
self.time = time
self.text = text
self.enabled = True
class LegacyEvent:
def __init__(self,id,channel,operator,time,log,removal_time=None,removal_op=None,mask=None):
self.mask_pattern = re.compile('.*!.*@.*')
self.mark_pattern = re.compile('\*\*MARK\*\*.*')
self.id = id
self.channel = channel
self.mask = mask
self.banmask = mask
self.operator = operator
self.time = pickle.loads(time)
try:
self.removal_time = pickle.loads(removal_time)
except TypeError:
self.removal_time = removal_time
self.removal_op = removal_op
self.reason = None
self.log = log
self.comments = self.getComments(id)
self.is_mark = False
self.is_kick = False
if not self.mask_pattern.match(self.mask):
# This is a kick
self.is_kick = True
self.nick = self.mask
for comment in self.comments:
if comment.time == self.time:
# Assuming that comments added by the bot happen
# at the same time as when the event itself was added
if self.mark_pattern.match(comment.text):
self.is_mark = True
self.reason = comment.text
comment.enabled = False
elif self.mask_pattern.match(comment.text):
self.mask = comment.text
comment.enabled = False
elif self.is_kick:
self.reason = comment.text
comment.enabled = False
if self.mask == self.banmask and self.is_mark is not True and self.is_kick is not True:
self.mask = 'unk'
print 'id: %s' % self.id
print 'Mask: %s' % self.mask
print 'Channel: %s' % self.channel
print 'Op: %s' % self.operator
print 'Kick: %s' % (self.is_kick)
print 'Mark: %s' % self.is_mark
print 'Reason: %s: ' % self.reason
print 'Ban: %s' % (self.banmask)
print 'hostmask: %s' % self.mask
print 'removal time: %s' % self.removal_time
print 'Comments:'
for comment in self.comments:
if comment.enabled:
print '%s: %s' % (comment.time,comment.text)
print '-------'
print '-----------------------------------------------------'
def add(self):
op,status = Operator.objects.get_or_create(host=self.operator)
op.save()
log = Log.objects.create(channel=self.channel,text=self.log)
log.save()
if self.is_mark:
event = Mark.objects.create(create_date = self.time, channel = self.channel,
log = log, operator = op,
hostmask = self.mask, reason = self.reason)
elif self.is_kick:
event = Kick.objects.create(create_date = self.time, channel = self.channel,
log = log, operator = op,
hostmask = self.mask, reason = self.reason)
else:
rem_op = None
if self.removal_op:
rem_op,status = Operator.objects.get_or_create(host=self.removal_op)
rem_op.save()
event = Ban.objects.create(create_date = self.time, channel = self.channel,
log = log, operator = op,
hostmask = self.mask, mask = self.banmask,
removal_date = self.removal_time, removed_by = rem_op)
event.save()
print event.id
for comment in self.comments:
if comment.enabled:
op,status = Operator.objects.get_or_create(host=comment.operator)
op.save()
c = Comment(content_object=event.event_ptr,text=comment.text,author=op,create_date=comment.time)
c.save()
print c.text
print c.create_date
def getComments(self,ban_id):
cursor = DB.cursor()
cursor.execute('SELECT * FROM comments WHERE ban_id = %s ORDER BY time' % ban_id)
comments = cursor.fetchall()
c = []
for comment in comments:
id = comment[0]
operator = comment[1]
text = comment[2]
time = pickle.loads(comment[3])
print time
c.append(LegacyComment(id,operator,text,time))
return c
cur = DB.cursor()
cur.execute('SELECT * FROM bans ORDER BY id desc LIMIT 100')
#cur.execute('SELECT * from bans where id = 16010')
result = cur.fetchall()
count = 0
for b in result:
id = b[0]
channel = b[1]
mask = b[2]
operator = b[3]
time = b[4]
removal = b[5]
removal_op = b[6]
log = unicode(b[7],errors='replace')
e = LegacyEvent(id,channel,operator,time,log,
removal_time=removal,removal_op=removal_op,
mask=mask)
e.add()
|