aboutsummaryrefslogtreecommitdiff
path: root/challenge-019
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2019-07-30 21:03:18 +0100
committerSteven Wilson <steven1170@zoho.eu>2019-07-30 21:03:18 +0100
commit0b7f8a37e93d9542e2c450fccfa42b4d46f65cfd (patch)
tree52b975b84005622b804874caf28859f571cf132d /challenge-019
parent171b002d09482518b309a5c6a0f70f1621aad74a (diff)
downloadperlweeklychallenge-club-0b7f8a37e93d9542e2c450fccfa42b4d46f65cfd.tar.gz
perlweeklychallenge-club-0b7f8a37e93d9542e2c450fccfa42b4d46f65cfd.tar.bz2
perlweeklychallenge-club-0b7f8a37e93d9542e2c450fccfa42b4d46f65cfd.zip
add solution for task 3 and script output file
Diffstat (limited to 'challenge-019')
-rw-r--r--challenge-019/steven-wilson/perl5/ch-3.pl120
-rw-r--r--challenge-019/steven-wilson/perl5/output_ch-3_script_txt57
2 files changed, 177 insertions, 0 deletions
diff --git a/challenge-019/steven-wilson/perl5/ch-3.pl b/challenge-019/steven-wilson/perl5/ch-3.pl
new file mode 100644
index 0000000000..86b6edc034
--- /dev/null
+++ b/challenge-019/steven-wilson/perl5/ch-3.pl
@@ -0,0 +1,120 @@
+#!/usr/bin/env perl
+# Author: Steven Wilson
+# Date: 2019-07-30
+# Week: 019
+#
+# Task #3
+# Write a script to use NYT Books API. You can get API key here. For
+# more information about API, please visit page. The API task is
+# optional but we would love to see your solution.
+
+use strict;
+use warnings;
+use feature qw/ say /;
+use Data::Dumper;
+use LWP::UserAgent;
+use JSON::MaybeXS;
+use YAML::XS 'LoadFile';
+
+my $config = LoadFile('nytimes_api_key.yml');
+my $api_key = $config->{api_key};
+my $base_url = "https://api.nytimes.com/svc/books/v3";
+
+my $ua = LWP::UserAgent->new();
+
+# Best Sellers Lists Services
+# List Names
+# The lists/names service returns a list of all the NYT Best Sellers
+# Lists. Some lists are published weekly and others monthly. The
+# response includes when each list was first published and last
+# published.
+# /lists/names.json
+
+my $response = $ua->get("$base_url/lists/names.json?api-key=$api_key");
+my %rd = %{ decode_json( $response->decoded_content ) };
+my @results = @{ $rd{results} };
+my $query = "E-Book";
+say "NYT Best Sellers Lists containing the word \"$query\"";
+for my $item (@results) {
+ if ( $$item{list_name} =~ /$query/ ) {
+ say $$item{list_name};
+ }
+}
+print "\n\n";
+
+# List Data
+# The lists/{date}/{name} service returns the books on the best sellers
+# list for the specified date and list name.
+# /lists/2019-01-20/hardcover-fiction.json
+$response = $ua->get(
+ "$base_url/lists/2014-07-01/business-books.json?api-key=$api_key");
+%rd = %{ decode_json( $response->decoded_content ) };
+@results = @{ $rd{results}{books} };
+
+say
+ "$rd{results}{display_name} $rd{results}{updated} list published $rd{results}{published_date}";
+
+for my $item (@results) {
+ say "$$item{title} by $$item{author}";
+}
+print "\n\n";
+
+# Use "current" for {date} to get the latest list.
+# /lists/current/hardcover-fiction.json
+$response
+ = $ua->get(
+ "$base_url/lists/current/combined-print-and-e-book-nonfiction.json?api-key=$api_key"
+ );
+%rd = %{ decode_json( $response->decoded_content ) };
+@results = @{ $rd{results}{books} };
+
+say
+ "$rd{results}{display_name} $rd{results}{updated} list published $rd{results}{published_date}";
+
+for my $item (@results) {
+ say "$$item{title} by $$item{author}";
+}
+print "\n\n";
+
+# Book Reviews Services
+# The book reviews service lets you get NYT book review by author, ISBN,
+# or title.
+
+# /reviews.json?author=Michelle+Obama
+my $forename = "Bruce";
+my $surname = "Sterling";
+$response = $ua->get(
+ "$base_url/reviews.json?author=$forename+$surname&api-key=$api_key");
+%rd = %{ decode_json( $response->decoded_content ) };
+@results = @{ $rd{results} };
+
+say "Book reviews for $forename $surname";
+for my $item (@results) {
+ say "$$item{book_title} reviewed by $$item{byline}\n$$item{url}";
+}
+print "\n\n";
+
+# /reviews.json?isbn=9781524763138
+my $isbn = "9781524763138";
+$response = $ua->get(
+ "$base_url/reviews.json?isbn=$isbn&api-key=$api_key");
+%rd = %{ decode_json( $response->decoded_content ) };
+@results = @{ $rd{results} };
+
+say "Book review for isbn $isbn";
+for my $item (@results) {
+ say "$$item{book_title} by $$item{book_author} reviewed by $$item{byline}\n$$item{url}";
+}
+print "\n\n";
+
+# /reviews.json?title=Becoming
+my $title = "Becoming"; # This is the only one I can get to work
+$response = $ua->get(
+ "$base_url/reviews.json?title=$title&api-key=$api_key");
+%rd = %{ decode_json( $response->decoded_content ) };
+@results = @{ $rd{results} };
+
+say "Book review for title $title";
+for my $item (@results) {
+ say "$$item{book_title} by $$item{book_author} reviewed by $$item{byline}\n$$item{url}";
+}
diff --git a/challenge-019/steven-wilson/perl5/output_ch-3_script_txt b/challenge-019/steven-wilson/perl5/output_ch-3_script_txt
new file mode 100644
index 0000000000..c5befdef7d
--- /dev/null
+++ b/challenge-019/steven-wilson/perl5/output_ch-3_script_txt
@@ -0,0 +1,57 @@
+NYT Best Sellers Lists containing the word "E-Book"
+Combined Print and E-Book Fiction
+Combined Print and E-Book Nonfiction
+E-Book Fiction
+E-Book Nonfiction
+Childrens Middle Grade E-Book
+Young Adult E-Book
+
+
+Business MONTHLY list published 2014-07-06
+CAPITAL IN THE TWENTY-FIRST CENTURY by Thomas Piketty
+THINK LIKE A FREAK by Steven D Levitt and Stephen J Dubner
+FLASH BOYS by Michael Lewis
+OUTLIERS by Malcolm Gladwell
+LEAN IN by Sheryl Sandberg with Nell Scovell
+#GIRLBOSS by Sophia Amoruso
+THINKING, FAST AND SLOW by Daniel Kahneman
+STRESS TEST by Timothy F Geithner
+THE POWER OF HABIT by Charles Duhigg
+THRIVE by Arianna Huffington
+
+
+Combined Print & E-Book Nonfiction WEEKLY list published 2019-08-04
+EDUCATED by Tara Westover
+AMERICAN CARNAGE by Tim Alberta
+THREE WOMEN by Lisa Taddeo
+JUSTICE ON TRIAL by Mollie Hemingway and Carrie Severino
+THE PIONEERS by David McCullough
+BECOMING by Michelle Obama
+UNFREEDOM OF THE PRESS by Mark R Levin
+BORN A CRIME by Trevor Noah
+SAPIENS by Yuval Noah Harari
+AMERICA'S RELUCTANT PRINCE by Steven M Gillon
+THE MUELLER REPORT by with related materials The Washington Post
+THEY CALLED US ENEMY by George Takei, Justin Eisinger and Steven Scott
+JUST MERCY by Bryan Stevenson
+MAYBE YOU SHOULD TALK TO SOMEONE by Lori Gottlieb
+WHITE FRAGILITY by Robin DiAngelo
+
+
+Book reviews for Bruce Sterling
+Zeitgeist reviewed by JON GARELICK
+http://www.nytimes.com/2000/11/19/books/books-in-brief-fiction-130656.html
+Hacker Crackdown : Law and Disorder on the Electronic Frontier reviewed by BILL SHARP
+http://www.nytimes.com/1992/12/20/books/in-short-nonfiction-850192.html
+Heavy Weather reviewed by GERALD JONAS
+http://www.nytimes.com/1994/10/16/books/science-fiction.html
+
+
+Book review for isbn 9781524763138
+Becoming by Michelle Obama reviewed by ISABEL WILKERSON
+https://www.nytimes.com/2018/12/06/books/review/michelle-obama-becoming-memoir.html
+
+
+Book review for title Becoming
+Becoming by Michelle Obama reviewed by ISABEL WILKERSON
+https://www.nytimes.com/2018/12/06/books/review/michelle-obama-becoming-memoir.html