Skip to content

Commit

Permalink
flake8 --max-line-length=200
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Dec 7, 2022
1 parent 918b6c1 commit 2770050
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 23 deletions.
8 changes: 7 additions & 1 deletion .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
10 changes: 6 additions & 4 deletions openlibrary/admin/numbers.py
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 17 additions & 3 deletions openlibrary/catalog/add_book/tests/test_add_book.py
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"],
Expand Down
8 changes: 7 additions & 1 deletion openlibrary/core/lending.py
Expand Up @@ -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')
Expand Down
74 changes: 71 additions & 3 deletions openlibrary/plugins/importapi/import_edition_builder.py
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion openlibrary/plugins/importapi/metaxml_to_json.py
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions openlibrary/plugins/openlibrary/home.py
Expand Up @@ -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))'
Expand Down
18 changes: 14 additions & 4 deletions openlibrary/plugins/upstream/borrow.py
Expand Up @@ -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 <a href="%(base_url)s/subjects/Lending_library">lending library</a>. Please <a href="%(base_url)s/ia/%(item_id)s/borrow">visit this book\'s page on Open Library</a> to access the book.'
'This book is part of the <a href="%(base_url)s/subjects/Lending_library">'
'lending library</a>. Please <a href="%(base_url)s/ia/%(item_id)s/borrow">'
'visit this book\'s page on Open Library</a> to access the book.'
% resolution_dict
)

Expand All @@ -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 <a href="%(base_url)s/ia/%(item_id)s">visit this book\'s page on Open Library</a> or <a href="%(base_url)s/subjects/Lending_library">look at other books available to borrow</a>.'
% resolution_dict
'This book is currently checked out. You can '
'<a href="%(base_url)s/ia/%(item_id)s">visit this book\'s page on '
'Open Library</a> or '
'<a href="%(base_url)s/subjects/Lending_library">look at other '
'books available to borrow</a>.' % resolution_dict
)

elif loan['expiry'] < datetime.datetime.utcnow().isoformat():
Expand Down Expand Up @@ -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 <a href="%(base_url)s/subjects/Lending_library" title="Open Library Lending Library">lending library</a>. Please <a href="%(base_url)s/ia/%(item_id)s/borrow" title="Borrow book page on Open Library">visit this book\'s page on Open Library</a> 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 <a href="%(base_url)s/subjects/Lending_'
'library" title="Open Library Lending Library">lending library</a>. '
'Please <a href="%(base_url)s/ia/%(item_id)s/borrow" title="Borrow '
'book page on Open Library">visit this book\'s page on Open Library'
'</a> to access the book. You must have cookies enabled for '
'archive.org and openlibrary.org to access borrowed books.'
% resolution_dict
)

Expand Down

0 comments on commit 2770050

Please sign in to comment.