forked from drbraden/pgdash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgdoc2set.py
More file actions
executable file
·29 lines (22 loc) · 969 Bytes
/
pgdoc2set.py
File metadata and controls
executable file
·29 lines (22 loc) · 969 Bytes
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
#!/usr/local/bin/python
import os, re, sqlite3
from bs4 import BeautifulSoup, NavigableString, Tag
conn = sqlite3.connect('postgresql.docset/Contents/Resources/docSet.dsidx')
cur = conn.cursor()
try: cur.execute('DROP TABLE searchIndex;')
except: pass
cur.execute('CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);')
cur.execute('CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);')
docpath = 'postgresql.docset/Contents/Resources/Documents'
page = open(os.path.join(docpath,'bookindex.html')).read()
soup = BeautifulSoup(page)
any = re.compile('.*')
for tag in soup.find_all('a', {'href':any}):
name = tag.text.strip()
if len(name) > 1:
path = tag.attrs['href'].strip()
if path != 'index.html':
cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, 'func', path))
print 'name: %s, path: %s' % (name, path)
conn.commit()
conn.close()