-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__SpeedyPlusInit.py
64 lines (44 loc) · 1.17 KB
/
__SpeedyPlusInit.py
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
#
# Setup the Sqlite DB For Speedy
#
import sqlite3 as lite
import sys
con = None
site_insert = "INSERT INTO Sites(Name, Url, Active) VALUES('{0}','{1}', 1);"
site_file = "data/sites.txt"
try:
con = lite.connect("data/speedyplus.db")
cur = con.cursor()
with open('sql/speedyplus.sql', 'r') as f:
cur.executescript(f.read())
con.commit()
with open('sql/speedyviews.sql', 'r') as f:
cur.executescript(f.read())
con.commit()
with open('sql/LinkCounter.sql', 'r') as f:
cur.executescript(f.read())
con.commit()
with open(site_file, 'r') as f:
all_lines = f.read().splitlines()
total = len(all_lines)
current = 0
print 'loading websites',
for council in all_lines:
current = current + 1
if council[0] <> '#': # not a comment
council_info = council.split(',')
if len(council_info) == 2:
council_name = council_info[0]
council_site = council_info[1]
print '.' ,
cur.execute( site_insert.format(council_name, council_site))
con.commit()
lid = cur.lastrowid
print ''
print "inserted %d Sites" % lid
except lite.Error, e:
print "Error %s:" % e.args[0]
sys.exit(1)
finally:
if con:
con.close()