Commit 17c659de authored by biondo's avatar biondo

Addedd an utility to visualize the db content.

parent 06ffb9bc
# -*- coding: utf-8 -*-
import sqlite3
import settings
import os
class dbAnalysis:
def __init__( self, db_path ):
self.db_con = sqlite3.connect( db_path )
self.db_cur = self.db_con.cursor()
def get_books( self ):
self.db_cur.execute( "SELECT * FROM library" )
books = self.db_cur.fetchall()
return books
def get_info( self, book ):
datas = self.db_cur.execute( 'SELECT * FROM _{}_isbn'.format( book ) )
out = {}
for data in datas:
if data[0] != '' and data[1] != '' and data[2] != '':
out = { 'auth': data[2], 'title': data[3], 'ISBN': data[0] }
break
if out == {}:
return None
else:
return out
def pretty_print( self ):
books = self.get_books()
for book in books:
info = self.get_info( book[0] )
if info is not None:
print 'Title {}\tAuthor: {}\tTitle: {}'.format( book[1].encode('UTF-8'), info['auth'], info['title'] )
else:
print 'Title {}\tNo data found.'.format( book[1].encode('UTF-8') )
db = dbAnalysis('/mnt/liberalibri/.bao_sqlite.db')
db.pretty_print()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment