summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xconvert.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/convert.py b/convert.py
index ab5b35d..b0354fa 100755
--- a/convert.py
+++ b/convert.py
@@ -4,6 +4,7 @@
import MySQLdb as mysql
import sqlite3
import sys
+import os.path
from definition import Definition
def create():
@@ -72,6 +73,9 @@ def insert_wn(rows):
sys.exit(1)
def get_db_version():
+ if not os.path.exists('dictionaries/wordnet.db'):
+ return 0
+
try:
con = sqlite3.connect('dictionaries/wordnet.db');
@@ -81,7 +85,7 @@ def get_db_version():
# Check if info table exists at all, if not then version 0
cur.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='info'")
row = cur.fetchone()
- if row[0] == 0:
+ if row[0] == None:
return 0
else:
cur.execute("SELECT value FROM info WHERE key = 'version'")
@@ -113,6 +117,10 @@ def update_db(version):
cur.execute("CREATE TABLE definition_categories (id integer primary key not null, definition_id int, category_id int)")
cur.execute("UPDATE info set value = 2 where key = 'version'")
+ if version < 3:
+ cur.execute("UPDATE definitions SET dictionary_id = 1 WHERE dictionary_id is null")
+ cur.execute("UPDATE info set value = 3 where key = 'version'")
+
except sqlite3.Error, e:
print "Database Error %s" % (e.args[0])
sys.exit(1)
@@ -276,10 +284,11 @@ def main():
version = get_db_version()
- # if version == 0:
- # create()
- # items = select_wn()
- # insert(items)
+ if version == 0:
+ create()
+ items = select_wn()
+ insert_wn(items)
+ version = 1
update_db(version)
parse_foldoc()