Skip to content

Commit

Permalink
Fix staging result content
Browse files Browse the repository at this point in the history
  • Loading branch information
janheinrichmerker committed Jan 11, 2023
1 parent b4d6aef commit 6e62a5d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ from chatnoir_api import cache_contents, Index, ShortUUID
contents = cache_contents(
ShortUUID("6svePe3PXteDeGPk1XqTLA"),
Index.ClueWeb22,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)
print(contents)

plain_contents = cache_contents(
ShortUUID("6svePe3PXteDeGPk1XqTLA"),
Index.ClueWeb22,
plain=True,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)
print(plain_contents)
```
Expand Down
5 changes: 3 additions & 2 deletions chatnoir_api/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

from requests import get, Response

from chatnoir_api.constants import BASE_URL
from chatnoir_api.constants import BASE_URL, BASE_URL_STAGING
from chatnoir_api.model import Index


def cache_contents(
uuid_or_document_id: Union[UUID, str],
index: Index,
plain: bool = False,
base_url: str = BASE_URL,
staging: bool = False,
) -> str:
uuid: UUID
if isinstance(uuid_or_document_id, str):
uuid = uuid5(NAMESPACE_URL, f"{index.prefix}:{uuid_or_document_id}")
else:
uuid = uuid_or_document_id

base_url = BASE_URL_STAGING if staging else BASE_URL
response: Response = get(
urljoin(base_url, "cache"),
params={
Expand Down
2 changes: 1 addition & 1 deletion chatnoir_api/model/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MinimalResultStaging(MinimalResult, ABC):
title: HighlightedText

def cache_contents(self, plain: bool = False) -> str:
return cache_contents(self.uuid, self.index, plain)
return cache_contents(self.uuid, self.index, plain, staging=True)


class ExplainedMinimalResultStaging(
Expand Down
4 changes: 2 additions & 2 deletions examples/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
contents = cache_contents(
ShortUUID("MzOlTIayX9ub7c13GLPr_g"),
Index.ClueWeb22,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)
print(contents)

plain_contents = cache_contents(
ShortUUID("MzOlTIayX9ub7c13GLPr_g"),
Index.ClueWeb22,
plain=True,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)
print(plain_contents)
4 changes: 2 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_html_contents_short_uuid():
contents = cache_contents(
ShortUUID("f6J0lMPmVfWs19jJNQkHKA"),
Index.ClueWeb22,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)

assert contents is not None
Expand All @@ -67,7 +67,7 @@ def test_html_contents_plain_short_uuid():
ShortUUID("f6J0lMPmVfWs19jJNQkHKA"),
Index.ClueWeb22,
plain=True,
base_url="https://chatnoir.web.webis.de/"
staging=True,
)

assert contents is not None
Expand Down

0 comments on commit 6e62a5d

Please sign in to comment.