Example #1
0
    def test_author(self):
        urls = (
            ("http://samlib.ru/p/pupkin_wasja_ibragimowich/indexdate.shtml",
             "Ясинский Анджей"),
            ("http://samlib.ru/e/elxterrus_i/", "Эльтеррус Иар"),
            ("http://samlib.ru/x/xgulliver/", "Gulliver"),
            ("http://samlib.ru/m/muhin_d_w/", "Zang"),
            ("http://zhurnal.lib.ru/z/zajcew_aleskandr/", "Зайцев Алескандр"),
        )
        for url, name in urls:
            author = core.create_author(url=url)
            self.assertEqual(author.name, name)

            books = models.Book.get_by_author(author, only_new=True)
            self.assertGreater(len(books), 0)

            core.book_read(books[0])
            new_books = models.Book.get_by_author(author, only_new=True)
            self.assertGreater(len(books), len(new_books))

        core.delete_author(urls[0][0])
        author = models.Author.get_by_url(urls[0][0])
        self.assertIsNone(author)

        self.assertRaises(
            urllib.request.URLError, core.create_author,
            "http://http://samlib.ru/p/pupkin_wasja_ibragimowich")
Example #2
0
    def test_author(self):
        urls = (
            ("http://samlib.ru/p/pupkin_wasja_ibragimowich/indexdate.shtml", "Ясинский Анджей"),
            ("http://samlib.ru/e/elxterrus_i/", "Эльтеррус Иар"),
            ("http://samlib.ru/x/xgulliver/", "Gulliver"),
            ("http://samlib.ru/m/muhin_d_w/", "Zang"),
            ("http://zhurnal.lib.ru/z/zajcew_aleskandr/", "Зайцев Алескандр"),
        )
        for url, name in urls:
            author = core.create_author(url=url)
            self.assertEqual(author.name, name)

            books = models.Book.get_by_author(author, only_new=True)
            self.assertGreater(len(books), 0)

            core.book_read(books[0])
            new_books = models.Book.get_by_author(author, only_new=True)
            self.assertGreater(len(books), len(new_books))

        core.delete_author(urls[0][0])
        author = models.Author.get_by_url(urls[0][0])
        self.assertIsNone(author)

        self.assertRaises(
            urllib.request.URLError, core.create_author, "http://http://samlib.ru/p/pupkin_wasja_ibragimowich"
        )
Example #3
0
                if only_authors:
                    print('{name:>s}: {url:>}'.format(name=author.name,
                        url=author.url))
                else:
                    books = models.Book.get_by_author(
                        author=author,
                        only_new=only_new
                    )
                    if books:
                        print('{name:>s}: {url:>}'.format(name=author.name,
                            url=author.url))
                        for book in books:
                            if book.is_new:
                                template = '\t>>> {name:>s}: {url:>}'
                                if mark_as_read:
                                    core.book_read(book)
                            else:
                                template = '\t{name:>s}: {url:>}'
                            if descriptions:
                                template += '\n\t\t{desc:>}'
                            print(template.format(
                                name=book.name,
                                url=book.url,
                                desc=book.desc)
                            )
        if not is_console:
            main()
    except KeyboardInterrupt:
        if is_console:
            print('Exit')
Example #4
0
            only_new = args.show == 'new'
            for author in sorted(models.Author.get(),
                key=lambda author: author.name
            ):
                if only_authors:
                    print('{name:>s}: {url:>}'.format(name=author.name,
                        url=author.url))
                else:
                    books = models.Book.get_by_author(
                        author=author,
                        only_new=only_new
                    )
                    if books:
                        print('{name:>s}: {url:>}'.format(name=author.name,
                            url=author.url))
                        for book in books:
                            if book.is_new:
                                template = '\t>>> {name:>s}: {url:>}'
                                core.book_read(book)
                            else:
                                template = '\t{name:>s}: {url:>}'
                            print(template.format(
                                name=book.name,
                                url=book.url)
                            )
        if not is_console:
            main()
    except KeyboardInterrupt:
        if is_console:
            print('Exit')
Example #5
0
 def mark_all_read(self, event=None):
     for group in self.books:
         for book in self.books[group]:
             core.book_read(book)
     self.books = self.books
Example #6
0
 def open_book(self, event=None):
     if self.book:
         core.book_read(self.book)
         self.tree.item(self.tree.focus(), image=[])
         webbrowser.open_new_tab(self.book.url)
Example #7
0
 def all_readed(self, event=None):
     for group in self.books:
         for book in self.books[group]:
             core.book_read(book)
     self.books = self.books
Example #8
0
 def open_book(self, event=None):
     if self.book:
         core.book_read(self.book)
         self.tree.item(self.tree.focus(), image=[])
         webbrowser.open_new_tab(self.book.url)