diff --git a/src/archive.py b/src/archive.py index 4d73ab6..5f18e17 100755 --- a/src/archive.py +++ b/src/archive.py @@ -5,14 +5,14 @@ from json import loads, dumps import requests as req -searchUrl = "https://archive.org/advancedsearch.php?q={0}&fl%5B%5D=avg_rating&fl%5B%5D=description&fl%5B%5D=identifier&fl%5B%5D=type&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=50&page=1&output=json&callback=callback&save=yes#raw" +searchUrl = "https://archive.org/advancedsearch.php?q={0}&fl%5B%5D=avg_rating&fl%5B%5D=description&fl%5B%5D=identifier&fl%5B%5D=mediatype&fl%5B%5D=type&fl%5B%5D=type&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=50&page=1&output=json&callback=callback&save=yes#raw" def searchIA(title, author): """ Do a search on The Internet Archive for a book """ print("running a search") - requrl = searchUrl.format(quote(title + " " + author)) + requrl = searchUrl.format(quote(title) + " AND " + quote(author)) try: results = loads(req.get(requrl).text[9:][0:-1]) except ValueError: @@ -24,7 +24,8 @@ def searchIA(title, author): return [] docs = results["response"]["docs"] urls = [] - for result in results["response"]["docs"][0:3]: + for result in [r for r in results["response"]["docs"][0:10] if r["mediatype"] == "texts"]: + print(result) urls.append("https://archive.org/details/%s" % result["identifier"]) return urls diff --git a/src/scripts/book.tag b/src/scripts/book.tag index 2c1444d..7ce82f1 100644 --- a/src/scripts/book.tag +++ b/src/scripts/book.tag @@ -9,14 +9,14 @@

-

- diff --git a/src/search.py b/src/search.py index ee04eb3..a9c67d0 100755 --- a/src/search.py +++ b/src/search.py @@ -20,8 +20,8 @@ es = elasticsearch.Elasticsearch() def summarize(text): splitted = text.split(" ") - if len(splitted) > 4: - return " ".join(splitted[0:4]) + ".." + if len(splitted) > 6: + return " ".join(splitted[0:6]) + ".." return text def sectionToJSON(section): @@ -204,7 +204,7 @@ def searchTerms(terms): if obj.books: secs["books"] = [ { - "booktitle" : summarize(book[0]), + "booktitle" : book[0], "bookauthor" : book[1], "bookprice" : book[2] }