|
| 1 | +from datetime import datetime |
1 | 2 | from typing import Dict, List, Literal, Optional, Union |
2 | 3 | from uuid import UUID |
3 | 4 |
|
|
6 | 7 | from asknews_sdk.dto.news import ( |
7 | 8 | ArticleResponse, |
8 | 9 | GraphResponse, |
| 10 | + IndexCountsResponse, |
9 | 11 | RedditResponse, |
10 | 12 | SearchResponse, |
11 | 13 | SourceReportResponse, |
@@ -230,6 +232,87 @@ def search_news( |
230 | 232 | ) |
231 | 233 | return SearchResponse.model_validate(response.content) |
232 | 234 |
|
| 235 | + def get_index_counts( |
| 236 | + self, |
| 237 | + start_datetime: datetime, |
| 238 | + end_datetime: datetime, |
| 239 | + sampling: Literal["5m", "1h", "12h", "1d", "1w", "1m"] = "1d", |
| 240 | + time_filter: Literal["crawl_date", "pub_date"] = "pub_date", |
| 241 | + categories: Optional[ |
| 242 | + List[ |
| 243 | + Literal[ |
| 244 | + "All", |
| 245 | + "Business", |
| 246 | + "Crime", |
| 247 | + "Politics", |
| 248 | + "Science", |
| 249 | + "Sports", |
| 250 | + "Technology", |
| 251 | + "Military", |
| 252 | + "Health", |
| 253 | + "Entertainment", |
| 254 | + "Finance", |
| 255 | + "Culture", |
| 256 | + "Climate", |
| 257 | + "Environment", |
| 258 | + "World", |
| 259 | + ] |
| 260 | + ] |
| 261 | + ] = None, |
| 262 | + provocative: Optional[str] = "all", |
| 263 | + reporting_voice: Optional[Union[List[str], str]] = None, |
| 264 | + domains: Optional[Union[List[str], str]] = None, |
| 265 | + bad_domain_url: Optional[Union[List[str], str]] = None, |
| 266 | + page_rank: Optional[int] = None, |
| 267 | + string_guarantee: Optional[List[str]] = None, |
| 268 | + string_guarantee_op: Optional[str] = "OR", |
| 269 | + reverse_string_guarantee: Optional[List[str]] = None, |
| 270 | + entity_guarantee: Optional[List[str]] = None, |
| 271 | + entity_guarantee_op: Optional[str] = "OR", |
| 272 | + return_graphs: Optional[bool] = False, |
| 273 | + return_geo: Optional[bool] = False, |
| 274 | + countries: Optional[List[str]] = None, |
| 275 | + countries_blacklist: Optional[List[str]] = None, |
| 276 | + languages: Optional[List[str]] = None, |
| 277 | + continents: Optional[List[str]] = None, |
| 278 | + sentiment: Optional[Literal["negative", "neutral", "positive"]] = None, |
| 279 | + *, |
| 280 | + http_headers: Optional[Dict] = None, |
| 281 | + ) -> SearchResponse: |
| 282 | + """ """ |
| 283 | + response = self.client.request( |
| 284 | + method="GET", |
| 285 | + endpoint="/v1/news/index_counts", |
| 286 | + query={ |
| 287 | + "start_datetime": start_datetime, |
| 288 | + "end_datetime": end_datetime, |
| 289 | + "time_filter": time_filter, |
| 290 | + "categories": categories if categories is not None else ["All"], |
| 291 | + "provocative": provocative, |
| 292 | + "reporting_voice": reporting_voice, |
| 293 | + "sampling": sampling, |
| 294 | + "domains": domains, |
| 295 | + "bad_domain_url": bad_domain_url, |
| 296 | + "page_rank": page_rank, |
| 297 | + "string_guarantee": string_guarantee, |
| 298 | + "string_guarantee_op": string_guarantee_op, |
| 299 | + "reverse_string_guarantee": reverse_string_guarantee, |
| 300 | + "entity_guarantee": entity_guarantee, |
| 301 | + "entity_guarantee_op": entity_guarantee_op, |
| 302 | + "return_graphs": return_graphs, |
| 303 | + "return_geo": return_geo, |
| 304 | + "countries": countries, |
| 305 | + "countries_blacklist": countries_blacklist, |
| 306 | + "languages": languages, |
| 307 | + "continents": continents, |
| 308 | + "sentiment": sentiment, |
| 309 | + "premium": True, |
| 310 | + }, |
| 311 | + headers=http_headers, |
| 312 | + accept=[(IndexCountsResponse.__content_type__, 1.0)], |
| 313 | + ) |
| 314 | + return IndexCountsResponse.model_validate(response.content) |
| 315 | + |
233 | 316 | def get_sources_report( |
234 | 317 | self, |
235 | 318 | n_points: int = 100, |
@@ -558,6 +641,87 @@ async def search_news( |
558 | 641 | ) |
559 | 642 | return SearchResponse.model_validate(response.content) |
560 | 643 |
|
| 644 | + async def get_index_counts( |
| 645 | + self, |
| 646 | + start_datetime: datetime, |
| 647 | + end_datetime: datetime, |
| 648 | + time_filter: Literal["crawl_date", "pub_date"] = "pub_date", |
| 649 | + categories: Optional[ |
| 650 | + List[ |
| 651 | + Literal[ |
| 652 | + "All", |
| 653 | + "Business", |
| 654 | + "Crime", |
| 655 | + "Politics", |
| 656 | + "Science", |
| 657 | + "Sports", |
| 658 | + "Technology", |
| 659 | + "Military", |
| 660 | + "Health", |
| 661 | + "Entertainment", |
| 662 | + "Finance", |
| 663 | + "Culture", |
| 664 | + "Climate", |
| 665 | + "Environment", |
| 666 | + "World", |
| 667 | + ] |
| 668 | + ] |
| 669 | + ] = None, |
| 670 | + sampling: Literal["5m", "1h", "12h", "1d", "1w", "1m"] = "1d", |
| 671 | + provocative: Optional[str] = "all", |
| 672 | + reporting_voice: Optional[Union[List[str], str]] = None, |
| 673 | + domains: Optional[Union[List[str], str]] = None, |
| 674 | + bad_domain_url: Optional[Union[List[str], str]] = None, |
| 675 | + page_rank: Optional[int] = None, |
| 676 | + string_guarantee: Optional[List[str]] = None, |
| 677 | + string_guarantee_op: Optional[str] = "OR", |
| 678 | + reverse_string_guarantee: Optional[List[str]] = None, |
| 679 | + entity_guarantee: Optional[List[str]] = None, |
| 680 | + entity_guarantee_op: Optional[str] = "OR", |
| 681 | + return_graphs: Optional[bool] = False, |
| 682 | + return_geo: Optional[bool] = False, |
| 683 | + countries: Optional[List[str]] = None, |
| 684 | + countries_blacklist: Optional[List[str]] = None, |
| 685 | + languages: Optional[List[str]] = None, |
| 686 | + continents: Optional[List[str]] = None, |
| 687 | + sentiment: Optional[Literal["negative", "neutral", "positive"]] = None, |
| 688 | + *, |
| 689 | + http_headers: Optional[Dict] = None, |
| 690 | + ) -> SearchResponse: |
| 691 | + """ """ |
| 692 | + response = await self.client.request( |
| 693 | + method="GET", |
| 694 | + endpoint="/v1/news/index_counts", |
| 695 | + query={ |
| 696 | + "sampling": sampling, |
| 697 | + "start_datetime": start_datetime, |
| 698 | + "end_datetime": end_datetime, |
| 699 | + "time_filter": time_filter, |
| 700 | + "categories": categories if categories is not None else ["All"], |
| 701 | + "provocative": provocative, |
| 702 | + "reporting_voice": reporting_voice, |
| 703 | + "domains": domains, |
| 704 | + "bad_domain_url": bad_domain_url, |
| 705 | + "page_rank": page_rank, |
| 706 | + "string_guarantee": string_guarantee, |
| 707 | + "string_guarantee_op": string_guarantee_op, |
| 708 | + "reverse_string_guarantee": reverse_string_guarantee, |
| 709 | + "entity_guarantee": entity_guarantee, |
| 710 | + "entity_guarantee_op": entity_guarantee_op, |
| 711 | + "return_graphs": return_graphs, |
| 712 | + "return_geo": return_geo, |
| 713 | + "countries": countries, |
| 714 | + "countries_blacklist": countries_blacklist, |
| 715 | + "languages": languages, |
| 716 | + "continents": continents, |
| 717 | + "sentiment": sentiment, |
| 718 | + "premium": True, |
| 719 | + }, |
| 720 | + headers=http_headers, |
| 721 | + accept=[(IndexCountsResponse.__content_type__, 1.0)], |
| 722 | + ) |
| 723 | + return IndexCountsResponse.model_validate(response.content) |
| 724 | + |
561 | 725 | async def get_sources_report( |
562 | 726 | self, |
563 | 727 | n_points: int = 100, |
|
0 commit comments