summaryrefslogtreecommitdiff
path: root/convert.py
diff options
context:
space:
mode:
Diffstat (limited to 'convert.py')
-rwxr-xr-x[-rw-r--r--]convert.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/convert.py b/convert.py
index 9e8bba4..1a07fb2 100644..100755
--- a/convert.py
+++ b/convert.py
@@ -1,18 +1,23 @@
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+
import MySQLdb as mysql
+import sqlite3
+import sys
def create():
try:
- con = mysql.connect('localhost', 'wordnet', 'words', 'wordnet');
+ con = sqlite3.connect('dictionaries/wordnet.db');
with con:
- cur = con.cursor(mysql.cursors.DictCursor)
- cur.execute("CREATE TABLE types (id int not null auto_increment, type text, abbreviation text, primary key(id))")
+ cur = con.cursor()
+ cur.execute("CREATE TABLE types (id integer primary key not null , type text, abbreviation text)")
cur.execute("INSERT INTO types (type, abbreviation) VALUES('noun', 'n')")
cur.execute("INSERT INTO types (type, abbreviation) VALUES('verb', 'v')")
cur.execute("INSERT INTO types (type, abbreviation) VALUES('adjective', 'adj')")
cur.execute("INSERT INTO types (type, abbreviation) VALUES('adverb', 'adv')")
- cur.execute("CREATE TABLE definitions (id bigint not null auto_increment, word text, type_id int, sub_id int, synset_id bigint, definition text, primary key(id))")
- cur.execute("CREATE TABLE uses (id bigint not null auto_increment, definition_id bigint, quote text, primary key(id))")
+ cur.execute("CREATE TABLE definitions (id integer primary key not null , word text, type_id int, sub_id int, synset_id bigint, definition text)")
+ cur.execute("CREATE TABLE uses (id integer primary key not null, definition_id bigint, quote text)")
except mysql.Error, e:
print "Database Error %d: %s" % (e.args[0],e.args[1])
@@ -35,10 +40,10 @@ def select():
def insert(rows):
try:
- con = mysql.connect('localhost', 'wordnet', 'words', 'wordnet');
+ con = sqlite3.connect('dictionaries/wordnet.db');
with con:
- cur = con.cursor(mysql.cursors.DictCursor)
+ cur = con.cursor()
for row in rows:
if row['pos'] == 'n':
@@ -50,7 +55,7 @@ def insert(rows):
elif row['pos'] == 'r':
type_id = 4
- cur.execute("INSERT INTO definitions(word, type_id, sub_id, synset_id, definition) values(%s, %s, %s, %s, %s)", [row['lemma'], type_id, row['sensenum'], row['synsetid'], row['definition']])
+ cur.execute("INSERT INTO definitions(word, type_id, sub_id, synset_id, definition) values(?, ?, ?, ?, ?)", [row['lemma'], type_id, row['sensenum'], row['synsetid'], row['definition']])
row_id = cur.lastrowid
@@ -58,10 +63,10 @@ def insert(rows):
uses = row['sampleset'].split("|")
for use in uses:
- cur.execute("INSERT INTO uses(definition_id, quote) values(%s, %s)", [row_id, use])
+ cur.execute("INSERT INTO uses(definition_id, quote) values(?, ?)", [row_id, use])
- except mysql.Error, e:
- print "Database Error %d: %s" % (e.args[0],e.args[1])
+ except sqlite3.Error, e:
+ print "Database Error %s" % (e.args[0])
sys.exit(1)
def main():