def main(): import optparse parser = optparse.OptionParser(__doc__.strip()) haddoc.add_options(parser) opts, args = parser.parse_args() haddoc.validate_options(opts) if len(args) != 2: parser.error("This program requires the source type name and the name " "of the index file to process.") source, fn = args conn = haddoc.getconnection() results = process_index(fn) for terms, url in results: fullterm = ' / '.join(terms) words = [] for term in terms: nterm = cleanup(term) words.extend(x.strip() for x in nterm.split()) term = ' '.join(words) with committing(conn) as curs: curs.execute(""" INSERT INTO terms (term, source, fullname, url) VALUES (%s, %s, %s, %s); """, (term, source, fullterm, url)) print repr(fullterm) conn.close()
def main(): import optparse parser = optparse.OptionParser(__doc__.strip()) haddoc.add_options(parser) opts, args = parser.parse_args() haddoc.validate_options(opts) if not args: parser.error("You need to specify some search terms.") conn = haddoc.getconnection() curs = conn.cursor() rsets = [] curs.execute(""" SELECT term, source, fullname, url FROM terms WHERE term ~* %s """, ('.*'.join(args),)) res = defaultdict(list) for term, source, fullname, url in curs: res[url].append((source, fullname)) for url, rlist in res.iteritems(): print url for source, fullname in rlist: print " %s: %s" % (source, fullname) print conn.close()
def main(): import optparse parser = optparse.OptionParser(__doc__.strip()) haddoc.add_options(parser) opts, args = parser.parse_args() haddoc.validate_options(opts) conn = haddoc.getconnection() curs = conn.cursor() print 'Dropping' with committing(conn, ignore_errors=1) as curs: curs.execute("DROP TABLE terms") print 'Creating' with committing(conn) as curs: curs.execute(schema)