Skip to content
Browse files

After small refactoring, have not tested it yet, need to refactor the

code to be shorter and more efficient
  • Loading branch information...
1 parent a8607b6 commit 5a5e8894a99c20bf1cbf353a1ce81b0597b4c9b1 @ik5 committed Feb 5, 2013
Showing with 12 additions and 5 deletions.
  1. +12 −5 convert_quotes.py
View
17 convert_quotes.py
@@ -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) :
@@ -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) '

0 comments on commit 5a5e889

Please sign in to comment.
Something went wrong with that request. Please try again.