Skip to content

Commit b57adc0

Browse files
author
Scott Barnes
committed
BookWorm: allow imports via BookWorm again
This commit reenables `/isbn` on both BookWorm and by extension openlibrary.org. Note: this changes the signature of `vendors.AmazonAPI()` to add a `proxy_url` parameter for passing in an HTTP Proxy URL.
1 parent 16fb67e commit b57adc0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

openlibrary/core/vendors.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
def setup(config):
4545
global affiliate_server_url
4646
affiliate_server_url = config.get('affiliate_server')
47-
global http_proxy_url
48-
http_proxy_url = config.get('http_proxy')
4947

5048

5149
def get_lexile(isbn):
@@ -93,12 +91,13 @@ def __init__(
9391
host: str = 'webservices.amazon.com',
9492
region: str = 'us-east-1',
9593
throttling: float = 0.9,
94+
proxy_url: str = "",
9695
) -> None:
9796
"""
9897
Creates an instance containing your API credentials.
9998
100-
Instantiating this object in a REPL requires the `infogami._setup()`
101-
magic incantation to set `http_proxy_url`.
99+
Instantiating this class requires a `proxy_url` parameter as of January
100+
10th, 2025 because `ol-home0` has no direct internet access.
102101
103102
:param str key: affiliate key
104103
:param str secret: affiliate secret
@@ -116,10 +115,11 @@ def __init__(
116115
)
117116

118117
# Replace the api object with one that supports the HTTP proxy. See #10310.
119-
configuration = Configuration()
120-
configuration.proxy = http_proxy_url
121-
rest_client = RESTClientObject(configuration=configuration)
122-
self.api.api_client.rest_client = rest_client
118+
if proxy_url:
119+
configuration = Configuration()
120+
configuration.proxy = http_proxy_url
121+
rest_client = RESTClientObject(configuration=configuration)
122+
self.api.api_client.rest_client = rest_client
123123

124124
def search(self, keywords):
125125
"""Adding method to test amz searches from the CLI, unused otherwise"""

scripts/affiliate_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ def GET(self, identifier: str) -> str:
689689
def load_config(configfile):
690690
# This loads openlibrary.yml + infobase.yml
691691
openlibrary_load_config(configfile)
692+
http_proxy_url = config.get('http_proxy')
692693

693694
stats.client = stats.create_stats_client(cfg=config)
694695

@@ -699,7 +700,7 @@ def load_config(configfile):
699700
config.amazon_api.get('id'),
700701
]
701702
if all(args):
702-
web.amazon_api = AmazonAPI(*args, throttling=0.9)
703+
web.amazon_api = AmazonAPI(*args, throttling=0.9, proxy_url=http_proxy_url)
703704
logger.info("AmazonAPI Initialized")
704705
else:
705706
raise RuntimeError(f"{configfile} is missing required keys.")

0 commit comments

Comments
 (0)