Created
April 15, 2015 02:18
-
-
Save mba811/35a7e280a5458c664d8c to your computer and use it in GitHub Desktop.
PostgreSQL docset for Dash (http://kapeli.com/dash/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python | |
| import os, re, sqlite3 | |
| from bs4 import BeautifulSoup, NavigableString, Tag | |
| db = sqlite3.connect('postgresql.docset/Contents/Resources/docSet.dsidx') | |
| cur = db.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) > 0: | |
| path = tag.attrs['href'].strip() | |
| if path.split('#')[0] not in ('index.html', 'biblio.html', 'bookindex.html'): | |
| cur.execute('INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?,?,?)', (name, 'func', path)) | |
| print 'name: %s, path: %s' % (name, path) | |
| db.commit() | |
| db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment