コード例 #1
0
        //For each object passed into the method's arguments, it will check whether it is null. If it is not null then it further check to see if the object's attribute for holding the average rating is not equal to 0. If is does not equal
        //then it will assign this data value to the public BookModel object's corresponding data attribute.
        private void SetAverageRatings(GoodreadsModel goodreadsBookData, GoolgeBooksApi.GoogleBookModel googleBooksBookData, AmazonModel amazonBookData)
        {
            if (googleBooksBookData != null)
            {
                if (googleBooksBookData.AverageRating != 0)
                {
                    bookModel.GoogleBooksAverageRating = googleBooksBookData.AverageRating;
                }
            }

            if (goodreadsBookData != null)
            {
                if (goodreadsBookData.AverageRating != 0)
                {
                    bookModel.GoodreadsAverageRating = goodreadsBookData.AverageRating;
                }
            }

            if (amazonBookData != null)
            {
                if (amazonBookData.AverageRating != 0)
                {
                    bookModel.GoodreadsAverageRating = amazonBookData.AverageRating;
                }
            }
        }
コード例 #2
0
        //Tnis method works by checking with the GoogleBookModel and GoodreadsModel(passed into the method's arguments) is not null. If both are not null then it check whether the title attribute held by the GoodreadsModel object is not null or empty. If it is
        //not null or empty then this data value will be assigned to the public BookModel object's data attribute which holds the title. If the object's title attribute value is null or empty then check whether the title attribute held by the GoodreadsModel object
        //is not null or empty. If it is not null or empty then this data value will be assigned to the public BookModel object's data attribute which holds the title.

        //However if one or both of the objects are null then check whether the GoogleBookModel object is null. If it is not null then check whether the title attribute held by the GoogleBookModel object is not null or empty. If it is
        //not null or empty then this data value will be assigned to the public BookModel object's data attribute which holds the title. If the GoogleBookModel object is null then check whether the GoodreadsModel object is null. If it is not null then check whether
        //the title attribute held by the GoodreadsModel object is not null or empty. If it is not null or empty then this data value will be assigned to the public BookModel object's data attribute which holds the title.
        private void SetBookTitle(GoodreadsModel goodreadsBookData, GoogleBookModel googleBooksBookData)
        {
            if (goodreadsBookData != null && googleBooksBookData != null)
            {
                if (!String.IsNullOrEmpty(goodreadsBookData.Title))
                {
                    bookModel.Title = goodreadsBookData.Title;
                }

                else if (!String.IsNullOrEmpty(googleBooksBookData.Title))
                {
                    bookModel.Title = googleBooksBookData.Title;
                }
            }
            else
            {
                if (googleBooksBookData != null)
                {
                    if (!String.IsNullOrEmpty(googleBooksBookData.Title))
                    {
                        bookModel.Title = googleBooksBookData.Title;
                    }
                }
                else if (goodreadsBookData != null)
                {
                    if (!String.IsNullOrEmpty(goodreadsBookData.Title))
                    {
                        bookModel.Title = goodreadsBookData.Title;
                    }
                }
            }
        }
コード例 #3
0
        //This method works by checking whether the GoogleBookModel object and GoodreadsModel object (both passed into the method's argument) is not null. If it is not null then it will check whether the GoodreadsModel object's page count attribute is
        //null. If it is not null then assign this data value to the public BookModel object's data attribute that holds the page count. If it is null then check whether the GoogleBooksModel object's page count attribute value is equal to 0.
        //If it does not equal 0 then assign this data value to the public BookModel object's data attribute that holds the page count.

        //However, if one or both of the objects(passed into the method's arguments) is not null then it first
        //checks whether the GoodreadsModel object is null. If it is not null then it will check whether the GoodreadsModel object's page count attribute is
        //null. If it is not null then assign this data value to the public BookModel object's data attribute that holds the page count. If it is null then it will check whether the GoogleBooksModel object is null. If it is not null then it will check whether
        //the GoogleBooksModel object's page count attribute value is equal to 0. If it does not equal 0 then assign this data value to the public BookModel object's data attribute that holds the page count.
        private void SetPageCount(GoodreadsModel goodreadsBookData, GoogleBookModel googleBooksBookData)
        {
            if (goodreadsBookData != null && googleBooksBookData != null)
            {
                if (goodreadsBookData.PageCount != null)
                {
                    bookModel.PageCount = goodreadsBookData.PageCount;
                }
                else if (googleBooksBookData.PageCount != 0)
                {
                    bookModel.PageCount = googleBooksBookData.PageCount;
                }
            }
            else
            {
                if (goodreadsBookData != null)
                {
                    if (goodreadsBookData.PageCount != null)
                    {
                        bookModel.PageCount = goodreadsBookData.PageCount;
                    }
                }
                else if (googleBooksBookData != null)
                {
                    if (googleBooksBookData.PageCount != 0)
                    {
                        bookModel.PageCount = googleBooksBookData.PageCount;
                    }
                }
            }
        }
コード例 #4
0
        //This method by first checking whether both the GoodreadsModel and GoogleBooksModel objects(passed into the method's arguments) is not null. If both are not null then it will check whether the description attribute value
        //held by each object actually contains a description. If both objects hold information relating to the description then it will check the description held by the GoodreadsModel object is longer than the description held by
        //the GoogleBookModel object. If it is longer than summarise the description held by the GoodreadsModel object and assign the summarised description to the public BookMode object's data attribute which holds the description.
        //If it is not longer than summarise the description held by the GoogleBookModel object and assign the summarised description to the public BookMode object's data attribute which holds the description.

        //However, if one or both objects do not contain a description then it will check whether the description held by the GoodreadsModel is null or empty. If it is not then it will summarise that description and assign the summarised
        //description to the public BookMode object's data attribute which holds the description. If it is null or empty then it check whether the description held by the GoogleBooksModel is null or empty. If it is not then it will summarise that description and assign the summarised
        //description to the public BookMode object's data attribute which holds the description.
        //The second outer else statement is to deal with cases where the GoodreadsModel  and/or GoogleBookModel objects is null. If this else statement is satisfied then it will check if the GoogleBooksModel object is null
        //and if it is not null then it will check  whether the description held by the GoogleBookModel object is null or empty. It it's not null or empty then this description will be summarised and the summarised description will be assigned
        //to the public BookModel object's data attribute that holds the description. If the GoogleBookModel object is null then it will check if the GoodreadsModel object is null
        //and if it is not null then it will check  whether the description held by the GoodreadsModel object is null or empty. It it's not null or empty then this description will be summarised and the summarised description will be assigned
        //to the public BookModel object's data attribute that holds the description.
        private void SetDescription(GoodreadsModel goodreadsBookData, GoolgeBooksApi.GoogleBookModel googleBooksBookData)
        {
            string summarisedBookDescription;

            if (goodreadsBookData != null && googleBooksBookData != null)
            {
                if (goodreadsBookData.Description.Length > 0 && googleBooksBookData.Description.Length > 0)
                {
                    if (goodreadsBookData.Description.Length > googleBooksBookData.Description.Length)
                    {
                        summarisedBookDescription = SummariseDescription(goodreadsBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }
                    else
                    {
                        summarisedBookDescription = SummariseDescription(googleBooksBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(goodreadsBookData.Description))
                    {
                        summarisedBookDescription = SummariseDescription(goodreadsBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }

                    else if (!String.IsNullOrEmpty(googleBooksBookData.Description))
                    {
                        summarisedBookDescription = SummariseDescription(googleBooksBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }
                }
            }
            else
            {
                if (googleBooksBookData != null)
                {
                    if (!String.IsNullOrEmpty(googleBooksBookData.Description))
                    {
                        summarisedBookDescription = SummariseDescription(googleBooksBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }
                }
                else if (goodreadsBookData != null)
                {
                    if (!String.IsNullOrEmpty(goodreadsBookData.Description))
                    {
                        summarisedBookDescription = SummariseDescription(goodreadsBookData.Description);
                        bookModel.Description     = summarisedBookDescription;
                    }
                }
            }
        }
コード例 #5
0
        //This method by first checking whether both the GoodreadsModel and GoogleBooksModel objects(passed into the method's arguments) is not null. If both are not null then it will check whether the Authors attribute value
        //held by GoogleBookModel model actually contains one or more author. If this check is passed then it will assign these authors to the public BookMode object's data attribute which holds the authors. If the check was not met then
        //it will check whether the Authors attribute value held by GoodreadsModel model actually contains one or more author. If this check is passed then it will iterate through each author and add it to the initialised list of authors and then will assign this list
        //to the public BookModel object's data attribute which holds the authors. If neither objects contained authors then assign an empty string list to the public BookModel object's data attribute which holds the authors.

        //However, if one or both objects are null then it will check if the GoogleBookModel object is null. If it isn't then it will check whether the Authors attribute value held by GoogleBookModel model actually contains one or more author.
        //If this check is passed then it will assign these authors to the public BookMode object's data attribute which holds the authors. If the GoogleBookModel object is null then it will check whether the GoodreadModel is not null and if it is not null then
        //it will check whether the Authors attribute value held by GoodreadsModel model actually contains one or more author. If this check is passed then it will iterate through each author and add it to the initialised list of authors and then will assign this list
        //to the public BookModel object's data attribute which holds the authors. If neither objects are null then it will assign an empty string list to the public BookModel object's data attribute which holds the authors.

        private void SetAuthorsOfBook(GoodreadsModel goodreadsBookData, GoogleBookModel googleBooksBookData)
        {
            if (goodreadsBookData != null && googleBooksBookData != null)
            {
                if (googleBooksBookData.Authors.Count != 0)
                {
                    bookModel.Authors = googleBooksBookData.Authors;
                }
                else if (goodreadsBookData.Authors.Count != 0)
                {
                    List <string> authors = new List <string>();
                    foreach (var author in goodreadsBookData.Authors)
                    {
                        authors.Add(author.Name);
                    }
                    bookModel.Authors = authors;
                }
                else
                {
                    bookModel.Authors = new List <string>();
                }
            }
            else
            {
                if (googleBooksBookData != null)
                {
                    if (googleBooksBookData.Authors.Count != 0)
                    {
                        bookModel.Authors = googleBooksBookData.Authors;
                    }
                }
                else if (goodreadsBookData != null)
                {
                    if (goodreadsBookData.Authors.Count != 0)
                    {
                        List <string> authors = new List <string>();
                        foreach (var author in goodreadsBookData.Authors)
                        {
                            authors.Add(author.Name);
                        }
                        bookModel.Authors = authors;
                    }
                    else
                    {
                        bookModel.Authors = new List <string>();
                    }
                }
            }
        }
コード例 #6
0
        //This method works by checking whether the GoogleBookModel object and GoodreadsModel object (both passed into the method's argument) is not null. If it is not null then it will check whether the GoodreadsModel object's Isbn attribute is
        //null or empty. If it is not then this isbn value url will be assigned to the public BookModel object data attribute that holds the isbn. If it is null or empty then it check whether the GoogleBooksModel object's Isbn attribute is
        //null or empty. If it is then this isbn value url will be assigned to the public BookModel object's data attribute that holds the isbn. If it is null or empty then the isbn(passed into the method's arguments) will be checked to see
        //if it contains numbers to confirm that it is a valid isbn. If this check passes then this isbn will be assigned to the public BookModel object's data attribute that holds the isbn.

        //However, if the one or both of the GoogleBookModel and GoodreadsModel object is null, it will check each model object individually to see if it is null and if it isn't then it will proceed to check if it's Isbn data attribute is not null nor empty.
        //Similarly, once that passes then it will be assigned to the public BookModel object data attribute that holds the isbn. If it neither object is not null then it repeats the same process as for checking the isbn(passed into the method;s arguments)
        //to see if it contains number and if it does, it will assign that value to the public BookModel object's data attribute that holds the isbn.
        private void SetIsbn(GoodreadsModel goodreadsBookData, GoogleBookModel googleBookModel, string retrievedIsbn)
        {
            if (googleBookModel != null && goodreadsBookData != null)
            {
                if (!String.IsNullOrEmpty(goodreadsBookData.Isbn))
                {
                    bookModel.Isbn = goodreadsBookData.Isbn;
                }
                else if (!String.IsNullOrEmpty(GetIsbn(googleBookModel)))
                {
                    bookModel.Isbn = GetIsbn(googleBookModel);
                }
                else
                {
                    if (retrievedIsbn.All(char.IsDigit).Equals(true))
                    {
                        bookModel.Isbn = retrievedIsbn;
                    }
                }
            }
            else
            {
                if (googleBookModel != null)
                {
                    if (!String.IsNullOrEmpty(GetIsbn(googleBookModel)))
                    {
                        bookModel.Isbn = GetIsbn(googleBookModel);
                    }
                }
                else if (goodreadsBookData != null)
                {
                    if (!String.IsNullOrEmpty(goodreadsBookData.Isbn))
                    {
                        bookModel.Isbn = goodreadsBookData.Isbn;
                    }
                }
                else
                {
                    if (retrievedIsbn.All(char.IsDigit).Equals(true))
                    {
                        bookModel.Isbn = retrievedIsbn;
                    }
                }
            }
        }
コード例 #7
0
        //This method works by first checking with the data(passed into the method's argument) is an Isbn. If it is not an isbn number it will first collect book data from the Google books api and uses the output to retrieve the
        //isbn number and this is then used to get book data from the Goodreads api. If the data is an isbn number then get the book data from the Google books and Goodreads apis. Afterwards, it then uses the data retrieved from
        //the Goodreads api to initalise the GoodreadsModel. This model along with the GoogleBookModel is used to set the description to the BookModel object which involves working the Python text summariser to receive a
        //summarised description of the book which is what is assigned to the BookModel object. It then proceeds use the AmazonWebScraper to scrape the relevent book data from the relevent product page and this returns
        //and AmazonModel object. All three models( GoodreadsModel, GoogleBooksModel and AmazonModel) were used to initialise the attributes for the BookModel object.
        public async void CollectDataFromSources(string data)
        {
            bookModel = new BookModel();
            server    = new TCPServer();
            dominantColorWebScraper = new DominantColorWebScraper();
            amazonWebScraper        = new AmazonWebScraper();
            AmazonModel amazonBookData = null;

            IWebDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            //If the data doesnt contain the isbn then the isbn will be initially retrieved
            //from the google books api which is then passed into the good reads api solution
            var dataContainsIsbn = data.All(char.IsDigit);

            if (dataContainsIsbn.Equals(false))
            {
                googleBookTask = googleBookApi.CollectDataForBook(data);
                amazonTask     = amazonWebScraper.CollectDataForBook(driver, data);
                var isbn = GetIsbn(googleBookModel);
                goodreadsTask = goodreadsApi.SearchByIsbn(isbn);
            }
            else
            {
                googleBookTask = googleBookApi.CollectDataForBook(data);
                amazonTask     = amazonWebScraper.CollectDataForBook(driver, data);
                goodreadsTask  = goodreadsApi.SearchByIsbn(data);
            }

            Task.WhenAll(amazonTask, googleBookTask, goodreadsTask);

            googleBookModel = googleBookTask.Result;

            //Check if model has a valid thumbnail url
            if (googleBookModel.ThumbnailUrl.Count() > 2)
            {
                DominantColorWebScraper dominantColorWebScraper = new DominantColorWebScraper();
                var dominantColour = dominantColorWebScraper.GetDominantColor(driver, googleBookModel.ThumbnailUrl);
                dominantColorString = dominantColour;
            }

            var            book           = goodreadsTask.Result;
            GoodreadsModel goodreadsModel = null;

            if (book != null)
            {
                goodreadsModel = goodreadsApi.CollectDataForBook(book);
            }

            amazonBookData = amazonTask.Result;
            SetDescription(goodreadsModel, googleBookModel);

            SetBookTitle(goodreadsModel, googleBookModel);
            SetAuthorsOfBook(goodreadsModel, googleBookModel);

            SetAverageRatings(goodreadsModel, googleBookModel, amazonBookData);
            SetPageCount(goodreadsModel, googleBookModel);
            SetAmazonRatings(amazonBookData);
            SetAmazonReviews(amazonBookData);
            SetReviewCount(amazonBookData);
            SetGenres(googleBookModel);
            SetSubtitle(googleBookModel);
            SetIsbn(goodreadsModel, googleBookModel, data);
            SetThumbnailUrl(googleBookModel);
            SetDominantColor(dominantColorString);
        }