Esempio n. 1
0
def novel(Int_Ent_Sent,conn,user_name):
    title = [i.lower() for i in list(dict.fromkeys(Int_Ent_Sent['Entity'])) if i.lower() in list(df['novel_name'])]
    author = [i.lower() for i in list(dict.fromkeys(Int_Ent_Sent['Entity'])) if i.lower() in list(df['writer'])]
    publisher = [i.lower() for i in list(dict.fromkeys(Int_Ent_Sent['Entity'])) if i.lower() in list(df['publisher'])]
    year = [i.lower() for i in list(dict.fromkeys(Int_Ent_Sent['Entity'])) if i.lower() in list(df['year'])]
    descr = [i.lower() for i in list(dict.fromkeys(Int_Ent_Sent['Entity'])) if i.lower() in list(df['descr'])]
    while (1):
        if title:
            #proceed
            l = Library()
            ids = l.search(title[0])
            if ids:
                for id in ids:
                    b1 = l.lookup(id, fields=["*"])
                for b in b1:
                    slack.post_message(conn, random.choice(["details of novel "+b.__dict__['title']+" are"]))
                    if author:
                        slack.post_message(conn, random.choice(["author : " + str(b.__dict__['author']) ]))
                    if publisher:
                        slack.post_message(conn, random.choice(["publisher : " + str(b.__dict__['publisher'])]))
                    if year:
                        slack.post_message(conn, random.choice(["year : " + str(b.__dict__['year'])]))
                    if descr:
                        slack.post_message(conn, random.choice(["descr : " + str(b.__dict__['descr']) ]))
            break
        else:
            slack.post_message(conn,'Please enter the novel name correctly')
            title= [slack.get_message(conn)][0]
Esempio n. 2
0
def test_api_endpoints():
    for mirror in constants.MIRRORS:
        lg = Library(mirror)
        ids = lg.search('automate the boring stuff', 'title')
        assert isinstance(ids, list)
        assert set(ids) == set([
            '1421206',
            '1421207',
            '1421208',
            '1351717',
            '1381538',
            '1381540',
            '1529338',
        ])

        books = lg.lookup(ids)
        assert isinstance(books, list)
        assert isinstance(books[0], dict)
        assert {book['md5']
                for book in books} == {
                    'd826b3e593b12422784f50d59c97a966',
                    'b34564156c3778261ed03167b09f6694',
                    '4e0efdd614737fd66408fd43a9d5ff10',
                    '5a64e12e79af379110a31ea04bb6320c',
                    'c157d6ec28d1a7c4b528f4e6a1ea4c9e',
                    '054255117b2e86251415292ef48320fd',
                    '1af2c71c1342e850e1e47013b06f9eb9',
                }

        book = lg.lookup(1421206)
        assert isinstance(book, dict)
        assert book['md5'] == '1af2c71c1342e850e1e47013b06f9eb9'

        lg.get_download_url(books[0]['md5'])
Esempio n. 3
0
 def __init__(self):
     self.lib = PyLib()
     self.path_download = Path(config.PATH_DOWNLOAD)
     if not self.path_download.is_dir():
         self.path_download.mkdir()
     self.path_converted = Path(config.PATH_CONVERTED)
     if not self.path_converted.is_dir():
         self.path_converted.mkdir()
     self.path_sent = Path(config.PATH_SENT)
     if not self.path_sent.is_dir():
         self.path_sent.mkdir()
Esempio n. 4
0
def libgen(ctx, author, title, isbn):
    """
    Look for documents on library genesis

    Examples of its usage are

    papis explore libgen -a 'Albert einstein' export --yaml einstein.yaml

    """
    from pylibgen import Library
    logger = logging.getLogger('explore:libgen')
    logger.info('Looking up...')
    lg = Library()
    ids = []

    if author:
        ids += lg.search(ascii(author), 'author')
    if isbn:
        ids += lg.search(ascii(isbn), 'isbn')
    if title:
        ids += lg.search(ascii(title), 'title')

    try:
        data = lg.lookup(ids)
    except:
        data = []

    docs = [papis.document.from_data(data=d.__dict__) for d in data]
    ctx.obj['documents'] += docs
    logger.info('{} documents found'.format(len(docs)))
Esempio n. 5
0
 def libgen(self, search):
     from pylibgen import Library
     parsed = self.parse_search()
     lg = Library()
     ids = []
     for key in ['title', 'author', 'isbn']:
         if parsed.get(key):
             ids += lg.search(ascii(parsed.get(key)), key)
     if len(ids) == 0:
         ids = lg.search(ascii(parsed.get('query')), 'title')
     if len(ids):
         data = lg.lookup(ids)
     else:
         self.logger.error("No documents found")
         return None
     doc = self.pick([papis.document.Document(data=d) for d in data])
     if doc:
         doc['doc_url'] = lg.get_download_url(doc['md5'])
     return doc
