diff --git a/fedireads/connectors/abstract_connector.py b/fedireads/connectors/abstract_connector.py index 24573f1d..1e5c2665 100644 --- a/fedireads/connectors/abstract_connector.py +++ b/fedireads/connectors/abstract_connector.py @@ -284,8 +284,14 @@ def get_date(date_string): ''' helper function to try to interpret dates ''' if not date_string: return None + try: return pytz.utc.localize(parser.parse(date_string)) + except ValueError: + pass + + try: + return parser.parse(date_string) except ValueError: return None diff --git a/fedireads/tests/data/fr_edition.json b/fedireads/tests/data/fr_edition.json new file mode 100644 index 00000000..bdb7c150 --- /dev/null +++ b/fedireads/tests/data/fr_edition.json @@ -0,0 +1,42 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "type": "Document", + "book_type": "Edition", + "name": "Jonathan Strange and Mr Norrell", + "url": "https://example.com/book/122", + "authors": [ + "https://example.com/author/25" + ], + "published_date": "2017-05-10T00:00:00+00:00", + "work": { + "@context": "https://www.w3.org/ns/activitystreams", + "type": "Document", + "book_type": "Work", + "name": "Jonathan Strange and Mr Norrell", + "url": "https://example.com/book/121", + "authors": [ + "https://example.com/author/25" + ], + "title": "Jonathan Strange and Mr Norrell", + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpg", + "url": "https://example.com/images/covers/8775540-M.jpg", + "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + } + ] + }, + "title": "Jonathan Strange and Mr Norrell", + "subtitle": "Bloomsbury Modern Classics", + "isbn_13": "9781408891469", + "physical_format": "paperback", + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpg", + "url": "https://example.com/images/covers/9155821-M.jpg", + "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + } + ] +} diff --git a/fedireads/tests/data/fr_search.json b/fedireads/tests/data/fr_search.json new file mode 100644 index 00000000..05dcf4f8 --- /dev/null +++ b/fedireads/tests/data/fr_search.json @@ -0,0 +1 @@ +[{"title": "Jonathan Strange and Mr Norrell", "key": "https://example.com/book/122", "author": "Susanna Clarke", "year": 2017}] diff --git a/fedireads/tests/data/fr_work.json b/fedireads/tests/data/fr_work.json new file mode 100644 index 00000000..e93f6706 --- /dev/null +++ b/fedireads/tests/data/fr_work.json @@ -0,0 +1,44 @@ +{ + "@context": "https://www.w3.org/ns/activitystreams", + "type": "Document", + "book_type": "Work", + "name": "Jonathan Strange and Mr Norrell", + "url": "https://example.com/book/121", + "authors": [ + "https://example.com/author/25" + ], + "editions": [ + { + "@context": "https://www.w3.org/ns/activitystreams", + "type": "Document", + "book_type": "Edition", + "name": "Jonathan Strange and Mr Norrell", + "url": "https://example.com/book/122", + "authors": [ + "https://example.com/author/25" + ], + "published_date": "2017-05-10T00:00:00+00:00", + "title": "Jonathan Strange and Mr Norrell", + "subtitle": "Bloomsbury Modern Classics", + "isbn_13": "9781408891469", + "physical_format": "paperback", + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpg", + "url": "https://example.com/images/covers/9155821-M.jpg", + "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + } + ] + } + ], + "title": "Jonathan Strange and Mr Norrell", + "attachment": [ + { + "type": "Document", + "mediaType": "image/jpg", + "url": "https://example.com/images/covers/8775540-M.jpg", + "name": "Cover of \"Jonathan Strange and Mr Norrell\"" + } + ] +} diff --git a/fedireads/tests/data/ol_edition_list.json b/fedireads/tests/data/ol_edition_list.json new file mode 100644 index 00000000..7954ad3b --- /dev/null +++ b/fedireads/tests/data/ol_edition_list.json @@ -0,0 +1,1018 @@ +{ + "entries": [ + { + "publishers": [ + "Rba Libros" + ], + "physical_format": "Hardcover", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 6, + "key": "/books/OL9142127M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "subjects": [ + "Action & Adventure - General", + "Science Fiction, Fantasy, & Magic", + "Children's 12-Up - Fiction - Fantasy" + ], + "languages": [ + { + "key": "/languages/spa" + } + ], + "title": "Sabriel", + "identifiers": { + "librarything": [ + "10014" + ], + "goodreads": [ + "461102" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "isbn_13": [ + "9788478710539" + ], + "isbn_10": [ + "8478710531" + ], + "publish_date": "November 2006", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "revision": 6 + }, + { + "publishers": [ + "Harper Trophy" + ], + "number_of_pages": 491, + "ia_box_id": [ + "IA107202" + ], + "isbn_10": [ + "0060273224", + "0060273232", + "0064471837" + ], + "lc_classifications": [ + "PZ7.N647 Sab 1995" + ], + "latest_revision": 7, + "key": "/books/OL22951843M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "ocaid": "sabriel00nixg", + "publish_places": [ + "New York" + ], + "description": { + "type": "/type/text", + "value": "Sabriel, daughter of the necromancer Abhorsen, must journey into the mysterious and magical Old Kingdom to rescue her father from the Land of the Dead." + }, + "languages": [ + { + "key": "/languages/eng" + } + ], + "pagination": "491 p. :", + "title": "Sabriel", + "dewey_decimal_class": [ + "[Fic]" + ], + "notes": { + "type": "/type/text", + "value": "Originally published: Australia : HarperCollins, 1995." + }, + "identifiers": { + "goodreads": [ + "535197", + "1102517", + "518848" + ], + "librarything": [ + "10014" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2009-02-12T16:29:58.929717" + }, + "edition_name": "1st American ed.", + "lccn": [ + "96001295" + ], + "subjects": [ + "Fantasy." + ], + "publish_date": "1996", + "publish_country": "nyu", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "by_statement": "Garth Nix.", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 7 + }, + { + "publishers": [ + "Listening Library" + ], + "physical_format": "Audio CD", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 6, + "key": "/books/OL7946150M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "contributions": [ + "Tim Curry (Narrator)" + ], + "subjects": [ + "Classics", + "Children's Audio - 9-12" + ], + "isbn_13": [ + "9780807216057" + ], + "title": "Sabriel", + "identifiers": { + "goodreads": [ + "1226951" + ], + "librarything": [ + "10014" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-29T15:03:11.581851" + }, + "languages": [ + { + "key": "/languages/eng" + } + ], + "isbn_10": [ + "0807216054" + ], + "publish_date": "January 2006", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 6 + }, + { + "publishers": [ + "Eos" + ], + "number_of_pages": 336, + "physical_format": "Paperback", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 7, + "key": "/books/OL9952943M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "subjects": [ + "Action & Adventure - General", + "Science Fiction, Fantasy, & Magic", + "Juvenile Fiction / Science Fiction, Fantasy, Magic", + "General", + "Juvenile Fiction", + "Children's Books - Young Adult Fiction", + "Children: Young Adult (Gr. 7-9)" + ], + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "identifiers": { + "goodreads": [ + "2254009" + ], + "librarything": [ + "10014" + ] + }, + "isbn_13": [ + "9780061474354" + ], + "languages": [ + { + "key": "/languages/eng" + } + ], + "isbn_10": [ + "0061474355" + ], + "publish_date": "April 22, 2008", + "title": "Sabriel", + "oclc_numbers": [ + "227382439" + ], + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "physical_dimensions": "8 x 5.3 x 0.8 inches", + "revision": 7 + }, + { + "publishers": [ + "Tandem Library" + ], + "identifiers": { + "goodreads": [ + "1149573" + ], + "librarything": [ + "10014" + ] + }, + "weight": "9.8 ounces", + "isbn_10": [ + "0613035976" + ], + "covers": [ + 5014078 + ], + "physical_format": "School & Library Binding", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 8, + "key": "/books/OL9788823M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "languages": [ + { + "key": "/languages/eng" + } + ], + "title": "Sabriel", + "number_of_pages": 491, + "isbn_13": [ + "9780613035972" + ], + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "subjects": [ + "Action & Adventure - General", + "Science Fiction, Fantasy, & Magic", + "Children's 12-Up - Fiction - Fantasy", + "Fantastic fiction", + "Children: Young Adult (Gr. 7-9)" + ], + "publish_date": "October 1999", + "oclc_numbers": [ + "228061047" + ], + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "physical_dimensions": "6.7 x 3.9 x 1.2 inches", + "revision": 8 + }, + { + "publishers": [ + "Collins" + ], + "number_of_pages": 368, + "covers": [ + 10070 + ], + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 7, + "key": "/books/OL7262051M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "title": "Sabriel", + "identifiers": { + "goodreads": [ + "1102512" + ], + "librarything": [ + "10014" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-29T13:35:46.876380" + }, + "isbn_13": [ + "9780007137305" + ], + "isbn_10": [ + "0007137303" + ], + "publish_date": "2002", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 7 + }, + { + "publishers": [ + "Perfection Learning Prebound" + ], + "physical_format": "Unknown Binding", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 6, + "key": "/books/OL9486423M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "subjects": [ + "Fiction" + ], + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "identifiers": { + "goodreads": [ + "3176822" + ], + "librarything": [ + "10014" + ] + }, + "isbn_13": [ + "9780780772311" + ], + "isbn_10": [ + "0780772318" + ], + "publish_date": "September 1997", + "title": "Sabriel", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 6 + }, + { + "publishers": [ + "Collins" + ], + "number_of_pages": 368, + "covers": [ + 10069 + ], + "physical_format": "Hardcover", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 7, + "key": "/books/OL9216766M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "first_sentence": { + "type": "/type/text", + "value": "THE RABBIT HAD been run over minutes before." + }, + "title": "Sabriel", + "identifiers": { + "goodreads": [ + "1102512" + ], + "librarything": [ + "10014" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "isbn_13": [ + "9780007137305" + ], + "isbn_10": [ + "0007137303" + ], + "publish_date": "2002", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 7 + }, + { + "publishers": [ + "HarperCollins" + ], + "covers": [ + 6419775 + ], + "physical_format": "Electronic resource", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 4, + "key": "/books/OL24278530M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "publish_places": [ + "New York" + ], + "languages": [ + { + "key": "/languages/eng" + } + ], + "source_records": [ + "marc_overdrive/InternetArchiveCrMarc-2010-06-11p.mrc:7615355:1976" + ], + "title": "Sabriel", + "identifiers": { + "overdrive": [ + "F940DC17-8420-498F-994F-D63CE5DBC902" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2010-06-18T11:48:53.716798" + }, + "isbn_13": [ + "9780060005467", + "9780060773977" + ], + "publish_date": "2001", + "publish_country": "nyu", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 4 + }, + { + "publishers": [ + "Collins Audio" + ], + "number_of_pages": 640, + "weight": "12.6 ounces", + "isbn_10": [ + "0007146949" + ], + "covers": [ + 2309591 + ], + "physical_format": "Audio Cassette", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 8, + "key": "/books/OL9922813M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "contributions": [ + "Tim Curry (Narrator)" + ], + "title": "Sabriel", + "identifiers": { + "librarything": [ + "10014" + ], + "goodreads": [ + "1102511" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "isbn_13": [ + "9780007146949" + ], + "subjects": [ + "Fantasy", + "Children: Young Adult (Gr. 7-9)" + ], + "publish_date": "September 2, 2002", + "oclc_numbers": [ + "155997306" + ], + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "physical_dimensions": "5.4 x 4.2 x 2 inches", + "revision": 8 + }, + { + "publishers": [ + "Listening Library" + ], + "physical_format": "Audio Cassette", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 3, + "key": "/books/OL9370923M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "subjects": [ + "Unabridged Audio - Fiction/General", + "Juvenile Fiction", + "Children's audiobooks", + "Abridged Audio - Fiction/Religious", + "Audio: Juvenile", + "Science Fiction, Fantasy, & Magic", + "General", + "Audiobooks", + "Fantasy fiction" + ], + "edition_name": "Unabridged library edition", + "languages": [ + { + "key": "/languages/eng" + } + ], + "created": { + "type": "/type/datetime", + "value": "2008-04-30T09:38:13.731961" + }, + "title": "Sabriel", + "isbn_13": [ + "9780807205631" + ], + "isbn_10": [ + "080720563X" + ], + "publish_date": "April 23, 2002", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 3 + }, + { + "publishers": [ + "Listening Library" + ], + "identifiers": { + "goodreads": [ + "1149574" + ], + "librarything": [ + "10014" + ] + }, + "weight": "10.1 ounces", + "isbn_10": [ + "0807205567" + ], + "covers": [ + 589207 + ], + "physical_format": "Audio Cassette", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 7, + "key": "/books/OL7946044M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "contributions": [ + "Tim Curry (Narrator)" + ], + "languages": [ + { + "key": "/languages/eng" + } + ], + "title": "Sabriel", + "created": { + "type": "/type/datetime", + "value": "2008-04-29T15:03:11.581851" + }, + "isbn_13": [ + "9780807205563" + ], + "edition_name": "Unabridged edition", + "subjects": [ + "Juvenile Fiction", + "Classics", + "Children's Audio - 4-8", + "Children's Audio - 9-12", + "Audio: Juvenile", + "Science Fiction, Fantasy, & Magic", + "Fantasy fiction", + "Juvenile Fiction / General", + "Audiobooks", + "Children's audiobooks" + ], + "publish_date": "April 23, 2002", + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "physical_dimensions": "6.6 x 4 x 2.7 inches", + "revision": 7 + }, + { + "publishers": [ + "Allen & Unwin Pty Ltd" + ], + "description": { + "type": "/type/text", + "value": "The first book in the best-selling Old Kingdom trilogy. This compelling high fantasy is a passionately exciting tale of a young heroine who must do battle in the realm of Death itself to defeat a powerful enemy.For many years Sabriel has lived outside the walls of the Old Kingdom, away from the random power of Free Magic, and away from the Dead who won't stay dead. But now her father, the Mage Abhorsen, is missing, and to find him Sabriel must cross back into that treacherous world - and face the power of her own extraordinary destiny.This beautiful edition includes part of the original hand-written manuscript of Sabriel, an explanation by Garth Nix of his writing process, and a guide to the Necromancers' Bells.'Sabriel is a winner, a fantasy that reads like realism. Here is a world with the same solidity and four-dimensional authority as our own, created with invention, clarity and intelligence.' PHILIP PULLMAN'Passionately exciting, full of intriguing characters and stunning scenery, Sabriel is sheer enjoyment.' THE TIMES'Weaving horror and fantasy into a rich, original story ... a powerful, gripping quest.' THE AGEWinner of the Aurealis Award for Excellence in Australian Speculative Fiction" + }, + "physical_format": "eBook", + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "latest_revision": 3, + "key": "/books/OL24285280M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "publish_places": [ + "Sydney" + ], + "isbn_13": [ + "9781741769586" + ], + "source_records": [ + "marc_overdrive/InternetArchiveCrMarc-2010-06-11e.mrc:2003008:2456" + ], + "title": "Sabriel", + "identifiers": { + "overdrive": [ + "10864286-6F96-45CA-8368-38F67DE901A8" + ] + }, + "created": { + "type": "/type/datetime", + "value": "2010-06-22T20:56:33.526569" + }, + "languages": [ + { + "key": "/languages/eng" + } + ], + "publish_date": "2010", + "publish_country": "nyu", + "oclc_numbers": [ + "606614533" + ], + "works": [ + { + "key": "/works/OL15832982W" + } + ], + "type": { + "key": "/type/edition" + }, + "revision": 3 + }, + { + "number_of_pages": 292, + "covers": [ + 3843137, + 24365 + ], + "lc_classifications": [ + "PZ7.N647 Sab 1995" + ], + "latest_revision": 14, + "ocaid": "sabrielnixg00nixg", + "description": { + "type": "/type/text", + "value": "Sabriel, daughter of the necromancer Abhorsen, must journey into the mysterious and magical Old Kingdom to rescue her father from the Land of the Dead." + }, + "uri_descriptions": [ + "Publisher description" + ], + "edition_name": "1st American ed.", + "source_records": [ + "marc:marc_records_scriblio_net/part25.dat:166260532:904", + "marc:marc_loc_updates/v37.i22.records.utf8:7860393:1020", + "ia:sabrielnixg00nixg" + ], + "title": "Sabriel", + "languages": [ + { + "key": "/languages/eng" + } + ], + "subjects": [ + "Fantasy" + ], + "publish_country": "nyu", + "by_statement": "Garth Nix.", + "type": { + "key": "/type/edition" + }, + "uris": [ + "http://www.loc.gov/catdir/description/hc041/96001295.html" + ], + "revision": 14, + "publishers": [ + "HarperCollins" + ], + "ia_box_id": [ + "IA121618" + ], + "last_modified": { + "type": "/type/datetime", + "value": "2017-10-08T21:20:07.665236" + }, + "key": "/books/OL965004M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "publish_places": [ + "New York" + ], + "lccn": [ + "96001295" + ], + "pagination": "xi, 292 p. ;", + "created": { + "type": "/type/datetime", + "value": "2008-04-01T03:28:50.625462" + }, + "dewey_decimal_class": [ + "[Fic]" + ], + "notes": { + "type": "/type/text", + "value": "\"First published in 1995 by HarperCollins\"--verso t.p." + }, + "identifiers": { + "goodreads": [ + "1102517", + "535197" + ], + "librarything": [ + "10014" + ] + }, + "url": [ + "http://www.loc.gov/catdir/description/hc041/96001295.html" + ], + "isbn_10": [ + "0060273224", + "0060273232" + ], + "publish_date": "1995", + "works": [ + { + "key": "/works/OL15832982W" + } + ] + }, + { + "links": [ + { + "url": "http://www.loc.gov/catdir/description/hc041/96001295.html", + "title": "Publisher description" + } + ], + "covers": [ + 6796986 + ], + "local_id": [ + "urn:phillips:31867001228878", + "urn:sfpl:31223117573841", + "urn:sfpl:31223117573866", + "urn:sfpl:31223089678065", + "urn:sfpl:31223095696317", + "urn:sfpl:31223117573874", + "urn:sfpl:31223095696283", + "urn:sfpl:31223117573791", + "urn:sfpl:31223117573882", + "urn:sfpl:31223117573817", + "urn:sfpl:31223117573858", + "urn:sfpl:31223089678099", + "urn:sfpl:31223089678107", + "urn:sfpl:31223117573833", + "urn:sfpl:31223117573825", + "urn:sfpl:31223117573890" + ], + "lc_classifications": [ + "PZ7.N647 Sab 1995" + ], + "latest_revision": 5, + "ocaid": "sabrielnixg00nixg", + "description": { + "type": "/type/text", + "value": "Sabriel, daughter of the necromancer Abhorsen, must journey into the mysterious and magical Old Kingdom to rescue her father from the Land of the Dead." + }, + "languages": [ + { + "key": "/languages/eng" + } + ], + "source_records": [ + "ia:sabrielnixg00nixg", + "marc:marc_openlibraries_phillipsacademy/PANO_FOR_IA_05072019.mrc:13839588:1256", + "marc:marc_openlibraries_sanfranciscopubliclibrary/sfpl_chq_2018_12_24_run02.mrc:143114297:4621" + ], + "title": "Sabriel", + "edition_name": "1st American ed.", + "subjects": [ + "Fantasy" + ], + "publish_country": "nyu", + "by_statement": "Garth Nix", + "type": { + "key": "/type/edition" + }, + "revision": 5, + "publishers": [ + "HarperCollins" + ], + "ia_box_id": [ + "IA121618" + ], + "full_title": "Sabriel", + "last_modified": { + "type": "/type/datetime", + "value": "2019-07-22T10:06:26.311648" + }, + "key": "/books/OL24743307M", + "authors": [ + { + "key": "/authors/OL382982A" + } + ], + "publish_places": [ + "New York" + ], + "pagination": "xi, 292 p. ;", + "created": { + "type": "/type/datetime", + "value": "2011-07-07T16:30:28.384311" + }, + "lccn": [ + "96001295" + ], + "notes": { + "type": "/type/text", + "value": "\"First published in 1995 by HarperCollins\"--verso t.p." + }, + "number_of_pages": 292, + "dewey_decimal_class": [ + "[Fic]" + ], + "isbn_10": [ + "0060273224", + "0060273232" + ], + "publish_date": "1995", + "works": [ + { + "key": "/works/OL15832982W" + } + ] + } + ], + "links": { + "self": "/works/OL15832982W/editions.json", + "work": "/works/OL15832982W" + }, + "size": 15 +} diff --git a/fedireads/tests/test_connector_fedireads.py b/fedireads/tests/test_connector_fedireads.py new file mode 100644 index 00000000..b1da6f4c --- /dev/null +++ b/fedireads/tests/test_connector_fedireads.py @@ -0,0 +1,66 @@ +''' testing book data connectors ''' +from dateutil import parser +from django.test import TestCase +import json +import pathlib +import pytz + +from fedireads import models +from fedireads.connectors.fedireads_connector import Connector +from fedireads.connectors.abstract_connector import SearchResult, get_date + + +class FedireadsConnector(TestCase): + def setUp(self): + models.Connector.objects.create( + identifier='example.com', + connector_file='fedireads_connector', + base_url='https://example.com', + books_url='https://example.com', + covers_url='https://example.com/images/covers', + search_url='https://example.com/search?q=', + key_name='remote_id', + ) + self.connector = Connector('example.com') + + work_file = pathlib.Path(__file__).parent.joinpath( + 'data/fr_work.json') + edition_file = pathlib.Path(__file__).parent.joinpath( + 'data/fr_edition.json') + self.work_data = json.loads(work_file.read_bytes()) + self.edition_data = json.loads(edition_file.read_bytes()) + + + def test_is_work_data(self): + self.assertEqual(self.connector.is_work_data(self.work_data), True) + self.assertEqual(self.connector.is_work_data(self.edition_data), False) + + + def test_get_edition_from_work_data(self): + edition = self.connector.get_edition_from_work_data(self.work_data) + self.assertEqual(edition['url'], 'https://example.com/book/122') + + + def test_get_work_from_edition_data(self): + work = self.connector.get_work_from_edition_date(self.edition_data) + self.assertEqual(work['url'], 'https://example.com/book/121') + + + def test_format_search_result(self): + datafile = pathlib.Path(__file__).parent.joinpath('data/fr_search.json') + search_data = json.loads(datafile.read_bytes()) + results = self.connector.parse_search_data(search_data) + self.assertIsInstance(results, list) + + result = self.connector.format_search_result(results[0]) + self.assertIsInstance(result, SearchResult) + self.assertEqual(result.title, 'Jonathan Strange and Mr Norrell') + self.assertEqual(result.key, 'https://example.com/book/122') + self.assertEqual(result.author, 'Susanna Clarke') + self.assertEqual(result.year, 2017) + + + def test_get_date(self): + date = get_date(self.edition_data['published_date']) + expected = parser.parse("2017-05-10T00:00:00+00:00") + self.assertEqual(date, expected) diff --git a/fedireads/view_actions.py b/fedireads/view_actions.py index e490bf4a..85cf40af 100644 --- a/fedireads/view_actions.py +++ b/fedireads/view_actions.py @@ -13,6 +13,7 @@ from fedireads import forms, models, outgoing from fedireads import goodreads_import from fedireads.settings import DOMAIN from fedireads.views import get_user_from_username +from fedireads.books_manager import get_or_create_book def user_login(request): diff --git a/fedireads/views.py b/fedireads/views.py index e1009203..2acee9ed 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -6,7 +6,6 @@ from django.db.models import Avg, Q from django.http import HttpResponseBadRequest, HttpResponseNotFound,\ JsonResponse from django.core.exceptions import PermissionDenied -from django.shortcuts import redirect from django.template.response import TemplateResponse from django.views.decorators.csrf import csrf_exempt @@ -390,7 +389,7 @@ def edit_profile_page(request): def book_page(request, book_id, tab='friends'): ''' info about a book ''' - book = get_or_create_book(book_id) + book = models.Book.objects.select_subclasses().get(id=book_id) if is_api_request(request): return JsonResponse(activitypub.get_book(book))