Skip to content

Commit

Permalink
Don't set locale if a link url already contains it
Browse files Browse the repository at this point in the history
My terrible logic was polluting the URLs with an additional locale query parameter for each call when using e.g. everything()
  • Loading branch information
urschrei committed Dec 25, 2024
1 parent 7aefee6 commit 32e9954
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/pyzotero/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ def __init__(
self.backoff = False
self.backoff_duration = 0.0

def _check_for_component(self, url, component):
"""Check a url path query fragment for a specific query parameter"""
if parse_qs(url).get(component):
return True
return False

def _striplocal(self, url):
if self.local:
parsed = urlparse(url)
Expand Down Expand Up @@ -425,10 +431,15 @@ def _retrieve_data(self, request=None, params=None):
self.self_link = request
# ensure that we wait if there's an active backoff
self._check_backoff()
if params:
params["locale"] = self.locale
if not params:
params = {"locale": self.locale}
# don't set locale if the url already contains it
if params and self.links:
if not self._check_for_component(self.links.get("next"), "locale"):
params["locale"] = self.locale
if not params and self.links:
if not self._check_for_component(self.links.get("next"), "locale"):
params = {"locale": self.locale}
else:
params = {}
self.request = requests.get(
url=full_url, headers=self.default_headers(), params=params
)
Expand Down

0 comments on commit 32e9954

Please sign in to comment.