Initial import of some conversion scripts for our db changes

This commit is contained in:
James Vega 2004-12-05 20:02:25 +00:00
parent d9e766b278
commit eca707912a
3 changed files with 134 additions and 0 deletions

58
tools/fundbConvert.py Executable file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python
import os
import sys
import sqlite
import supybot.dbi as dbi
import supybot.plugins.Lart as Lart
import supybot.plugins.Praise as Praise
def usage():
print 'usage: %s <sqlitedb> <channel> [<botname>]' % sys.argv[0]
print '<botname> is an optional parameter used if any db entries are '\
'missing a "created by" user.'
def main():
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) not in (3, 4):
usage()
sys.exit(1)
sqldb = sys.argv[1]
channel = sys.argv[2]
if len(sys.argv) >= 4:
botname = sys.argv[3]
if not os.path.exists(sqldb):
print 'Unable to open %s' % sqldb
sys.exit(1)
praises = Praise.Praise().db
larts = Lart.Lart().db
db = sqlite.connect(sqldb)
cursor = db.cursor()
total = 0
failed = 0
success = 0
for (table, plugin) in (('larts', larts), ('praises', praises))
cursor.execute("""SELECT * FROM %s ORDER BY id ASC""" % table)
table = table[:-1]
if cursor.rowcount != 0:
entries = cursor.fetchall()
for entry in entries:
try:
total += 1
text = entry[1]
by = entry[2]
if by is None:
by = botname
plugin.add(channel, table, text, by)
success += 1
except dbi.Error:
failed += 1
print '%s/%s entries successfully added. %s failed.' % (success, total,
failed)
print 'Dbs are at: %s' % ', '.join((praises.filename, larts.filename))
db.close()
praises.close()
larts.close()
sys.exit(0)
if __name__ == '__main__':
main()

50
tools/noteConvert.py Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
import os
import sys
import sqlite
import supybot.dbi as dbi
import supybot.plugins.Note as Note
def main():
if '-h' in sys.argv or '--help' in sys.argv or len(sys.argv) != 2:
print 'usage: %s <sqlitedb>' % sys.argv[0]
sys.exit(1)
sqldb = sys.argv[1]
if not os.path.exists(sqldb):
print 'Could not find %s' % sqldb
sys.exit(1)
TxtDb = Note.NoteDB()
db = sqlite.connect(sqldb)
cursor = db.cursor()
total = 0
failed = 0
success = 0
cursor.execute("""SELECT notified, read, from_id, to_id, public, note FROM notes ORDER BY id ASC""")
if cursor.rowcount != 0:
entries = cursor.fetchall()
for entry in entries:
try:
entry = tuple(entry)
total += 1
notified = bool(entry[0])
read = bool(entry[1])
frm = int(entry[2])
to = int(entry[3])
public = bool(entry[4])
text = entry[5]
id = TxtDb.send(frm, to, public, text)
if notified:
TxtDb.setNotified(id)
if read:
TxtDb.setRead(id)
success += 1
except dbi.Error:
failed += 1
print '%s/%s entries successfully added. %s failed.' % (success, total, failed)
db.close()
TxtDb.close()
sys.exit(0)
if __name__ == '__main__':
main()

26
tools/urlConvert.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
import sys
import time
import supybot.ircmsgs as ircmsgs
import supybot.plugins.URL as URL
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'usage: %s URL.db' % sys.argv[0]
sys.exit()
try:
olddb = file(sys.argv[1])
except IOError, e:
print str(e)
sys.exit()
db = URL.URLDB()
for line in olddb:
(url, person) = line.split()
m = ircmsgs.IrcMsg(command='PRIVMSG', args=('#foo', '%s' % url), prefix=person)
m.tag('receivedAt', time.time())
db.add(None, url, m)
db.close()
olddb.close()