Skip to content

Commit 1429ad9

Browse files
committed
過去のアノテーション仕様を参照
1 parent 0e7c671 commit 1429ad9

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

annofabapi/api.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import json
33
import logging
4+
import warnings
45
from typing import Any, Callable, Dict, List, Optional, Tuple, Union # pylint: disable=unused-import
56

67
import backoff
@@ -177,6 +178,26 @@ def _request_wrapper(self, http_method: str, url_path: str, query_params: Option
177178
content = self._response_to_content(response)
178179
return content, response
179180

181+
def _get_signed_cookie(self, project_id):
182+
"""
183+
アノテーション仕様の履歴情報を取得するために、非公開APIにアクセスする。
184+
変更される可能性あり.
185+
186+
.. deprecated:: X
187+
188+
Args:
189+
project_id: プロジェクトID
190+
191+
Returns:
192+
Tuple[Content, Reponse)
193+
194+
"""
195+
warnings.warn("deprecated", DeprecationWarning)
196+
url_path = f'/private/projects/{project_id}/sign-headers'
197+
http_method = 'GET'
198+
keyword_params: Dict[str, Any] = {}
199+
return self._request_wrapper(http_method, url_path, **keyword_params)
200+
180201
#########################################
181202
# Public Method : Login
182203
#########################################

annofabapi/wrapper.py

+16
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,22 @@ def get_all_annotation_list(self, project_id: str,
154154
#########################################
155155
# Public Method : AfAnnotationSpecsApi
156156
#########################################
157+
def get_annotation_specs_from_url(self, project_id: str, url: str) -> AnnotationSpecs:
158+
"""
159+
アノテーション仕様の履歴から取得したURLから、アノテーション仕様を取得する
160+
161+
Args:
162+
project_id: プロジェクトID
163+
url: アノテーション仕様の履歴から取得したURL
164+
165+
Returns:
166+
put_annotation_specsのContent
167+
"""
168+
cookies, _ = self.api._get_signed_cookie(project_id)
169+
kwargs = self.api._create_kwargs()
170+
kwargs.update({"cookies": cookies})
171+
return requests.get(url, **kwargs).json()
172+
157173
def copy_annotation_specs(self, src_project_id: str, dest_project_id: str,
158174
comment: Optional[str] = None) -> AnnotationSpecs:
159175
"""

tests/test_api.py

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def test_annotation_specs():
129129
annotation_specs_histories = api.get_annotation_specs_histories(project_id)[0]
130130
assert type(annotation_specs_histories) == list
131131

132+
old_annotation_specs_url = annotation_specs_histories[0]["url"]
133+
old_annotation_specs = wrapper.get_annotation_specs_from_url(project_id, old_annotation_specs_url)
134+
assert type(old_annotation_specs) == dict
135+
132136

133137
def test_login():
134138
print(f"login")

0 commit comments

Comments
 (0)