Ejemplo n.º 1
0
    def post(self, request, **kwargs):

        print(request.body)

        json_str = json.loads(request.body)

        user_email = json_str['email']
        password = json_str['password']

        user = CustomUser.objects.get(email=json_str['email'])

        if not user.check_password(password):
            return HttpResponse("Invalid login details supplied.")

        try:

            json_book_data = json_str['query']

            book_data = BookData()
            hasSearch = False
            if 'title' in json_book_data:
                if json_book_data['title'] != "":
                    book_data.title = json_book_data['title']
                    hasSearch = True
            if 'author' in json_book_data:
                json_book_data['author'] != ""
                if json_book_data['author'] != "":
                    book_data.authors = [json_book_data['author']]
                    hasSearch = True
            if 'ISBN' in json_book_data:
                if json_book_data['ISBN'] != "":
                    book_data.isbn_13 = json_book_data['ISBN']
                    hasSearch = True

            if not hasSearch:
                raise Exception()

        except:
            return HttpResponse("Bad Request, Example: " + json.dumps(example))

        newQuery = Query()
        newQuery.user = user
        newQuery.save()

        book_data.print_data()
        company = user.getCompany()
        print(company)

        site_name_list = str(company.search_sites).split(",")
        site_slug_list = []
        site_list = []
        for site_name in site_name_list:
            Site = {"name": site_name, "slug": siteToSlug(site_name)}
            site_list.append(Site)
            site_slug_list.append(siteToSlug(site_name))

        result_data = {}
        for site in site_slug_list:
            result_data[site] = [
                i for i in (
                    Sort(get_book_site(site).find_book_matches(book_data)))
                if i[0] > .20
            ]

        # test_book = BookData()
        # test_book.format = Format.DIGITAL
        # test_book.title = "Murder and Intrigue on the Mexican Border"
        # test_book.subtitle = "Somethign"
        # test_book.image_url = "https://books.google.com/books/content/images/frontcover/-lRoDwAAQBAJ?fif"
        # test_book.isbn_13 = "9781623495855"
        # test_book.authors = ['John A. Adams']
        # test_book.extra = {'Price': '$9.99'}

        # result_data = {'GB' : [(0.5, test_book), (0.5, test_book)]}

        for slug in result_data:
            book_list = result_data[slug]
            for count in range(0, len(book_list)):
                book = book_list[count]
                book[1].content = None
                book[1].image = None
                book_list[count] = {'Match': book[0], "Book": book[1].data}

        return JsonResponse(result_data)
Ejemplo n.º 2
0
def testAudiobooks():
    book_site = get_book_site("AB")
    book_data = book_site.get_book_data(
        "https://www.audiobooks.com/audiobook/chronicles-of-narnia-adult-box-set/347498"
    )
    book_data.print_data()
Ejemplo n.º 3
0
    def post(self, request, **kwargs):
        company = request.user.getCompany()
        newQuery = Query()
        newQuery.user = request.user
        newQuery.save()

        if 'searchJSON' in request.POST:
            search = True
            searchJSON = request.POST['searchJSON']
            json_book_data = json.loads(searchJSON)
            # print("Book Data:" + str(json_book_data))

            book_data = BookData()
            if 'title' in json_book_data:
                print("There's a title")
                book_data.title = json_book_data['title']
            if 'author' in json_book_data:
                book_data.authors = [json_book_data['author']]
            if 'ISBN' in json_book_data:
                book_data.isbn_13 = json_book_data['ISBN']

        elif ('searchTitle'
              in request.POST) or ('searchAuthor'
                                   in request.POST) or ('searchISBN'
                                                        in request.POST):
            search = True
            book_data = BookData()
            if request.POST['searchTitle'] != "":
                book_data.title = request.POST['searchTitle']
            if request.POST['searchAuthor'] != "":
                book_data.authors = [request.POST['searchAuthor']]
            if request.POST['searchISBN'] != "":
                book_data.isbn_13 = request.POST['searchISBN']

        site_name_list = str(company.search_sites).split(",")
        site_slug_list = []
        site_list = []
        for site_name in site_name_list:
            Site = {"name": site_name, "slug": siteToSlug(site_name)}
            site_list.append(Site)
            site_slug_list.append(siteToSlug(site_name))

        result_data = {}

        for site in site_slug_list:
            result_data[site] = [
                i for i in (
                    Sort(get_book_site(site).find_book_matches(book_data)))
                if i[0] > .20
            ]

        print(result_data)

        context = {
            'company': company,
            'searchResults': result_data,
            'site_list': site_list,
            'search': search,
        }

        return render(request, 'search_page.html', context)
Ejemplo n.º 4
0
def testGoogle():
    book_site = get_book_site("GB")
    book_data = book_site.get_book_data(
        "https://play.google.com/store/books/details?id=-lRoDwAAQBAJ&source=gbs_api"
    )
    book_data.print_data()
Ejemplo n.º 5
0
def testScribd():
    book_site = get_book_site("SD")
    book_data = book_site.get_book_data(
        "https://www.scribd.com/book/357813054/Principles-Life-and-Work")
    book_data.print_data()
Ejemplo n.º 6
0
def testLivrariaCultura():
    book_site = get_book_site("LC")
    book_data = book_site.get_book_data(
        "https://www3.livrariacultura.com.br/what-if-its-us-2012739487/p")
    book_data.print_data()
Ejemplo n.º 7
0
def testKobo():
    book_site = get_book_site("KB")
    book_data = book_site.get_book_data(
        "https://www.kobo.com/us/en/ebook/snow-white-before-the-hea-2")
    book_data.print_data()
Ejemplo n.º 8
0
def testBookstore():
    book_site = get_book_site("TB")
    book_data = book_site.get_book_data(
        "http://127.0.0.1:8000/library/9781524243456/")
    book_data.print_data()