Esempio n. 6
0
from pylibgen import Library

from contextlib import closing

from PyQt5.Qt import QUrl

from calibre import browser
from calibre.gui2 import open_url
from calibre.gui2.store import StorePlugin
from calibre.gui2.store.basic_config import BasicStoreConfig
from calibre.gui2.store.search_result import SearchResult
from calibre.gui2.store.web_store_dialog import WebStoreDialog


lg = Library()
br = browser()


class LibGen_Store(BasicStoreConfig, StorePlugin):


    RES_THRESH = 5
    url = 'http://gen.lib.rus.ec'

    def open(self, parent=None, detail_item=None, external=False):

        detail_url = None
        if detail_item:
            detail_url = self.get_cover_page(detail_item)
Esempio n. 7
0
class Library:
    def __init__(self):
        self.lib = PyLib()
        self.path_download = Path(config.PATH_DOWNLOAD)
        if not self.path_download.is_dir():
            self.path_download.mkdir()
        self.path_converted = Path(config.PATH_CONVERTED)
        if not self.path_converted.is_dir():
            self.path_converted.mkdir()
        self.path_sent = Path(config.PATH_SENT)
        if not self.path_sent.is_dir():
            self.path_sent.mkdir()

    def get_ids(self, isbn13):
        """
        :return: a list of ids
        """
        for timeout in range(10):
            try:
                ids = self.lib.search(isbn13)
                if ids:
                    return ids
            except:
                continue
        return []

    def get_ebooks_info(self, ids):
        """
        :return: an iterator
        """
        if ids:
            for timeout in range(10):
                try:
                    info = self.lib.lookup(ids)
                    if any(True for _ in info):
                        return info
                except:
                    continue
        return None

    def get_url(self, isbn13):
        ids = self.get_ids(isbn13)
        ebooks = self.get_ebooks_info(ids)
        url = None
        if ebooks is not None:
            for timeout in range(10):
                try:
                    url = next(ebooks).get_url(filehost='libgen.io')
                except:
                    continue
            return url
        else:
            print("No ebooks... :(")
        return None

    def download(self, isbn13):
        os.chdir(self.path_download)
        url = self.get_url(isbn13)
        if url is not None:
            r = requests.get(url)
            return r.raise_for_status()
        else:
            return None

    def get_converted_filename(self, filename):
        return "".join(filename.split(".")[0:-1]) + ".azw3"

    def get_extension(self, filename):
        return filename.split(".")[-1]

    def move_converted_file(self, file):
        file.rename(self.path_converted)

    def move_sent_file(self, file):
        file.rename(self.path_sent)

    def convert_to_kindle(self):
        for file in self.path_download.iterdir():
            if file.is_file():
                if file.suffix in [".mobi", ".azw3"]:
                    self.move_converted_file(file)
                else:
                    filename = str(file)
                    converted_filename = self.get_converted_filename(filename)
                    subprocess.call(
                        ["ebook-convert", filename, converted_filename])
                    self.move_converted_file(Path(converted_filename))
Esempio n. 8
0
from pylibgen import Library
l = Library()
ids = l.search('harry')
for id in ids:
    b1=l.lookup(id,fields=["*"])
    for b in b1:
        print(b.__dict__)
Esempio n. 9
0
 async def part2_get_best_book_from_ids(self,
                                        pylibgen_lib: pylibgen.Library,
                                        book_ids: list[str], session):
     libgen_books = pylibgen_lib.lookup(ids=book_ids, extension="pdf")
     return next(libgen_books)
Esempio n. 10
0
 async def part1_get_book_ids(self, pylibgen_lib: pylibgen.Library,
                              isbn: str, session):
     return pylibgen_lib.search(req=isbn, mode="isbn")
Esempio n. 11
0
#                                  pylibgen                                   #
#-----------------------------------------------------------------------------#
import subprocess
from slugify import slugify
from pylibgen import Library

def fname_book(book):
    title = slugify(book.title)
    fname = title + '.pdf'
    return fname

def get_book(book):
    fname = fname_book(book)
    subprocess.run(f'wget -O {fname} {book.get_url()}', shell=True)

l = Library()

def search(isbn):
    ids = l.search(isbn)
    if len(ids) == 0:
        print('No results!')
        return
    books = list(l.lookup(ids))
    for i, b in enumerate(books):
        if b.extension != 'pdf':
            continue
        print(f'BOOK {i}')
        pprint(vars(b))
        print('\n')
    bidx = input('Download book: ')
    if bidx: