Skip to content

Commit

Permalink
#2: Added code to filter out GoodReads Review nodes with invalid ISBN…
Browse files Browse the repository at this point in the history
…13s.
  • Loading branch information
OOPMan committed Nov 10, 2016
1 parent f739eac commit ac8ca31
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ object GoodreadsLibraryValueCalculator extends App {

val reviewPages = isbnUtils.getAllReviews(config)
// TODO: Find a way to clean this up
val reviewNodes = for (reviewPage <- reviewPages) yield (for (reviews <- reviewPage) yield reviews \\ "review").flatten
val allReviewNodes = for (reviewPage <- reviewPages) yield (for (reviews <- reviewPage) yield reviews \\ "review").flatten
val reviewNodes = for (reviews <- allReviewNodes) yield reviews.filter { review =>
val reviewId = (review \ "id").text
val bookId = (review \ "book" \ "id").text
val isbn13 = (review \\ "isbn13").text
val title = (review \\ "title").text
if (isbn13.length != 13) logger.info(s"Skipping $title (Book ID: $bookId) with invalid ISBN '$isbn13' for Review ID $reviewId")
isbn13.length == 13
}

// TODO: Find a way to clean this up
val isbnNodes = for (review <- reviewNodes) yield (for (reviewNode <- review) yield reviewNode \\ "isbn13").flatten
val collectedISBNs = isbnNodes.map { i => i.map { j => j.text } }
val collectedISBNs = isbnNodes.map(_.map(_.text))
// TODO: Find a way to clean this up
val titleNodes = for (review <- reviewNodes) yield (for (reviewNode <- review) yield reviewNode \\ "title").flatten
val collectedTitles = titleNodes.map { i => i.map { j => j.text } }
val collectedTitles = titleNodes.map(_.map(_.text))

// TODO: Use this to output titles of unmatched ISBNs
val isbnToTitle = for {
Expand Down

0 comments on commit ac8ca31

Please sign in to comment.