Skip to content

Commit

Permalink
After small refactoring, have not tested it yet, need to refactor the
Browse files Browse the repository at this point in the history
code to be shorter and more efficient
  • Loading branch information
ik5 committed Feb 5, 2013
1 parent a8607b6 commit 5a5e889
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions convert_quotes.py
Expand Up @@ -112,9 +112,9 @@ def iter_quotes(quotes_file = QUOTES_FILE, logger = LOGGER) :

logger.debug('Total quotes found with iterator: %d', counter)

def insert_to_db(con, quote, author, authors_ids, logger=LOGGER) :
"""Insert quotes to the database"""
cursor = con.cursor()
def handle_author_db(con, author, authors_ids, logger=LOGGER) :
"""work on the author side of the quote"""
# TODO: Refactor code
author_id = None
if author :
if not authors_ids.has_key(author) :
Expand All @@ -139,12 +139,19 @@ def insert_to_db(con, quote, author, authors_ids, logger=LOGGER) :
except fdb.DatabaseError as e : # could not get the author id
logger.info('Could not find author (%s): %s', author, e)
else:
logger.debug('Author (%s) has a known id : %d',
author, authors_ids[author])
author_id = authors_ids[author]
logger.debug('Author (%s) has a known id : %d', author, author_id)
else:
logger.debug('Author is not set')

return author_id


def insert_to_db(con, quote, author, authors_ids, logger=LOGGER) :
"""Insert quotes to the database"""
cursor = con.cursor()
author_id = handle_author_db(con, author,authors_ids, logger)

try :
logger.debug('Going to insert quote ("%s") to db', quote)
cursor.execute(('insert into quotes(body, author_ref) '
Expand Down

0 comments on commit 5a5e889

Please sign in to comment.