Example #1
0
    def __init__(self, **kwargs):
        super(BookGridLayout, self).__init__(**kwargs)

        self.data = SqliteDB.get_db_values('booktable')

        for item in self.data:
            if not item['imageDest']:
                book_cover = 'images/book_random_ver1.png'
            else:
                book_cover = item['imageDest']

            sort_params = {'date': item['dateCompleted'],
                           'pages': item['pageCount']}

            filter_params = {'is_fav': item['isFav'],
                             'rented': bool(item['rentedPerson'])}

            book = BookItem(book_id=item['book_id'], title=item['title'],
                            cover=book_cover, shelves=item['shelves'],
                            tags=item['tags'], author=item['author'],
                            sort_params=sort_params,
                            filter_params=filter_params)

            self.add_widget(book)
            self.height += book.height / 3 + 10
Example #2
0
    def open_edit_book(self, book_id):
        for i in range(len(self.root.ids.rootmanager.screen_names)):
            if self.root.ids.rootmanager.screen_names[i].find('new') != -1:
                index = i

        book_values = SqliteDB.get_single_book_from_db(book_id)
        self.root.ids['rootmanager'].remove_widget(
            self.root.ids.rootmanager.screens[index])

        self.root.ids['rootmanager'].add_widget(
            AddScreen(
                title=book_values['title'],
                author=book_values['author'],
                category=book_values['category'],
                rating=book_values['rating'],
                rented_person=book_values['rentedPerson'],
                date_completed=book_values['dateCompleted'],
                pages=book_values['pageCount'],
                book_id=book_id,
                description=book_values['describtion'],
                shelves=book_values['shelves'].split(';'),
                tags=book_values['tags'].split(';')
                ))

        self.root.ids['rootmanager'].current = 'new'
        self.root.ids['rootmanager'].screens[4].ids['stars_rating'].\
            set_rating(book_values['rating'])
        self.root.ids['rootmanager'].screens[4].ids['fav_btn'].\
            load_favourite(book_values['isFav'])
        self.root.ids['rootmanager'].screens[4].ids['read_btn'].\
            load_read_status(book_values['isRead'])
        self.root.ids['rootmanager'].screens[4].ids['add_image_btn'].\
            load_book_image(book_values['imageDest'])
        self.load_shelves_checkboxes()
Example #3
0
    def build(self):
        self.title = 'BookByBook'
        # self.icon = ''

        SqliteDB()

        self.root = RootWidget()
        return self.root
Example #4
0
    def count_tag_books(self, tag):
        book_count = 0
        books_data = SqliteDB.get_db_values('booktable')

        for item in books_data:
            if item['tags'] and tag in item['tags']:
                book_count += 1

        return book_count
Example #5
0
    def count_shelf_books(self, shelf):
        book_count = 0
        books_data = SqliteDB.get_db_values('booktable')

        for item in books_data:
            if item['shelves'] and shelf in item['shelves']:
                book_count += 1

        return book_count
Example #6
0
    def find_top_authors(self):
        books_data = SqliteDB.get_db_values('booktable')
        authors = defaultdict(int)

        for item in books_data:
            if item['isRead']:
                authors[item['author']] += 1

        top_authors = [(x, y) for x, y in itertools.islice(sorted(
            authors.items(), key=lambda item: item[1], reverse=True), 3)]

        if len(top_authors) < 3:
            top_authors.append(('', 0))
            top_authors.append(('', 0))
            top_authors.append(('', 0))

        return top_authors
Example #7
0
 def __init__(self, **kwargs):
     super(WishViewer, self).__init__(**kwargs)
     self.data = SqliteDB.get_db_values('wishlist')
Example #8
0
 def remove_tag(self, tag_title):
     for item in self.data:
         if item['tag'] == tag_title:
             self.data.remove(item)
     SqliteDB.del_value_from('tags', tag_title, 'tag')
Example #9
0
 def add_tag(self, tag_title):
     if tag_title:
         SqliteDB.insert_to('tags', tag_title)
         self.data.append({'tag': tag_title})
