From ed15360ad055943387b2ed95c50f9593fec23326 Mon Sep 17 00:00:00 2001 From: Roman Kalyakin Date: Fri, 27 Dec 2024 19:22:09 +0800 Subject: [PATCH] regenerated types and api accessors, replaced newspapers with media_sources and updated references. changed documentation style to match the rest of the project. --- docs/resources.md | 12 +- .../{newspapers.ipynb => media_sources.ipynb} | 55 ++++--- .../{newspapers => media_sources}/__init__.py | 0 .../find_media_sources.py} | 89 ++++++++---- .../get_media_source.py} | 34 ++--- impresso/api_client/models/__init__.py | 22 ++- ... find_media_sources_base_find_response.py} | 28 ++-- ..._sources_base_find_response_pagination.py} | 8 +- ...r_by.py => find_media_sources_order_by.py} | 22 +-- .../models/find_media_sources_type.py | 12 ++ impresso/api_client/models/media_source.py | 136 ++++++++++++++++++ .../models/media_source_properties_item.py | 54 +++++++ .../api_client/models/media_source_totals.py | 56 ++++++++ .../api_client/models/media_source_type.py | 12 ++ impresso/api_models.py | 62 ++++++++ impresso/client_base.py | 6 +- .../{newspapers.py => media_sources.py} | 60 +++++--- mkdocs.yml | 2 +- 18 files changed, 531 insertions(+), 139 deletions(-) rename examples/notebooks/{newspapers.ipynb => media_sources.ipynb} (69%) rename impresso/api_client/api/{newspapers => media_sources}/__init__.py (100%) rename impresso/api_client/api/{newspapers/find_newspapers.py => media_sources/find_media_sources.py} (63%) rename impresso/api_client/api/{newspapers/get_newspaper.py => media_sources/get_media_source.py} (84%) rename impresso/api_client/models/{find_newspapers_base_find_response.py => find_media_sources_base_find_response.py} (50%) rename impresso/api_client/models/{find_newspapers_base_find_response_pagination.py => find_media_sources_base_find_response_pagination.py} (81%) rename impresso/api_client/models/{find_newspapers_order_by.py => find_media_sources_order_by.py} (50%) create mode 100644 impresso/api_client/models/find_media_sources_type.py create mode 100644 impresso/api_client/models/media_source.py create mode 100644 impresso/api_client/models/media_source_properties_item.py create mode 100644 impresso/api_client/models/media_source_totals.py create mode 100644 impresso/api_client/models/media_source_type.py rename impresso/resources/{newspapers.py => media_sources.py} (51%) diff --git a/docs/resources.md b/docs/resources.md index df60048..037bb22 100644 --- a/docs/resources.md +++ b/docs/resources.md @@ -26,21 +26,21 @@ impresso.entities.find(term="Douglas Adams") ::: impresso.resources.entities.EntityType ::: impresso.api_client.models.find_entities_order_by.FindEntitiesOrderByLiteral -## Newspapers +## Media sources -Search newspapers available in the Impresso corpus. +Search media sources available in the Impresso corpus. ```python -impresso.newspapers.find( +impresso.media_sources.find( term="wort", order_by="lastIssue", ) ``` -::: impresso.resources.newspapers.NewspapersResource +::: impresso.resources.media_sources.MediaSourcesResource -::: impresso.api_client.models.find_newspapers_order_by.FindNewspapersOrderByLiteral -::: impresso.resources.newspapers.FindNewspapersContainer +::: impresso.api_client.models.find_media_sources_order_by.FindMediaSourcesOrderByLiteral +::: impresso.resources.media_sources.FindMediaSourcesContainer ## Content Items diff --git a/examples/notebooks/newspapers.ipynb b/examples/notebooks/media_sources.ipynb similarity index 69% rename from examples/notebooks/newspapers.ipynb rename to examples/notebooks/media_sources.ipynb index 1f44ef4..7811162 100644 --- a/examples/notebooks/newspapers.ipynb +++ b/examples/notebooks/media_sources.ipynb @@ -10,7 +10,7 @@ "output_type": "stream", "text": [ "🎉 You are now connected to the Impresso API! 🎉\n", - "🔗 Using API: https://dev.impresso-project.ch/public-api\n" + "🔗 Using API: http://localhost:3030\n" ] } ], @@ -24,14 +24,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Search newspapers\n", + "# Search media sources\n", "\n", "Find newspapers having the term 'wort' in their name." ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -39,7 +39,7 @@ "text/html": [ "
\n", "
\n", - "

FindNewspapers result

\n", + "

FindMediaSources result

