Example #1
0
def add_books_to_db(fin=books_json):
    from PyQt4 import QtCore
    from models import Book, Cat
    with open(fin, 'r') as books_file:
        data = books_file.read()
        data = json.loads(data)
    cats = data.keys()
    for c in cats:
        cat = Cat(name=c)
        cat.put()
        cat = Cat.get(name=c)[0]
        cat_id = cat.id
        for book in data[c]:
            title = book[0]
            cat_order = book[1]
            if cat_order.isdigit():
                b = Book.add(title=title, cat_id=cat_id,
                             cat_order=int(cat_order), copies=1,
                             available=True)
                if type(b) in [str, QtCore.QString]:
                    print b, title, cat_order
Example #2
0
def add_books_to_db(fin=books_json):
    from PyQt4 import QtCore
    from models import Book, Cat
    with open(fin, 'r') as books_file:
        data = books_file.read()
        data = json.loads(data)
    cats = data.keys()
    for c in cats:
        cat = Cat(name=c)
        cat.put()
        cat = Cat.get(name=c)[0]
        cat_id = cat.id
        for book in data[c]:
            title = book[0]
            cat_order = book[1]
            if cat_order.isdigit():
                b = Book.add(title=title,
                             cat_id=cat_id,
                             cat_order=int(cat_order),
                             copies=1,
                             available=True)
                if type(b) in [str, QtCore.QString]:
                    print b, title, cat_order