mirror of
https://github.com/serialexperiments0815/OpenLibFetch.git
synced 2026-07-12 15:32:24 +00:00
59 lines
No EOL
1.8 KiB
Python
59 lines
No EOL
1.8 KiB
Python
import requests as rq
|
|
|
|
|
|
class request_api():
|
|
|
|
def __init__(self):
|
|
self.Booktitle = None
|
|
self.Bookauthor = None
|
|
self.Bookisbn = None
|
|
self.Bookdate = None
|
|
self.Booktext = None
|
|
|
|
def search(self, input):
|
|
filtered_input = ''
|
|
for x in input:
|
|
|
|
if x == ' ':
|
|
x = '+'
|
|
filtered_input += x
|
|
|
|
Book = rq.get(f"https://openlibrary.org/search.json?q={filtered_input}&fields=key,title,author_name,editions,isbn,number_of_pages_median,publish_date,availability&limit=1")
|
|
Booktext = Book.json()
|
|
Bookinfo = Booktext['docs'][0]
|
|
|
|
self.Booktitle = Bookinfo.get('title')
|
|
self.Bookauthor = Bookinfo.get('author_name')
|
|
self.Bookisbn = Bookinfo.get('isbn')
|
|
self.Bookdate = Bookinfo.get('publish_date')
|
|
|
|
|
|
def return_title(self, x):
|
|
return self.Booktitle[x]
|
|
|
|
def return_author(self, x):
|
|
return self.Bookauthor[x]
|
|
|
|
def return_isbn(self, x = None):
|
|
try:
|
|
if x != None:
|
|
return self.Bookisbn[x]
|
|
if x == None:
|
|
return self.Bookisbn
|
|
except IndexError:
|
|
return self.Bookisbn[0]
|
|
|
|
def return_date(self, x):
|
|
return self.Bookdate[x]
|
|
|
|
def out_image(self, imageisbn=None):
|
|
if imageisbn is None:
|
|
imageisbn = self.Bookisbn[0]
|
|
image_output = f'https://covers.openlibrary.org/b/isbn/{imageisbn}-L.jpg'
|
|
return image_output
|
|
|
|
def out_image_small(self, imageisbn=None):
|
|
if imageisbn is None:
|
|
imageisbn = self.Bookisbn[0]
|
|
image_output = f'https://covers.openlibrary.org/b/isbn/{imageisbn}-M.jpg'
|
|
return image_output |