Example #10
0
 def __init__(self, **kwargs):
     super(TagViewer, self).__init__(**kwargs)
     self.data = SqliteDB.get_db_values('tags')
     for tag_dict in self.data:
         tag_dict['book_count'] = self.count_tag_books(tag_dict['tag'])
Example #11
0
    def export_book_data(self):
        books_data = SqliteDB.get_db_values('booktable')

        with open('book_list.txt', 'w', encoding="utf-8") as txt_file:
            for book in books_data:
                txt_file.write(book['title'] + ' - ' + book['author'] + '\n')
Example #12
0
 def remove_wish(self, title, author):
     SqliteDB.del_value_from('wishlist', title, 'title')
     self.data.remove({'title': title, 'author': author})
Example #13
0
 def remove_shelf(self, shelf_title):
     for item in self.data:
         if item['shelf'] == shelf_title:
             self.data.remove(item)
     SqliteDB.del_value_from('shelves', shelf_title, 'shelf')
Example #14
0
 def add_wish(self, title, author):
     if title and author:
         SqliteDB.insert_to_wishlist(title, author)
         self.data.append({'title': title, 'author': author})
Example #15
0
 def add_shelf(self, shelf_title):
     if shelf_title:
         SqliteDB.insert_to('shelves', shelf_title)
         self.data.append({'shelf': shelf_title})
Example #16
0
 def __init__(self, **kwargs):
     super(ShelfViewer, self).__init__(**kwargs)
     self.data = SqliteDB.get_db_values('shelves')
     for shelf_dict in self.data:
         shelf_dict['book_count'] = \
             self.count_shelf_books(shelf_dict['shelf'])
Example #17
0
 def save_book(self, values):
     if self.book_id > 0:
         SqliteDB.edit_book_in_db(self.book_id, *values)
     else:
         SqliteDB.add_book_to_db(*values)
Example #18
0
    def plot_data(self):
        books_data = SqliteDB.get_db_values('booktable')

        " ----- Read books pie ----- "
        all_books = len(books_data)
        if not all_books:
            all_books = 1
        read_books = 0
        for item in books_data:
            if item['isRead']:
                read_books += 1

        counts = [all_books-read_books, read_books]
        explode = 2 * (0.025,)

        fig1, ax1 = plt.subplots()
        ax1.pie(counts, startangle=90, pctdistance=0.78, explode=explode)

        centre_circle = plt.Circle((0, 0), 0.65, fc='white')
        fig = plt.gcf()
        fig.gca().add_artist(centre_circle)

        textstr = \
            f"Books read: {read_books}\n\n{read_books/all_books*100:0.0f}\
                   % of your library "

        plt.figtext(0.51, 0.45, textstr, fontsize=14)
        plt.subplots_adjust(right=0.5)

        plt.savefig("pie.png", bbox_inches='tight', pad_inches=0)

        " ----- Categories pie ----- "
        category_counts = defaultdict(int)
        for item in books_data:
            category_counts[item['category']] += 1

        categories = \
            [ct if ct else 'no category' for ct in category_counts.keys()]

        def func(pct, allvals):
            absolute = int(pct/100.*sum(allvals))
            if pct < 3:
                return ""
            else:
                return "{:.0f}%\n({:d})".format(pct, absolute)

        fig1, ax1 = plt.subplots()
        explode = len(categories) * (0.05,)
        category_counts = list(category_counts.values())

        patches, texts, autotexts = \
            ax1.pie(
                category_counts,
                autopct=lambda pct: func(pct, category_counts),
                startangle=90, pctdistance=0.8, explode=explode)

        ax1.legend(patches,
                   categories,
                   title="Categories            ",
                   loc="center left",
                   bbox_to_anchor=(0.95, 0, 0.5, 1),
                   frameon=False,
                   fontsize=12,
                   title_fontsize=14)

        centre_circle = plt.Circle((0, 0), 0.65, fc='white')
        fig = plt.gcf()
        fig.gca().add_artist(centre_circle)
        plt.subplots_adjust(right=0.5)

        plt.savefig("pie2.png", bbox_inches='tight', pad_inches=0)