\n", "
Contains 2 items of 2 total items.
\n", "
\n", "See this result in the Impresso App.\n", @@ -64,13 +64,15 @@ " \n", " \n", " \n", - " title\n", - " startYear\n", - " endYear\n", + " type\n", + " name\n", " languageCodes\n", - " totalArticles\n", - " totalIssues\n", - " totalPages\n", + " publishedPeriodYears\n", + " availableDatesRange\n", + " properties\n", + " totals.articles\n", + " totals.issues\n", + " totals.pages\n", " \n", " \n", " uid\n", @@ -81,45 +83,52 @@ " \n", " \n", " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", " landwortbild\n", + " newspaper\n", " Luxemburger Land in Wort und Bild\n", - " 1895\n", - " 1895\n", - " [de, fr]\n", - " 755\n", + " [fr, de]\n", + " [1895, 1895]\n", + " [1895-04-07T00:00:00+00:00, 1895-12-29T00:00:0...\n", + " []\n", + " 735\n", " 39\n", " 314\n", " \n", " \n", " luxwort\n", + " newspaper\n", " Luxemburger Wort\n", - " 1848\n", - " 1950\n", - " [de, fr, lb]\n", - " 1160333\n", - " 30355\n", - " 101320\n", + " [fr, de, lb]\n", + " [1848, 1950]\n", + " [1848-03-23T00:00:00+00:00, 1950-12-30T00:00:0...\n", + " []\n", + " 1113163\n", + " 30372\n", + " 161216\n", " \n", " \n", "\n", "
" ], "text/plain": [ - "" + "" ] }, - "execution_count": 2, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "result = impresso.newspapers.find(\n", + "result = impresso.media_sources.find(\n", " term=\"wort\",\n", + " type=\"newspaper\",\n", " order_by=\"lastIssue\",\n", ")\n", "result" diff --git a/impresso/api_client/api/newspapers/__init__.py b/impresso/api_client/api/media_sources/__init__.py similarity index 100% rename from impresso/api_client/api/newspapers/__init__.py rename to impresso/api_client/api/media_sources/__init__.py diff --git a/impresso/api_client/api/newspapers/find_newspapers.py b/impresso/api_client/api/media_sources/find_media_sources.py similarity index 63% rename from impresso/api_client/api/newspapers/find_newspapers.py rename to impresso/api_client/api/media_sources/find_media_sources.py index 3a22c2e..f32570b 100644 --- a/impresso/api_client/api/newspapers/find_newspapers.py +++ b/impresso/api_client/api/media_sources/find_media_sources.py @@ -6,15 +6,18 @@ from ... import errors from ...client import AuthenticatedClient, Client from ...models.error import Error -from ...models.find_newspapers_base_find_response import FindNewspapersBaseFindResponse -from ...models.find_newspapers_order_by import FindNewspapersOrderBy +from ...models.find_media_sources_base_find_response import FindMediaSourcesBaseFindResponse +from ...models.find_media_sources_order_by import FindMediaSourcesOrderBy +from ...models.find_media_sources_type import FindMediaSourcesType from ...types import UNSET, Response, Unset def _get_kwargs( *, term: Union[Unset, str] = UNSET, - order_by: Union[Unset, FindNewspapersOrderBy] = UNSET, + type: Union[Unset, FindMediaSourcesType] = UNSET, + order_by: Union[Unset, FindMediaSourcesOrderBy] = UNSET, + include_properties: Union[Unset, bool] = False, limit: Union[Unset, int] = UNSET, offset: Union[Unset, int] = UNSET, ) -> Dict[str, Any]: @@ -22,12 +25,20 @@ def _get_kwargs( params["term"] = term + json_type: Union[Unset, str] = UNSET + if not isinstance(type, Unset): + json_type = type.value + + params["type"] = json_type + json_order_by: Union[Unset, str] = UNSET if not isinstance(order_by, Unset): json_order_by = order_by.value params["order_by"] = json_order_by + params["include_properties"] = include_properties + params["limit"] = limit params["offset"] = offset @@ -36,7 +47,7 @@ def _get_kwargs( _kwargs: Dict[str, Any] = { "method": "get", - "url": "/newspapers", + "url": "/media-sources", "params": params, } @@ -45,9 +56,9 @@ def _get_kwargs( def _parse_response( *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Error, FindNewspapersBaseFindResponse]]: +) -> Optional[Union[Error, FindMediaSourcesBaseFindResponse]]: if response.status_code == HTTPStatus.OK: - response_200 = FindNewspapersBaseFindResponse.from_dict(response.json()) + response_200 = FindMediaSourcesBaseFindResponse.from_dict(response.json()) return response_200 if response.status_code == HTTPStatus.UNAUTHORIZED: @@ -82,7 +93,7 @@ def _parse_response( def _build_response( *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Error, FindNewspapersBaseFindResponse]]: +) -> Response[Union[Error, FindMediaSourcesBaseFindResponse]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -95,15 +106,19 @@ def sync_detailed( *, client: AuthenticatedClient, term: Union[Unset, str] = UNSET, - order_by: Union[Unset, FindNewspapersOrderBy] = UNSET, + type: Union[Unset, FindMediaSourcesType] = UNSET, + order_by: Union[Unset, FindMediaSourcesOrderBy] = UNSET, + include_properties: Union[Unset, bool] = False, limit: Union[Unset, int] = UNSET, offset: Union[Unset, int] = UNSET, -) -> Response[Union[Error, FindNewspapersBaseFindResponse]]: - """Find newspapers that match the given query +) -> Response[Union[Error, FindMediaSourcesBaseFindResponse]]: + """Find media sources Args: term (Union[Unset, str]): - order_by (Union[Unset, FindNewspapersOrderBy]): + type (Union[Unset, FindMediaSourcesType]): + order_by (Union[Unset, FindMediaSourcesOrderBy]): + include_properties (Union[Unset, bool]): Default: False. limit (Union[Unset, int]): offset (Union[Unset, int]): @@ -112,12 +127,14 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Error, FindNewspapersBaseFindResponse]] + Response[Union[Error, FindMediaSourcesBaseFindResponse]] """ kwargs = _get_kwargs( term=term, + type=type, order_by=order_by, + include_properties=include_properties, limit=limit, offset=offset, ) @@ -133,15 +150,19 @@ def sync( *, client: AuthenticatedClient, term: Union[Unset, str] = UNSET, - order_by: Union[Unset, FindNewspapersOrderBy] = UNSET, + type: Union[Unset, FindMediaSourcesType] = UNSET, + order_by: Union[Unset, FindMediaSourcesOrderBy] = UNSET, + include_properties: Union[Unset, bool] = False, limit: Union[Unset, int] = UNSET, offset: Union[Unset, int] = UNSET, -) -> Optional[Union[Error, FindNewspapersBaseFindResponse]]: - """Find newspapers that match the given query +) -> Optional[Union[Error, FindMediaSourcesBaseFindResponse]]: + """Find media sources Args: term (Union[Unset, str]): - order_by (Union[Unset, FindNewspapersOrderBy]): + type (Union[Unset, FindMediaSourcesType]): + order_by (Union[Unset, FindMediaSourcesOrderBy]): + include_properties (Union[Unset, bool]): Default: False. limit (Union[Unset, int]): offset (Union[Unset, int]): @@ -150,13 +171,15 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Error, FindNewspapersBaseFindResponse] + Union[Error, FindMediaSourcesBaseFindResponse] """ return sync_detailed( client=client, term=term, + type=type, order_by=order_by, + include_properties=include_properties, limit=limit, offset=offset, ).parsed @@ -166,15 +189,19 @@ async def asyncio_detailed( *, client: AuthenticatedClient, term: Union[Unset, str] = UNSET, - order_by: Union[Unset, FindNewspapersOrderBy] = UNSET, + type: Union[Unset, FindMediaSourcesType] = UNSET, + order_by: Union[Unset, FindMediaSourcesOrderBy] = UNSET, + include_properties: Union[Unset, bool] = False, limit: Union[Unset, int] = UNSET, offset: Union[Unset, int] = UNSET, -) -> Response[Union[Error, FindNewspapersBaseFindResponse]]: - """Find newspapers that match the given query +) -> Response[Union[Error, FindMediaSourcesBaseFindResponse]]: + """Find media sources Args: term (Union[Unset, str]): - order_by (Union[Unset, FindNewspapersOrderBy]): + type (Union[Unset, FindMediaSourcesType]): + order_by (Union[Unset, FindMediaSourcesOrderBy]): + include_properties (Union[Unset, bool]): Default: False. limit (Union[Unset, int]): offset (Union[Unset, int]): @@ -183,12 +210,14 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Error, FindNewspapersBaseFindResponse]] + Response[Union[Error, FindMediaSourcesBaseFindResponse]] """ kwargs = _get_kwargs( term=term, + type=type, order_by=order_by, + include_properties=include_properties, limit=limit, offset=offset, ) @@ -202,15 +231,19 @@ async def asyncio( *, client: AuthenticatedClient, term: Union[Unset, str] = UNSET, - order_by: Union[Unset, FindNewspapersOrderBy] = UNSET, + type: Union[Unset, FindMediaSourcesType] = UNSET, + order_by: Union[Unset, FindMediaSourcesOrderBy] = UNSET, + include_properties: Union[Unset, bool] = False, limit: Union[Unset, int] = UNSET, offset: Union[Unset, int] = UNSET, -) -> Optional[Union[Error, FindNewspapersBaseFindResponse]]: - """Find newspapers that match the given query +) -> Optional[Union[Error, FindMediaSourcesBaseFindResponse]]: + """Find media sources Args: term (Union[Unset, str]): - order_by (Union[Unset, FindNewspapersOrderBy]): + type (Union[Unset, FindMediaSourcesType]): + order_by (Union[Unset, FindMediaSourcesOrderBy]): + include_properties (Union[Unset, bool]): Default: False. limit (Union[Unset, int]): offset (Union[Unset, int]): @@ -219,14 +252,16 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Error, FindNewspapersBaseFindResponse] + Union[Error, FindMediaSourcesBaseFindResponse] """ return ( await asyncio_detailed( client=client, term=term, + type=type, order_by=order_by, + include_properties=include_properties, limit=limit, offset=offset, ) diff --git a/impresso/api_client/api/newspapers/get_newspaper.py b/impresso/api_client/api/media_sources/get_media_source.py similarity index 84% rename from impresso/api_client/api/newspapers/get_newspaper.py rename to impresso/api_client/api/media_sources/get_media_source.py index 4ac1fe9..415c64e 100644 --- a/impresso/api_client/api/newspapers/get_newspaper.py +++ b/impresso/api_client/api/media_sources/get_media_source.py @@ -6,7 +6,7 @@ from ... import errors from ...client import AuthenticatedClient, Client from ...models.error import Error -from ...models.newspaper import Newspaper +from ...models.media_source import MediaSource from ...types import Response @@ -15,7 +15,7 @@ def _get_kwargs( ) -> Dict[str, Any]: _kwargs: Dict[str, Any] = { "method": "get", - "url": f"/newspapers/{id}", + "url": f"/media-sources/{id}", } return _kwargs @@ -23,9 +23,9 @@ def _get_kwargs( def _parse_response( *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Error, Newspaper]]: +) -> Optional[Union[Error, MediaSource]]: if response.status_code == HTTPStatus.OK: - response_200 = Newspaper.from_dict(response.json()) + response_200 = MediaSource.from_dict(response.json()) return response_200 if response.status_code == HTTPStatus.UNAUTHORIZED: @@ -60,7 +60,7 @@ def _parse_response( def _build_response( *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Error, Newspaper]]: +) -> Response[Union[Error, MediaSource]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -73,8 +73,8 @@ def sync_detailed( id: str, *, client: AuthenticatedClient, -) -> Response[Union[Error, Newspaper]]: - """Get a newspaper by ID +) -> Response[Union[Error, MediaSource]]: + """Get media source by ID Args: id (str): @@ -84,7 +84,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Error, Newspaper]] + Response[Union[Error, MediaSource]] """ kwargs = _get_kwargs( @@ -102,8 +102,8 @@ def sync( id: str, *, client: AuthenticatedClient, -) -> Optional[Union[Error, Newspaper]]: - """Get a newspaper by ID +) -> Optional[Union[Error, MediaSource]]: + """Get media source by ID Args: id (str): @@ -113,7 +113,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Error, Newspaper] + Union[Error, MediaSource] """ return sync_detailed( @@ -126,8 +126,8 @@ async def asyncio_detailed( id: str, *, client: AuthenticatedClient, -) -> Response[Union[Error, Newspaper]]: - """Get a newspaper by ID +) -> Response[Union[Error, MediaSource]]: + """Get media source by ID Args: id (str): @@ -137,7 +137,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Error, Newspaper]] + Response[Union[Error, MediaSource]] """ kwargs = _get_kwargs( @@ -153,8 +153,8 @@ async def asyncio( id: str, *, client: AuthenticatedClient, -) -> Optional[Union[Error, Newspaper]]: - """Get a newspaper by ID +) -> Optional[Union[Error, MediaSource]]: + """Get media source by ID Args: id (str): @@ -164,7 +164,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Error, Newspaper] + Union[Error, MediaSource] """ return ( diff --git a/impresso/api_client/models/__init__.py b/impresso/api_client/models/__init__.py index c4a9cae..bc9de4a 100644 --- a/impresso/api_client/models/__init__.py +++ b/impresso/api_client/models/__init__.py @@ -27,9 +27,10 @@ from .find_entities_base_find_response import FindEntitiesBaseFindResponse from .find_entities_base_find_response_pagination import FindEntitiesBaseFindResponsePagination from .find_entities_order_by import FindEntitiesOrderBy -from .find_newspapers_base_find_response import FindNewspapersBaseFindResponse -from .find_newspapers_base_find_response_pagination import FindNewspapersBaseFindResponsePagination -from .find_newspapers_order_by import FindNewspapersOrderBy +from .find_media_sources_base_find_response import FindMediaSourcesBaseFindResponse +from .find_media_sources_base_find_response_pagination import FindMediaSourcesBaseFindResponsePagination +from .find_media_sources_order_by import FindMediaSourcesOrderBy +from .find_media_sources_type import FindMediaSourcesType from .find_text_reuse_clusters_base_find_response import FindTextReuseClustersBaseFindResponse from .find_text_reuse_clusters_base_find_response_pagination import FindTextReuseClustersBaseFindResponsePagination from .find_text_reuse_clusters_order_by import FindTextReuseClustersOrderBy @@ -56,6 +57,10 @@ from .impresso_named_entity_recognition_request import ImpressoNamedEntityRecognitionRequest from .impresso_named_entity_recognition_request_method import ImpressoNamedEntityRecognitionRequestMethod from .impresso_named_entity_recognition_response import ImpressoNamedEntityRecognitionResponse +from .media_source import MediaSource +from .media_source_properties_item import MediaSourcePropertiesItem +from .media_source_totals import MediaSourceTotals +from .media_source_type import MediaSourceType from .new_collection_request import NewCollectionRequest from .new_collection_request_access_level import NewCollectionRequestAccessLevel from .newspaper import Newspaper @@ -112,9 +117,10 @@ "FindEntitiesBaseFindResponse", "FindEntitiesBaseFindResponsePagination", "FindEntitiesOrderBy", - "FindNewspapersBaseFindResponse", - "FindNewspapersBaseFindResponsePagination", - "FindNewspapersOrderBy", + "FindMediaSourcesBaseFindResponse", + "FindMediaSourcesBaseFindResponsePagination", + "FindMediaSourcesOrderBy", + "FindMediaSourcesType", "FindTextReuseClustersBaseFindResponse", "FindTextReuseClustersBaseFindResponsePagination", "FindTextReuseClustersOrderBy", @@ -141,6 +147,10 @@ "ImpressoNamedEntityRecognitionRequest", "ImpressoNamedEntityRecognitionRequestMethod", "ImpressoNamedEntityRecognitionResponse", + "MediaSource", + "MediaSourcePropertiesItem", + "MediaSourceTotals", + "MediaSourceType", "NewCollectionRequest", "NewCollectionRequestAccessLevel", "Newspaper", diff --git a/impresso/api_client/models/find_newspapers_base_find_response.py b/impresso/api_client/models/find_media_sources_base_find_response.py similarity index 50% rename from impresso/api_client/models/find_newspapers_base_find_response.py rename to impresso/api_client/models/find_media_sources_base_find_response.py index bcd0adc..1dc9f78 100644 --- a/impresso/api_client/models/find_newspapers_base_find_response.py +++ b/impresso/api_client/models/find_media_sources_base_find_response.py @@ -3,23 +3,23 @@ from attrs import define as _attrs_define if TYPE_CHECKING: - from ..models.find_newspapers_base_find_response_pagination import FindNewspapersBaseFindResponsePagination - from ..models.newspaper import Newspaper + from ..models.find_media_sources_base_find_response_pagination import FindMediaSourcesBaseFindResponsePagination + from ..models.media_source import MediaSource -T = TypeVar("T", bound="FindNewspapersBaseFindResponse") +T = TypeVar("T", bound="FindMediaSourcesBaseFindResponse") @_attrs_define -class FindNewspapersBaseFindResponse: +class FindMediaSourcesBaseFindResponse: """ Attributes: - data (List['Newspaper']): - pagination (FindNewspapersBaseFindResponsePagination): + data (List['MediaSource']): + pagination (FindMediaSourcesBaseFindResponsePagination): """ - data: List["Newspaper"] - pagination: "FindNewspapersBaseFindResponsePagination" + data: List["MediaSource"] + pagination: "FindMediaSourcesBaseFindResponsePagination" def to_dict(self) -> Dict[str, Any]: data = [] @@ -41,22 +41,22 @@ def to_dict(self) -> Dict[str, Any]: @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.find_newspapers_base_find_response_pagination import FindNewspapersBaseFindResponsePagination - from ..models.newspaper import Newspaper + from ..models.find_media_sources_base_find_response_pagination import FindMediaSourcesBaseFindResponsePagination + from ..models.media_source import MediaSource d = src_dict.copy() data = [] _data = d.pop("data") for data_item_data in _data: - data_item = Newspaper.from_dict(data_item_data) + data_item = MediaSource.from_dict(data_item_data) data.append(data_item) - pagination = FindNewspapersBaseFindResponsePagination.from_dict(d.pop("pagination")) + pagination = FindMediaSourcesBaseFindResponsePagination.from_dict(d.pop("pagination")) - find_newspapers_base_find_response = cls( + find_media_sources_base_find_response = cls( data=data, pagination=pagination, ) - return find_newspapers_base_find_response + return find_media_sources_base_find_response diff --git a/impresso/api_client/models/find_newspapers_base_find_response_pagination.py b/impresso/api_client/models/find_media_sources_base_find_response_pagination.py similarity index 81% rename from impresso/api_client/models/find_newspapers_base_find_response_pagination.py rename to impresso/api_client/models/find_media_sources_base_find_response_pagination.py index 63a7283..c686502 100644 --- a/impresso/api_client/models/find_newspapers_base_find_response_pagination.py +++ b/impresso/api_client/models/find_media_sources_base_find_response_pagination.py @@ -2,11 +2,11 @@ from attrs import define as _attrs_define -T = TypeVar("T", bound="FindNewspapersBaseFindResponsePagination") +T = TypeVar("T", bound="FindMediaSourcesBaseFindResponsePagination") @_attrs_define -class FindNewspapersBaseFindResponsePagination: +class FindMediaSourcesBaseFindResponsePagination: """ Attributes: total (int): The total number of items matching the query @@ -45,10 +45,10 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: offset = d.pop("offset") - find_newspapers_base_find_response_pagination = cls( + find_media_sources_base_find_response_pagination = cls( total=total, limit=limit, offset=offset, ) - return find_newspapers_base_find_response_pagination + return find_media_sources_base_find_response_pagination diff --git a/impresso/api_client/models/find_newspapers_order_by.py b/impresso/api_client/models/find_media_sources_order_by.py similarity index 50% rename from impresso/api_client/models/find_newspapers_order_by.py rename to impresso/api_client/models/find_media_sources_order_by.py index fa13b95..3393772 100644 --- a/impresso/api_client/models/find_newspapers_order_by.py +++ b/impresso/api_client/models/find_media_sources_order_by.py @@ -2,35 +2,27 @@ from typing import Literal -class FindNewspapersOrderBy(str, Enum): +class FindMediaSourcesOrderBy(str, Enum): COUNTISSUES = "countIssues" - ENDYEAR = "endYear" FIRSTISSUE = "firstIssue" LASTISSUE = "lastIssue" NAME = "name" - STARTYEAR = "startYear" - VALUE_0 = "-name" - VALUE_11 = "-countIssues" - VALUE_2 = "-startYear" - VALUE_4 = "-endYear" - VALUE_7 = "-firstIssue" - VALUE_9 = "-lastIssue" + VALUE_1 = "-name" + VALUE_3 = "-firstIssue" + VALUE_5 = "-lastIssue" + VALUE_7 = "-countIssues" def __str__(self) -> str: return str(self.value) -FindNewspapersOrderByLiteral = Literal[ +FindMediaSourcesOrderByLiteral = Literal[ "countIssues", - "endYear", "firstIssue", "lastIssue", "name", - "startYear", "-name", - "-countIssues", - "-startYear", - "-endYear", "-firstIssue", "-lastIssue", + "-countIssues", ] diff --git a/impresso/api_client/models/find_media_sources_type.py b/impresso/api_client/models/find_media_sources_type.py new file mode 100644 index 0000000..4e7a878 --- /dev/null +++ b/impresso/api_client/models/find_media_sources_type.py @@ -0,0 +1,12 @@ +from enum import Enum +from typing import Literal + + +class FindMediaSourcesType(str, Enum): + NEWSPAPER = "newspaper" + + def __str__(self) -> str: + return str(self.value) + + +FindMediaSourcesTypeLiteral = Literal["newspaper",] diff --git a/impresso/api_client/models/media_source.py b/impresso/api_client/models/media_source.py new file mode 100644 index 0000000..f664d99 --- /dev/null +++ b/impresso/api_client/models/media_source.py @@ -0,0 +1,136 @@ +import datetime +from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast + +from attrs import define as _attrs_define +from dateutil.parser import isoparse + +from ..models.media_source_type import MediaSourceType +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.media_source_properties_item import MediaSourcePropertiesItem + from ..models.media_source_totals import MediaSourceTotals + + +T = TypeVar("T", bound="MediaSource") + + +@_attrs_define +class MediaSource: + """A media source is what a content item belongs to. This can be a newspaper, a TV or a radio station, etc. + + Attributes: + uid (str): The unique identifier of the media source. + type (MediaSourceType): The type of the media source. + name (str): A display name of the media source. + language_codes (List[str]): ISO 639-2 language codes this media source has content in. + totals (MediaSourceTotals): + published_period_years (Union[Unset, List[int]]): The range of years this media source has been published for. + Impresso may not have data for all this period. Is not defined if there is no information. + available_dates_range (Union[Unset, List[datetime.datetime]]): The range of dates this media source has content + items for. This represents the earliest and the latest dates of the contet items. Is not defined if there are + no content items for this source. + properties (Union[Unset, List['MediaSourcePropertiesItem']]): + """ + + uid: str + type: MediaSourceType + name: str + language_codes: List[str] + totals: "MediaSourceTotals" + published_period_years: Union[Unset, List[int]] = UNSET + available_dates_range: Union[Unset, List[datetime.datetime]] = UNSET + properties: Union[Unset, List["MediaSourcePropertiesItem"]] = UNSET + + def to_dict(self) -> Dict[str, Any]: + uid = self.uid + + type = self.type.value + + name = self.name + + language_codes = self.language_codes + + totals = self.totals.to_dict() + + published_period_years: Union[Unset, List[int]] = UNSET + if not isinstance(self.published_period_years, Unset): + published_period_years = self.published_period_years + + available_dates_range: Union[Unset, List[str]] = UNSET + if not isinstance(self.available_dates_range, Unset): + available_dates_range = [] + for available_dates_range_item_data in self.available_dates_range: + available_dates_range_item = available_dates_range_item_data.isoformat() + available_dates_range.append(available_dates_range_item) + + properties: Union[Unset, List[Dict[str, Any]]] = UNSET + if not isinstance(self.properties, Unset): + properties = [] + for properties_item_data in self.properties: + properties_item = properties_item_data.to_dict() + properties.append(properties_item) + + field_dict: Dict[str, Any] = {} + field_dict.update( + { + "uid": uid, + "type": type, + "name": name, + "languageCodes": language_codes, + "totals": totals, + } + ) + if published_period_years is not UNSET: + field_dict["publishedPeriodYears"] = published_period_years + if available_dates_range is not UNSET: + field_dict["availableDatesRange"] = available_dates_range + if properties is not UNSET: + field_dict["properties"] = properties + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + from ..models.media_source_properties_item import MediaSourcePropertiesItem + from ..models.media_source_totals import MediaSourceTotals + + d = src_dict.copy() + uid = d.pop("uid") + + type = MediaSourceType(d.pop("type")) + + name = d.pop("name") + + language_codes = cast(List[str], d.pop("languageCodes")) + + totals = MediaSourceTotals.from_dict(d.pop("totals")) + + published_period_years = cast(List[int], d.pop("publishedPeriodYears", UNSET)) + + available_dates_range = [] + _available_dates_range = d.pop("availableDatesRange", UNSET) + for available_dates_range_item_data in _available_dates_range or []: + available_dates_range_item = isoparse(available_dates_range_item_data) + + available_dates_range.append(available_dates_range_item) + + properties = [] + _properties = d.pop("properties", UNSET) + for properties_item_data in _properties or []: + properties_item = MediaSourcePropertiesItem.from_dict(properties_item_data) + + properties.append(properties_item) + + media_source = cls( + uid=uid, + type=type, + name=name, + language_codes=language_codes, + totals=totals, + published_period_years=published_period_years, + available_dates_range=available_dates_range, + properties=properties, + ) + + return media_source diff --git a/impresso/api_client/models/media_source_properties_item.py b/impresso/api_client/models/media_source_properties_item.py new file mode 100644 index 0000000..ed41903 --- /dev/null +++ b/impresso/api_client/models/media_source_properties_item.py @@ -0,0 +1,54 @@ +from typing import Any, Dict, Type, TypeVar + +from attrs import define as _attrs_define + +T = TypeVar("T", bound="MediaSourcePropertiesItem") + + +@_attrs_define +class MediaSourcePropertiesItem: + """ + Attributes: + id (str): The unique identifier of the property. + label (str): The name of the property. + value (str): The value of the property. + """ + + id: str + label: str + value: str + + def to_dict(self) -> Dict[str, Any]: + id = self.id + + label = self.label + + value = self.value + + field_dict: Dict[str, Any] = {} + field_dict.update( + { + "id": id, + "label": label, + "value": value, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + id = d.pop("id") + + label = d.pop("label") + + value = d.pop("value") + + media_source_properties_item = cls( + id=id, + label=label, + value=value, + ) + + return media_source_properties_item diff --git a/impresso/api_client/models/media_source_totals.py b/impresso/api_client/models/media_source_totals.py new file mode 100644 index 0000000..71bc388 --- /dev/null +++ b/impresso/api_client/models/media_source_totals.py @@ -0,0 +1,56 @@ +from typing import Any, Dict, Type, TypeVar, Union + +from attrs import define as _attrs_define + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="MediaSourceTotals") + + +@_attrs_define +class MediaSourceTotals: + """ + Attributes: + articles (Union[Unset, int]): The number of articles in the media source. + issues (Union[Unset, int]): The number of issues in the media source. + pages (Union[Unset, int]): The number of pages in the media source. + """ + + articles: Union[Unset, int] = UNSET + issues: Union[Unset, int] = UNSET + pages: Union[Unset, int] = UNSET + + def to_dict(self) -> Dict[str, Any]: + articles = self.articles + + issues = self.issues + + pages = self.pages + + field_dict: Dict[str, Any] = {} + field_dict.update({}) + if articles is not UNSET: + field_dict["articles"] = articles + if issues is not UNSET: + field_dict["issues"] = issues + if pages is not UNSET: + field_dict["pages"] = pages + + return field_dict + + @classmethod + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + d = src_dict.copy() + articles = d.pop("articles", UNSET) + + issues = d.pop("issues", UNSET) + + pages = d.pop("pages", UNSET) + + media_source_totals = cls( + articles=articles, + issues=issues, + pages=pages, + ) + + return media_source_totals diff --git a/impresso/api_client/models/media_source_type.py b/impresso/api_client/models/media_source_type.py new file mode 100644 index 0000000..f7a9219 --- /dev/null +++ b/impresso/api_client/models/media_source_type.py @@ -0,0 +1,12 @@ +from enum import Enum +from typing import Literal + + +class MediaSourceType(str, Enum): + NEWSPAPER = "newspaper" + + def __str__(self) -> str: + return str(self.value) + + +MediaSourceTypeLiteral = Literal["newspaper",] diff --git a/impresso/api_models.py b/impresso/api_models.py index 3f56def..0591317 100644 --- a/impresso/api_models.py +++ b/impresso/api_models.py @@ -382,6 +382,68 @@ class EntityMention(BaseModel): ] +class Totals(BaseModel): + model_config = ConfigDict( + extra='forbid', + ) + articles: Annotated[ + Optional[int], + Field(None, description='The number of articles in the media source.'), + ] + issues: Annotated[ + Optional[int], + Field(None, description='The number of issues in the media source.'), + ] + pages: Annotated[ + Optional[int], + Field(None, description='The number of pages in the media source.'), + ] + + +class Property(BaseModel): + model_config = ConfigDict( + extra='forbid', + ) + id: Annotated[str, Field(description='The unique identifier of the property.')] + label: Annotated[str, Field(description='The name of the property.')] + value: Annotated[str, Field(description='The value of the property.')] + + +class MediaSource(BaseModel): + model_config = ConfigDict( + extra='forbid', + ) + uid: Annotated[str, Field(description='The unique identifier of the media source.')] + type: Annotated[ + Literal['newspaper'], Field(description='The type of the media source.') + ] + name: Annotated[str, Field(description='A display name of the media source.')] + languageCodes: Annotated[ + Sequence[str], + Field(description='ISO 639-2 language codes this media source has content in.'), + ] + publishedPeriodYears: Annotated[ + Optional[Sequence[int]], + Field( + None, + description='The range of years this media source has been published for. Impresso may not have data for all this period. Is not defined if there is no information.', + max_length=2, + min_length=2, + ), + ] + availableDatesRange: Annotated[ + Optional[Sequence[AwareDatetime]], + Field( + None, + description='The range of dates this media source has content items for. This represents the earliest and the latest dates of the contet items. Is not defined if there are no content items for this source.', + max_length=2, + min_length=2, + ), + ] + totals: Totals + properties: Optional[Sequence[Property]] = None + + class Newspaper(BaseModel): model_config = ConfigDict( extra='forbid', diff --git a/impresso/client_base.py b/impresso/client_base.py index d84e2a0..ac70e5e 100644 --- a/impresso/client_base.py +++ b/impresso/client_base.py @@ -2,7 +2,7 @@ from impresso.resources.content_items import ContentItemsResource from impresso.resources.collections import CollectionsResource from impresso.resources.entities import EntitiesResource -from impresso.resources.newspapers import NewspapersResource +from impresso.resources.media_sources import MediaSourcesResource from impresso.resources.search import SearchResource from impresso.resources.text_reuse import TextReuseDomain from impresso.resources.tools import ToolsResource @@ -27,8 +27,8 @@ def text_reuse(self) -> TextReuseDomain: return TextReuseDomain(self._api_client) @property - def newspapers(self) -> NewspapersResource: - return NewspapersResource(self._api_client) + def media_sources(self) -> MediaSourcesResource: + return MediaSourcesResource(self._api_client) @property def collections(self) -> CollectionsResource: diff --git a/impresso/resources/newspapers.py b/impresso/resources/media_sources.py similarity index 51% rename from impresso/resources/newspapers.py rename to impresso/resources/media_sources.py index 1e1a123..4fa91ab 100644 --- a/impresso/resources/newspapers.py +++ b/impresso/resources/media_sources.py @@ -1,25 +1,29 @@ from pandas import DataFrame, json_normalize -from impresso.api_client.api.newspapers import find_newspapers -from impresso.api_client.models.find_newspapers_order_by import ( - FindNewspapersOrderBy, - FindNewspapersOrderByLiteral, +from impresso.api_client.api.media_sources import find_media_sources +from impresso.api_client.models.find_media_sources_order_by import ( + FindMediaSourcesOrderBy, + FindMediaSourcesOrderByLiteral, +) +from impresso.api_client.models.find_media_sources_type import ( + FindMediaSourcesType, + FindMediaSourcesTypeLiteral, ) from impresso.api_client.types import UNSET -from impresso.api_models import BaseFind, Newspaper +from impresso.api_models import BaseFind, MediaSource from impresso.data_container import DataContainer from impresso.resources.base import Resource from impresso.util.error import raise_for_error from impresso.util.py import get_enum_from_literal -class FindNewspapersSchema(BaseFind): - """Schema for the find newspapers response.""" +class FindMediaSourcesSchema(BaseFind): + """Schema for the find media sources response.""" - data: list[Newspaper] + data: list[MediaSource] -class FindNewspapersContainer(DataContainer): +class FindMediaSourcesContainer(DataContainer): """Response of a search call.""" @property @@ -31,46 +35,56 @@ def df(self) -> DataFrame: return DataFrame() -class NewspapersResource(Resource): - """Search newspapers in the Impresso database.""" +class MediaSourcesResource(Resource): + """Search media sources in the Impresso database.""" - name = "newspapers" + name = "media_sources" def find( self, term: str | None = None, - order_by: FindNewspapersOrderByLiteral | None = None, + type: FindMediaSourcesTypeLiteral | None = None, + order_by: FindMediaSourcesOrderByLiteral | None = None, + with_properties: bool = False, limit: int | None = None, offset: int | None = None, - ) -> FindNewspapersContainer: + ) -> FindMediaSourcesContainer: """ - Search newspapers in Impresso. + Search media sources in Impresso. Args: term: Search term. + type: Type of media sources to search for. order_by: Field to order results by. + with_properties: Include properties in the results. limit: Number of results to return. offset: Number of results to skip. Returns: - FindNewspapersContainer: Data container with a page of results of the search. + FindMediaSourcesContainer: Data container with a page of results of the search. """ - result = find_newspapers.sync( + result = find_media_sources.sync( client=self._api_client, term=term if term is not None else UNSET, order_by=( - get_enum_from_literal(order_by, FindNewspapersOrderBy) + get_enum_from_literal(order_by, FindMediaSourcesOrderBy) if order_by is not None else UNSET ), + type=( + get_enum_from_literal(type, FindMediaSourcesType) + if type is not None + else UNSET + ), + include_properties=with_properties, limit=limit if limit is not None else UNSET, offset=offset if offset is not None else UNSET, ) raise_for_error(result) - return FindNewspapersContainer( + return FindMediaSourcesContainer( result, - FindNewspapersSchema, - web_app_search_result_url=_build_web_app_newspapers_url( + FindMediaSourcesSchema, + web_app_search_result_url=_build_web_app_media_sources_url( base_url=self._get_web_app_base_url(), term=term, order_by=order_by, @@ -78,10 +92,10 @@ def find( ) -def _build_web_app_newspapers_url( +def _build_web_app_media_sources_url( base_url: str, term: str | None = None, - order_by: FindNewspapersOrderByLiteral | None = None, + order_by: FindMediaSourcesOrderByLiteral | None = None, ) -> str: query_params = { "orderBy": order_by, diff --git a/mkdocs.yml b/mkdocs.yml index 6456e2c..afd8bb5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,7 +1,7 @@ site_name: "Impresso" theme: - name: "material" + name: "readthedocs" plugins: - search