Skip to content

Commit

Permalink
Strip "/api" when parsing local API links
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Dec 25, 2024
1 parent 48ee630 commit 7aefee6
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/pyzotero/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@
import zipfile
from collections import OrderedDict
from functools import wraps
from pathlib import Path
from urllib.parse import parse_qs, parse_qsl, quote, urlencode, urlparse, urlunparse
from pathlib import Path, PurePosixPath
from urllib.parse import (
parse_qs,
parse_qsl,
quote,
unquote,
urlencode,
urlparse,
urlunparse,
)

import bibtexparser
import feedparser
Expand Down Expand Up @@ -272,8 +280,10 @@ def __init__(
"""Store Zotero credentials"""
if not local:
self.endpoint = "https://api.zotero.org"
self.local = False
else:
self.endpoint = "http://localhost:23119/api"
self.local = True
if library_id and library_type:
self.library_id = library_id
# library_type determines whether query begins w. /users or /groups
Expand Down Expand Up @@ -321,6 +331,15 @@ def __init__(
self.backoff = False
self.backoff_duration = 0.0

def _striplocal(self, url):
if self.local:
parsed = urlparse(url)
purepath = PurePosixPath(unquote(parsed.path))
newpath = "/".join(purepath.parts[2:])
replaced = parsed._replace(path="/" + newpath)
return urlunparse(replaced)
return url

def _set_backoff(self, duration):
"""
Set a backoff
Expand Down Expand Up @@ -845,10 +864,10 @@ def all_top(self, **kwargs):
@retrieve
def follow(self):
"""Return the result of the call to the URL in the 'Next' link"""
if self.links.get("next"):
return self.links.get("next")
else:
return
if n := self.links.get("next"):
newurl = self._striplocal(n)
return newurl
return

def iterfollow(self):
"""Generator for self.follow()"""
Expand Down

0 comments on commit 7aefee6

Please sign in to comment.