diff --git a/.flake8 b/.flake8 index 7ba08ab34ff..5441aa4f239 100644 --- a/.flake8 +++ b/.flake8 @@ -1,8 +1,14 @@ [flake8] count = true exclude = ./.*,vendor/*,node_modules/* +# 55 E203 whitespace before ':' -- Do not fix, black will remove it +# 18 E402 module level import not at top of file +# 47 E722 do not use bare 'except' +# 120 F401 '.model.*' imported but unused +# 10 F811 redefinition of unused '_' from line 34 +# 60 F841 local variable 'account' is assigned to but never used extend-ignore = E203,E402,E722,F401,F811,F841,I max-complexity = 41 -max-line-length = 1195 +max-line-length = 200 show-source = true statistics = true diff --git a/openlibrary/admin/numbers.py b/openlibrary/admin/numbers.py index 9e353f5b14f..7b33d7c7bcc 100644 --- a/openlibrary/admin/numbers.py +++ b/openlibrary/admin/numbers.py @@ -92,8 +92,9 @@ def admin_range__human_edits(**kargs): result = db.query(q1) total_edits = result[0].count q1 = ( - "SELECT count(DISTINCT t.id) AS count FROM transaction t, version v WHERE v.transaction_id=t.id AND t.created >= '%s' and t.created < '%s' AND t.author_id IN (SELECT thing_id FROM account WHERE bot = 't')" - % (start, end) + "SELECT count(DISTINCT t.id) AS count FROM transaction t, version v WHERE " + "v.transaction_id=t.id AND t.created >= '%s' and t.created < '%s' AND " + "t.author_id IN (SELECT thing_id FROM account WHERE bot = 't')" % (start, end) ) result = db.query(q1) bot_edits = result[0].count @@ -111,8 +112,9 @@ def admin_range__bot_edits(**kargs): except KeyError as k: raise TypeError("%s is a required argument for admin_range__bot_edits" % k) q1 = ( - "SELECT count(*) AS count FROM transaction t, version v WHERE v.transaction_id=t.id AND t.created >= '%s' and t.created < '%s' AND t.author_id IN (SELECT thing_id FROM account WHERE bot = 't')" - % (start, end) + "SELECT count(*) AS count FROM transaction t, version v WHERE " + "v.transaction_id=t.id AND t.created >= '%s' and t.created < '%s' AND " + "t.author_id IN (SELECT thing_id FROM account WHERE bot = 't')" % (start, end) ) result = db.query(q1) count = result[0].count diff --git a/openlibrary/catalog/add_book/tests/test_add_book.py b/openlibrary/catalog/add_book/tests/test_add_book.py index c48c6588ef2..7232806ed69 100644 --- a/openlibrary/catalog/add_book/tests/test_add_book.py +++ b/openlibrary/catalog/add_book/tests/test_add_book.py @@ -555,7 +555,12 @@ def test_extra_author(mock_site, add_languages): "covers": [6060295, 5551343], "first_sentence": { "type": "/type/text", - "value": "When it first became known to Europe that a new continent had been discovered, the wise men, philosophers, and especially the learned ecclesiastics, were sorely perplexed to account for such a discovery.", + "value": ( + "When it first became known to Europe that a new continent had " + "been discovered, the wise men, philosophers, and especially the " + "learned ecclesiastics, were sorely perplexed to account for such " + "a discovery.", + ), }, "subject_places": [ "Alaska", @@ -584,7 +589,12 @@ def test_extra_author(mock_site, add_languages): ], "excerpts": [ { - "excerpt": "When it first became known to Europe that a new continent had been discovered, the wise men, philosophers, and especially the learned ecclesiastics, were sorely perplexed to account for such a discovery." + "excerpt": ( + "When it first became known to Europe that a new continent " + "had been discovered, the wise men, philosophers, and " + "especially the learned ecclesiastics, were sorely perplexed " + "to account for such a discovery." + ) } ], "first_publish_date": "1882", @@ -835,7 +845,11 @@ def test_same_twice(mock_site, add_languages): 'source_records': ['ia:test_item'], "publishers": ["Ten Speed Press"], "pagination": "20 p.", - "description": "A macabre mash-up of the children's classic Pat the Bunny and the present-day zombie phenomenon, with the tactile features of the original book revoltingly re-imagined for an adult audience.", + "description": ( + "A macabre mash-up of the children's classic Pat the Bunny and the " + "present-day zombie phenomenon, with the tactile features of the original " + "book revoltingly re-imagined for an adult audience.", + ), "title": "Pat The Zombie", "isbn_13": ["9781607740360"], "languages": ["eng"], diff --git a/openlibrary/core/lending.py b/openlibrary/core/lending.py index aa9ed9bbda6..2764389ffdf 100644 --- a/openlibrary/core/lending.py +++ b/openlibrary/core/lending.py @@ -63,7 +63,13 @@ def setup(config): """Initializes this module from openlibrary config.""" - global config_loanstatus_url, config_ia_access_secret, config_bookreader_host, config_ia_ol_shared_key, config_ia_ol_xauth_s3, config_internal_tests_api_key, config_ia_loan_api_url, config_http_request_timeout, config_ia_availability_api_v2_url, config_ia_ol_metadata_write_s3, config_ia_xauth_api_url, config_http_request_timeout, config_ia_s3_auth_url, config_ia_users_loan_history, config_ia_loan_api_developer_key, config_ia_civicrm_api, config_ia_domain + global config_loanstatus_url, config_ia_access_secret, config_bookreader_host + global config_ia_ol_shared_key, config_ia_ol_xauth_s3, config_internal_tests_api_key + global config_ia_loan_api_url, config_http_request_timeout + global config_ia_availability_api_v2_url, config_ia_ol_metadata_write_s3 + global config_ia_xauth_api_url, config_http_request_timeout, config_ia_s3_auth_url + global config_ia_users_loan_history, config_ia_loan_api_developer_key + global config_ia_civicrm_api, config_ia_domain config_loanstatus_url = config.get('loanstatus_url') config_bookreader_host = config.get('bookreader_host', 'archive.org') diff --git a/openlibrary/plugins/importapi/import_edition_builder.py b/openlibrary/plugins/importapi/import_edition_builder.py index 4d04a622af4..579ddc8d75e 100644 --- a/openlibrary/plugins/importapi/import_edition_builder.py +++ b/openlibrary/plugins/importapi/import_edition_builder.py @@ -13,9 +13,77 @@ which is stored as a list of authors in the edition dict. A sample dict looks like one of these: -{'edition_name': u'3rd ed.', 'pagination': u'xii, 444 p.', 'title': u'A course of pure mathematics', 'publishers': [u'At the University Press'], 'number_of_pages': 444, 'languages': ['eng'], 'publish_date': '1921', 'location': [u'GLAD'], 'authors': [{'birth_date': u'1877', 'personal_name': u'Hardy, G. H.', 'death_date': u'1947', 'name': u'Hardy, G. H.', 'entity_type': 'person'}], 'by_statement': u'by G.H. Hardy', 'publish_places': [u'Cambridge'], 'publish_country': 'enk'} -{'publishers': [u'Ace Books'], 'pagination': u'271 p. ;', 'title': u'Neuromancer', 'lccn': [u'91174394'], 'notes': u'Hugo award book, 1985; Nebula award ; Philip K. Dick award', 'number_of_pages': 271, 'isbn_13': [u'9780441569595'], 'languages': ['eng'], 'dewey_decimal_class': [u'813/.54'], 'lc_classifications': [u'PS3557.I2264 N48 1984', u'PR9199.3.G53 N49 1984'], 'publish_date': '1984', 'publish_country': 'nyu', 'authors': [{'birth_date': u'1948', 'personal_name': u'Gibson, William', 'name': u'Gibson, William', 'entity_type': 'person'}], 'by_statement': u'William Gibson', 'oclc_numbers': ['24379880'], 'publish_places': [u'New York'], 'isbn_10': [u'0441569595']} -{'publishers': [u'Grosset & Dunlap'], 'pagination': u'156 p.', 'title': u'Great trains of all time', 'lccn': [u'62051844'], 'number_of_pages': 156, 'languages': ['eng'], 'dewey_decimal_class': [u'625.2'], 'lc_classifications': [u'TF147 .H8'], 'publish_date': '1962', 'publish_country': 'nyu', 'authors': [{'birth_date': u'1894', 'personal_name': u'Hubbard, Freeman H.', 'name': u'Hubbard, Freeman H.', 'entity_type': 'person'}], 'by_statement': u'Illustrated by Herb Mott', 'oclc_numbers': [u'1413013'], 'publish_places': [u'New York']} +{ + "edition_name": "3rd ed.", + "pagination": "xii, 444 p.", + "title": "A course of pure mathematics", + "publishers": ["At the University Press"], + "number_of_pages": 444, + "languages": ["eng"], + "publish_date": "1921", + "location": ["GLAD"], + "authors": [ + { + "birth_date": "1877", + "personal_name": "Hardy, G. H.", + "death_date": "1947", + "name": "Hardy, G. H.", + "entity_type": "person", + } + ], + "by_statement": "by G.H. Hardy", + "publish_places": ["Cambridge"], + "publish_country": "enk", +} +{ + "publishers": ["Ace Books"], + "pagination": "271 p. ;", + "title": "Neuromancer", + "lccn": ["91174394"], + "notes": "Hugo award book, 1985; Nebula award ; Philip K. Dick award", + "number_of_pages": 271, + "isbn_13": ["9780441569595"], + "languages": ["eng"], + "dewey_decimal_class": ["813/.54"], + "lc_classifications": ["PS3557.I2264 N48 1984", "PR9199.3.G53 N49 1984"], + "publish_date": "1984", + "publish_country": "nyu", + "authors": [ + { + "birth_date": "1948", + "personal_name": "Gibson, William", + "name": "Gibson, William", + "entity_type": "person", + } + ], + "by_statement": "William Gibson", + "oclc_numbers": ["24379880"], + "publish_places": ["New York"], + "isbn_10": ["0441569595"], +} +{ + "publishers": ["Grosset & Dunlap"], + "pagination": "156 p.", + "title": "Great trains of all time", + "lccn": ["62051844"], + "number_of_pages": 156, + "languages": ["eng"], + "dewey_decimal_class": ["625.2"], + "lc_classifications": ["TF147 .H8"], + "publish_date": "1962", + "publish_country": "nyu", + "authors": [ + { + "birth_date": "1894", + "personal_name": "Hubbard, Freeman H.", + "name": "Hubbard, Freeman H.", + "entity_type": "person", + } + ], + "by_statement": "Illustrated by Herb Mott", + "oclc_numbers": ["1413013"], + "publish_places": ["New York"], +} """ from openlibrary.plugins.importapi.import_validator import import_validator diff --git a/openlibrary/plugins/importapi/metaxml_to_json.py b/openlibrary/plugins/importapi/metaxml_to_json.py index b0d4a46c14f..2839c1f2085 100755 --- a/openlibrary/plugins/importapi/metaxml_to_json.py +++ b/openlibrary/plugins/importapi/metaxml_to_json.py @@ -6,7 +6,30 @@ usage: > python metaxml_to_json.py romanceonthreele00hafnrich_meta.xml -{"publishers": ["New York : Bloomsbury"], "description": "Includes bibliographical references (p. [243]-247) and index", "title": "A romance on three legs : Glenn Gould's obsessive quest for the perfect piano", "isbn_10": ["1596915250"], "isbn_13": ["9781596915251"], "languages": ["eng"], "subjects": ["Lending library", "protected DAISY", "Accessible book", "Gould, Glenn, 1932-1982", "Steinway piano"], "publish_date": "2009", "authors": [{"entity_type": "person", "name": "Hafner, Katie", "personal_name": "Hafner, Katie"}], "ocaid": "romanceonthreele00hafnrich"} +{ + "publishers": ["New York : Bloomsbury"], + "description": "Includes bibliographical references (p. [243]-247) and index", + "title": "A romance on three legs : Glenn Gould's obsessive quest for the perfect piano", + "isbn_10": ["1596915250"], + "isbn_13": ["9781596915251"], + "languages": ["eng"], + "subjects": [ + "Lending library", + "protected DAISY", + "Accessible book", + "Gould, Glenn, 1932-1982", + "Steinway piano", + ], + "publish_date": "2009", + "authors": [ + { + "entity_type": "person", + "name": "Hafner, Katie", + "personal_name": "Hafner, Katie", + } + ], + "ocaid": "romanceonthreele00hafnrich", +} """ from openlibrary.plugins.importapi.import_edition_builder import import_edition_builder diff --git a/openlibrary/plugins/openlibrary/home.py b/openlibrary/plugins/openlibrary/home.py index 51f2a100204..2706d45d188 100644 --- a/openlibrary/plugins/openlibrary/home.py +++ b/openlibrary/plugins/openlibrary/home.py @@ -19,8 +19,18 @@ logger = logging.getLogger("openlibrary.home") CAROUSELS_PRESETS = { - 'preset:thrillers': '(creator:"Clancy, Tom" OR creator:"King, Stephen" OR creator:"Clive Cussler" OR creator:("Cussler, Clive") OR creator:("Dean Koontz") OR creator:("Koontz, Dean") OR creator:("Higgins, Jack")) AND !publisher:"Pleasantville, N.Y. : Reader\'s Digest Association" AND languageSorter:"English"', - 'preset:comics': '(subject:"comics" OR creator:("Gary Larson") OR creator:("Larson, Gary") OR creator:("Charles M Schulz") OR creator:("Schulz, Charles M") OR creator:("Jim Davis") OR creator:("Davis, Jim") OR creator:("Bill Watterson") OR creator:("Watterson, Bill") OR creator:("Lee, Stan"))', + 'preset:thrillers': ( + '(creator:"Clancy, Tom" OR creator:"King, Stephen" OR creator:"Clive Cussler" ' + 'OR creator:("Cussler, Clive") OR creator:("Dean Koontz") OR creator:("Koontz, ' + 'Dean") OR creator:("Higgins, Jack")) AND !publisher:"Pleasantville, N.Y. : ' + 'Reader\'s Digest Association" AND languageSorter:"English"' + ), + 'preset:comics': ( + '(subject:"comics" OR creator:("Gary Larson") OR creator:("Larson, Gary") ' + 'OR creator:("Charles M Schulz") OR creator:("Schulz, Charles M") OR ' + 'creator:("Jim Davis") OR creator:("Davis, Jim") OR creator:("Bill Watterson")' + 'OR creator:("Watterson, Bill") OR creator:("Lee, Stan"))' + ), 'preset:authorsalliance_mitpress': ( '(openlibrary_subject:(authorsalliance) OR collection:(mitpress) OR ' 'publisher:(MIT Press) OR openlibrary_subject:(mitpress))' diff --git a/openlibrary/plugins/upstream/borrow.py b/openlibrary/plugins/upstream/borrow.py index 531b6a97214..834b2e79ca1 100644 --- a/openlibrary/plugins/upstream/borrow.py +++ b/openlibrary/plugins/upstream/borrow.py @@ -879,7 +879,9 @@ def get_ia_auth_dict(user, item_id, user_specified_loan_key, access_token): # Book is not checked out as a BookReader loan - may still be checked out in ACS4 error_message = 'Lending Library Book' resolution_message = ( - 'This book is part of the lending library. Please visit this book\'s page on Open Library to access the book.' + 'This book is part of the ' + 'lending library. Please ' + 'visit this book\'s page on Open Library to access the book.' % resolution_dict ) @@ -891,8 +893,11 @@ def get_ia_auth_dict(user, item_id, user_specified_loan_key, access_token): # Borrowed by someone else - OR possibly came in through ezproxy and there's a stale login in on openlibrary.org error_message = 'This book is checked out' resolution_message = ( - 'This book is currently checked out. You can visit this book\'s page on Open Library or look at other books available to borrow.' - % resolution_dict + 'This book is currently checked out. You can ' + 'visit this book\'s page on ' + 'Open Library or ' + 'look at other ' + 'books available to borrow.' % resolution_dict ) elif loan['expiry'] < datetime.datetime.utcnow().isoformat(): @@ -922,7 +927,12 @@ def get_ia_auth_dict(user, item_id, user_specified_loan_key, access_token): # Couldn't validate using token - they need to go to Open Library error_message = "Lending Library Book" resolution_message = ( - 'This book is part of the lending library. Please visit this book\'s page on Open Library to access the book. You must have cookies enabled for archive.org and openlibrary.org to access borrowed books.' + 'This book is part of the lending library. ' + 'Please visit this book\'s page on Open Library' + ' to access the book. You must have cookies enabled for ' + 'archive.org and openlibrary.org to access borrowed books.' % resolution_dict ) diff --git a/openlibrary/utils/olcompress.py b/openlibrary/utils/olcompress.py index 9ca8b892be7..bdbc6e691fd 100644 --- a/openlibrary/utils/olcompress.py +++ b/openlibrary/utils/olcompress.py @@ -7,10 +7,10 @@ # using 4 random records from OL seed -seed1 = '{"subject_place": ["Great Britain", "Great Britain."], "lc_classifications": ["RT85.5 .K447 1994"], "contributions": ["Richardson, Eileen, RGN."], "id": 1875537, "title": "nursing process and quality care", "languages": [{"key": "/l/eng"}], "subjects": ["Nursing -- Quality control.", "Nursing -- Standards.", "Nursing audit.", "Nursing -- Great Britain -- Quality control.", "Nursing -- Standards -- Great Britain.", "Nursing audit -- Great Britain."], "publish_country": "cau", "title_prefix": "The ", "type": {"key": "/type/edition"}, "by_statement": "Nan Kemp, Eileen Richardson.", "revision": 1, "other_titles": ["Nursing process & quality care."], "publishers": ["Singular Pub. Group"], "last_modified": {"type": "/type/datetime", "value": "2008-04-01 03:28:50.625462"}, "key": "/b/OL1234567M", "authors": [{"key": "/a/OL448883A"}], "publish_places": ["San Diego, Calif"], "pagination": "132 p. :", "dewey_decimal_class": ["362.1/73/0685"], "notes": {"type": "/type/text", "value": "Includes bibliographical references and index.\nCover title: The nursing process & quality care."}, "number_of_pages": 132, "lccn": ["94237442"], "isbn_10": ["1565933834"], "publish_date": "1994"}' -seed2 = '{"subtitle": "exploration & celebration : papers delivered at an academic conference honoring twenty years of women in the rabbinate, 1972-1992", "subject_place": ["United States"], "lc_classifications": ["BM652 .W66 1996"], "contributions": ["Zola, Gary Phillip."], "id": 1523482, "title": "Women rabbis", "languages": [{"key": "/l/eng"}], "subjects": ["Women rabbis -- United States -- Congresses.", "Reform Judaism -- United States -- Congresses.", "Women in Judaism -- Congresses."], "publish_country": "ohu", "by_statement": "edited by Gary P. Zola.", "type": {"key": "/type/edition"}, "revision": 1, "publishers": ["HUC-JIR Rabbinic Alumni Association Press"], "last_modified": {"type": "/type/datetime", "value": "2008-04-01 03:28:50.625462"}, "key": "/b/OL987654M", "publish_places": ["Cincinnati"], "pagination": "x, 135 p. ;", "dewey_decimal_class": ["296.6/1/082"], "notes": {"type": "/type/text", "value": "Includes bibliographical references and index."}, "number_of_pages": 135, "lccn": ["96025781"], "isbn_10": ["0878202145"], "publish_date": "1996"}' -seed3 = '{"name": "W. Wilkins Davis", "personal_name": "W. Wilkins Davis", "death_date": "1866.", "last_modified": {"type": "/type/datetime", "value": "2008-08-21 07:57:48.336414"}, "key": "/a/OL948765A", "birth_date": "1842", "type": {"key": "/type/author"}, "id": 2985386, "revision": 2}' -seed4 = '{"name": "Alberto Tebechrani", "personal_name": "Alberto Tebechrani", "last_modified": {"type": "/type/datetime", "value": "2008-09-08 15:29:34.798941"}, "key": "/a/OL94792A", "type": {"key": "/type/author"}, "id": 238564, "revision": 2}' +seed1 = '{"subject_place": ["Great Britain", "Great Britain."], "lc_classifications": ["RT85.5 .K447 1994"], "contributions": ["Richardson, Eileen, RGN."], "id": 1875537, "title": "nursing process and quality care", "languages": [{"key": "/l/eng"}], "subjects": ["Nursing -- Quality control.", "Nursing -- Standards.", "Nursing audit.", "Nursing -- Great Britain -- Quality control.", "Nursing -- Standards -- Great Britain.", "Nursing audit -- Great Britain."], "publish_country": "cau", "title_prefix": "The ", "type": {"key": "/type/edition"}, "by_statement": "Nan Kemp, Eileen Richardson.", "revision": 1, "other_titles": ["Nursing process & quality care."], "publishers": ["Singular Pub. Group"], "last_modified": {"type": "/type/datetime", "value": "2008-04-01 03:28:50.625462"}, "key": "/b/OL1234567M", "authors": [{"key": "/a/OL448883A"}], "publish_places": ["San Diego, Calif"], "pagination": "132 p. :", "dewey_decimal_class": ["362.1/73/0685"], "notes": {"type": "/type/text", "value": "Includes bibliographical references and index.\nCover title: The nursing process & quality care."}, "number_of_pages": 132, "lccn": ["94237442"], "isbn_10": ["1565933834"], "publish_date": "1994"}' # noqa: E501 +seed2 = '{"subtitle": "exploration & celebration : papers delivered at an academic conference honoring twenty years of women in the rabbinate, 1972-1992", "subject_place": ["United States"], "lc_classifications": ["BM652 .W66 1996"], "contributions": ["Zola, Gary Phillip."], "id": 1523482, "title": "Women rabbis", "languages": [{"key": "/l/eng"}], "subjects": ["Women rabbis -- United States -- Congresses.", "Reform Judaism -- United States -- Congresses.", "Women in Judaism -- Congresses."], "publish_country": "ohu", "by_statement": "edited by Gary P. Zola.", "type": {"key": "/type/edition"}, "revision": 1, "publishers": ["HUC-JIR Rabbinic Alumni Association Press"], "last_modified": {"type": "/type/datetime", "value": "2008-04-01 03:28:50.625462"}, "key": "/b/OL987654M", "publish_places": ["Cincinnati"], "pagination": "x, 135 p. ;", "dewey_decimal_class": ["296.6/1/082"], "notes": {"type": "/type/text", "value": "Includes bibliographical references and index."}, "number_of_pages": 135, "lccn": ["96025781"], "isbn_10": ["0878202145"], "publish_date": "1996"}' # noqa: E501 +seed3 = '{"name": "W. Wilkins Davis", "personal_name": "W. Wilkins Davis", "death_date": "1866.", "last_modified": {"type": "/type/datetime", "value": "2008-08-21 07:57:48.336414"}, "key": "/a/OL948765A", "birth_date": "1842", "type": {"key": "/type/author"}, "id": 2985386, "revision": 2}' # noqa: E501 +seed4 = '{"name": "Alberto Tebechrani", "personal_name": "Alberto Tebechrani", "last_modified": {"type": "/type/datetime", "value": "2008-09-08 15:29:34.798941"}, "key": "/a/OL94792A", "type": {"key": "/type/author"}, "id": 238564, "revision": 2}' # noqa: E501 seed = seed1 + seed2 + seed3 + seed4