Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
1131 lines (882 loc) · 45.7 KB
/
Copy pathclient.py
File metadata and controls
1131 lines (882 loc) · 45.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file was auto-generated by Fern from our API Definition.
import typing
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.aggregation_by import AggregationBy
from ..types.all_domain_links import AllDomainLinks
from ..types.all_links import AllLinks
from ..types.all_links_text import AllLinksText
from ..types.by_parse_date import ByParseDate
from ..types.content_sentiment_max import ContentSentimentMax
from ..types.content_sentiment_min import ContentSentimentMin
from ..types.countries import Countries
from ..types.from_ import From
from ..types.from_rank import FromRank
from ..types.has_nlp import HasNlp
from ..types.include_nlp_data import IncludeNlpData
from ..types.iptc_tags import IptcTags
from ..types.is_headline import IsHeadline
from ..types.is_opinion import IsOpinion
from ..types.is_paid_content import IsPaidContent
from ..types.lang import Lang
from ..types.loc_entity_name import LocEntityName
from ..types.misc_entity_name import MiscEntityName
from ..types.not_author_name import NotAuthorName
from ..types.not_countries import NotCountries
from ..types.not_iptc_tags import NotIptcTags
from ..types.not_lang import NotLang
from ..types.not_sources import NotSources
from ..types.not_theme import NotTheme
from ..types.org_entity_name import OrgEntityName
from ..types.page import Page
from ..types.page_size import PageSize
from ..types.parent_url import ParentUrl
from ..types.per_entity_name import PerEntityName
from ..types.predefined_sources import PredefinedSources
from ..types.published_date_precision import PublishedDatePrecision
from ..types.q import Q
from ..types.ranked_only import RankedOnly
from ..types.robots_compliant import RobotsCompliant
from ..types.search_in import SearchIn
from ..types.sort_by import SortBy
from ..types.sources import Sources
from ..types.theme import Theme
from ..types.title_sentiment_max import TitleSentimentMax
from ..types.title_sentiment_min import TitleSentimentMin
from ..types.to import To
from ..types.to_rank import ToRank
from ..types.word_count_max import WordCountMax
from ..types.word_count_min import WordCountMin
from .raw_client import AsyncRawAggregationCountClient, RawAggregationCountClient
from .types.get_aggregation_count_response import GetAggregationCountResponse
from .types.post_aggregation_count_response import PostAggregationCountResponse
# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)
class AggregationCountClient:
def __init__(self, *, client_wrapper: SyncClientWrapper):
self._raw_client = RawAggregationCountClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> RawAggregationCountClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
RawAggregationCountClient
"""
return self._raw_client
def get(
self,
*,
q: Q,
aggregation_by: typing.Optional[AggregationBy] = None,
search_in: typing.Optional[SearchIn] = None,
predefined_sources: typing.Optional[str] = None,
sources: typing.Optional[str] = None,
not_sources: typing.Optional[str] = None,
lang: typing.Optional[str] = None,
not_lang: typing.Optional[str] = None,
countries: typing.Optional[str] = None,
not_countries: typing.Optional[str] = None,
not_author_name: typing.Optional[str] = None,
from_: typing.Optional[From] = None,
to: typing.Optional[To] = None,
published_date_precision: typing.Optional[PublishedDatePrecision] = None,
by_parse_date: typing.Optional[ByParseDate] = None,
sort_by: typing.Optional[SortBy] = None,
ranked_only: typing.Optional[RankedOnly] = None,
from_rank: typing.Optional[FromRank] = None,
to_rank: typing.Optional[ToRank] = None,
is_headline: typing.Optional[IsHeadline] = None,
is_opinion: typing.Optional[IsOpinion] = None,
is_paid_content: typing.Optional[IsPaidContent] = None,
parent_url: typing.Optional[str] = None,
all_links: typing.Optional[str] = None,
all_domain_links: typing.Optional[str] = None,
all_links_text: typing.Optional[str] = None,
word_count_min: typing.Optional[WordCountMin] = None,
word_count_max: typing.Optional[WordCountMax] = None,
page: typing.Optional[Page] = None,
page_size: typing.Optional[PageSize] = None,
include_nlp_data: typing.Optional[IncludeNlpData] = None,
has_nlp: typing.Optional[HasNlp] = None,
theme: typing.Optional[Theme] = None,
not_theme: typing.Optional[NotTheme] = None,
org_entity_name: typing.Optional[OrgEntityName] = None,
per_entity_name: typing.Optional[PerEntityName] = None,
loc_entity_name: typing.Optional[LocEntityName] = None,
misc_entity_name: typing.Optional[MiscEntityName] = None,
title_sentiment_min: typing.Optional[TitleSentimentMin] = None,
title_sentiment_max: typing.Optional[TitleSentimentMax] = None,
content_sentiment_min: typing.Optional[ContentSentimentMin] = None,
content_sentiment_max: typing.Optional[ContentSentimentMax] = None,
iptc_tags: typing.Optional[str] = None,
not_iptc_tags: typing.Optional[str] = None,
robots_compliant: typing.Optional[RobotsCompliant] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetAggregationCountResponse:
"""
Retrieves the count of articles aggregated by day or hour based on various search criteria, such as keyword, language, country, and source.
Parameters
----------
q : Q
aggregation_by : typing.Optional[AggregationBy]
search_in : typing.Optional[SearchIn]
predefined_sources : typing.Optional[str]
Predefined top news sources per country.
Format: start with the word `top`, followed by the number of desired sources, and then the two-letter country code [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
Multiple countries with the number of top sources can be specified as a comma-separated string.
sources : typing.Optional[str]
One or more news sources to narrow down the search. The format must be a domain URL. Subdomains, such as `finance.yahoo.com`, are also acceptable.To specify multiple sources, use a comma-separated string.
not_sources : typing.Optional[str]
The news sources to exclude from the search. To exclude multiple sources, use a comma-separated string.
lang : typing.Optional[str]
The language(s) of the search. The only accepted format is the two-letter [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code. To select multiple languages, use a comma-separated string.
To learn more, see [Enumerated parameters > Language](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#language-lang-and-not-lang).
not_lang : typing.Optional[str]
The language(s) to exclude from the search. The accepted format is the two-letter [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code. To exclude multiple languages, use a comma-separated string.
To learn more, see [Enumerated parameters > Language](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#language-lang-and-not-lang).
countries : typing.Optional[str]
The countries where the news publisher is located. The accepted format is the two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code. To select multiple countries, use a comma-separated string.
To learn more, see [Enumerated parameters > Country](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#country-country-and-not-country).
not_countries : typing.Optional[str]
The publisher location countries to exclude from the search. The accepted format is the two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code. To exclude multiple countries, use a comma-separated string.
To learn more, see [Enumerated parameters > Country](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#country-country-and-not-country).
not_author_name : typing.Optional[str]
The list of author names to exclude from your search. To exclude articles by specific authors, use a comma-separated string.
from_ : typing.Optional[From]
to : typing.Optional[To]
published_date_precision : typing.Optional[PublishedDatePrecision]
by_parse_date : typing.Optional[ByParseDate]
sort_by : typing.Optional[SortBy]
ranked_only : typing.Optional[RankedOnly]
from_rank : typing.Optional[FromRank]
to_rank : typing.Optional[ToRank]
is_headline : typing.Optional[IsHeadline]
is_opinion : typing.Optional[IsOpinion]
is_paid_content : typing.Optional[IsPaidContent]
parent_url : typing.Optional[str]
The categorical URL(s) to filter your search. To filter your search by multiple categorical URLs, use a comma-separated string.
all_links : typing.Optional[str]
The complete URL(s) mentioned in the article. For multiple URLs, use a comma-separated string.
For more details, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
all_domain_links : typing.Optional[str]
The domain(s) mentioned in the article. For multiple domains, use a comma-separated string.
For more details, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
all_links_text : typing.Optional[str]
The text content of links mentioned in the article. Searches for links where the anchor text contains the specified terms. For multiple terms, use a comma-separated string.
**Note**: When this parameter is used, the response includes the `all_links_data` field with detailed link information.
To learn more, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
word_count_min : typing.Optional[WordCountMin]
word_count_max : typing.Optional[WordCountMax]
page : typing.Optional[Page]
page_size : typing.Optional[PageSize]
include_nlp_data : typing.Optional[IncludeNlpData]
has_nlp : typing.Optional[HasNlp]
theme : typing.Optional[Theme]
not_theme : typing.Optional[NotTheme]
org_entity_name : typing.Optional[OrgEntityName]
per_entity_name : typing.Optional[PerEntityName]
loc_entity_name : typing.Optional[LocEntityName]
misc_entity_name : typing.Optional[MiscEntityName]
title_sentiment_min : typing.Optional[TitleSentimentMin]
title_sentiment_max : typing.Optional[TitleSentimentMax]
content_sentiment_min : typing.Optional[ContentSentimentMin]
content_sentiment_max : typing.Optional[ContentSentimentMax]
iptc_tags : typing.Optional[str]
Filters articles based on International Press Telecommunications Council (IPTC) media topic tags. To specify multiple IPTC tags, use a comma-separated string of tag IDs.
**Note**: The `iptc_tags` parameter is only available in the `v3_nlp_iptc_tags` subscription plan.
To learn more, see [IPTC Media Topic NewsCodes](https://www.iptc.org/std/NewsCodes/treeview/mediatopic/mediatopic-en-GB.html).
not_iptc_tags : typing.Optional[str]
Inverse of the `iptc_tags` parameter. Excludes articles based on International Press Telecommunications Council (IPTC) media topic tags. To specify multiple IPTC tags to exclude, use a comma-separated string of tag IDs.
**Note**: The `not_iptc_tags` parameter is only available in the `v3_nlp_iptc_tags` subscription plan.
To learn more, see [IPTC Media Topic NewsCodes](https://www.iptc.org/std/NewsCodes/treeview/mediatopic/mediatopic-en-GB.html).
robots_compliant : typing.Optional[RobotsCompliant]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetAggregationCountResponse
A successful response containing aggregation count results that match the search criteria. If no matches, returns a failed aggregation response according to the defined schema.
Examples
--------
from newscatcher import NewscatcherApi
client = NewscatcherApi(
api_key="YOUR_API_KEY",
)
client.aggregation_count.get(
q='"supply chain" AND Amazon NOT China',
search_in="title_content, title_content_translated",
predefined_sources="top 50 US, top 20 GB",
sources="nytimes.com,finance.yahoo.com",
not_sources="cnn.com,wsj.com",
lang="en,es",
not_lang="fr,de",
countries="US,CA",
not_countries="UK,FR",
not_author_name="John Doe, Jane Doe",
from_="1 day ago",
to="now",
published_date_precision="full",
by_parse_date=True,
ranked_only=True,
from_rank=100,
to_rank=100,
is_headline=True,
is_opinion=True,
is_paid_content=False,
parent_url="wsj.com/politics,wsj.com/tech",
all_links="https://aiindex.stanford.edu/report,https://www.stateof.ai",
all_domain_links="who.int,nih.gov",
all_links_text="Nvidia,Tesla",
word_count_min=300,
word_count_max=1000,
page=2,
page_size=50,
include_nlp_data=True,
has_nlp=True,
theme="Finance,Tech",
not_theme="Crime,Sports",
org_entity_name='"Apple Inc" OR Microsoft',
per_entity_name='"Elon Musk" OR "Jeff Bezos"',
loc_entity_name='"San Francisco" OR "New York City"',
misc_entity_name='AWS OR "Microsoft Azure"',
title_sentiment_min=-0.5,
title_sentiment_max=0.5,
content_sentiment_min=-0.5,
content_sentiment_max=0.5,
iptc_tags="20000199,20000209",
not_iptc_tags="20000205,20000209",
robots_compliant=True,
)
"""
_response = self._raw_client.get(
q=q,
aggregation_by=aggregation_by,
search_in=search_in,
predefined_sources=predefined_sources,
sources=sources,
not_sources=not_sources,
lang=lang,
not_lang=not_lang,
countries=countries,
not_countries=not_countries,
not_author_name=not_author_name,
from_=from_,
to=to,
published_date_precision=published_date_precision,
by_parse_date=by_parse_date,
sort_by=sort_by,
ranked_only=ranked_only,
from_rank=from_rank,
to_rank=to_rank,
is_headline=is_headline,
is_opinion=is_opinion,
is_paid_content=is_paid_content,
parent_url=parent_url,
all_links=all_links,
all_domain_links=all_domain_links,
all_links_text=all_links_text,
word_count_min=word_count_min,
word_count_max=word_count_max,
page=page,
page_size=page_size,
include_nlp_data=include_nlp_data,
has_nlp=has_nlp,
theme=theme,
not_theme=not_theme,
org_entity_name=org_entity_name,
per_entity_name=per_entity_name,
loc_entity_name=loc_entity_name,
misc_entity_name=misc_entity_name,
title_sentiment_min=title_sentiment_min,
title_sentiment_max=title_sentiment_max,
content_sentiment_min=content_sentiment_min,
content_sentiment_max=content_sentiment_max,
iptc_tags=iptc_tags,
not_iptc_tags=not_iptc_tags,
robots_compliant=robots_compliant,
request_options=request_options,
)
return _response.data
def post(
self,
*,
q: Q,
aggregation_by: typing.Optional[AggregationBy] = OMIT,
search_in: typing.Optional[SearchIn] = OMIT,
predefined_sources: typing.Optional[PredefinedSources] = OMIT,
sources: typing.Optional[Sources] = OMIT,
not_sources: typing.Optional[NotSources] = OMIT,
lang: typing.Optional[Lang] = OMIT,
not_lang: typing.Optional[NotLang] = OMIT,
countries: typing.Optional[Countries] = OMIT,
not_countries: typing.Optional[NotCountries] = OMIT,
not_author_name: typing.Optional[NotAuthorName] = OMIT,
from_: typing.Optional[From] = OMIT,
to: typing.Optional[To] = OMIT,
published_date_precision: typing.Optional[PublishedDatePrecision] = OMIT,
by_parse_date: typing.Optional[ByParseDate] = OMIT,
sort_by: typing.Optional[SortBy] = OMIT,
ranked_only: typing.Optional[RankedOnly] = OMIT,
from_rank: typing.Optional[FromRank] = OMIT,
to_rank: typing.Optional[ToRank] = OMIT,
is_headline: typing.Optional[IsHeadline] = OMIT,
is_opinion: typing.Optional[IsOpinion] = OMIT,
is_paid_content: typing.Optional[IsPaidContent] = OMIT,
parent_url: typing.Optional[ParentUrl] = OMIT,
all_links: typing.Optional[AllLinks] = OMIT,
all_domain_links: typing.Optional[AllDomainLinks] = OMIT,
all_links_text: typing.Optional[AllLinksText] = OMIT,
word_count_min: typing.Optional[WordCountMin] = OMIT,
word_count_max: typing.Optional[WordCountMax] = OMIT,
page: typing.Optional[Page] = OMIT,
page_size: typing.Optional[PageSize] = OMIT,
include_nlp_data: typing.Optional[IncludeNlpData] = OMIT,
has_nlp: typing.Optional[HasNlp] = OMIT,
theme: typing.Optional[Theme] = OMIT,
not_theme: typing.Optional[NotTheme] = OMIT,
org_entity_name: typing.Optional[OrgEntityName] = OMIT,
per_entity_name: typing.Optional[PerEntityName] = OMIT,
loc_entity_name: typing.Optional[LocEntityName] = OMIT,
misc_entity_name: typing.Optional[MiscEntityName] = OMIT,
title_sentiment_min: typing.Optional[TitleSentimentMin] = OMIT,
title_sentiment_max: typing.Optional[TitleSentimentMax] = OMIT,
content_sentiment_min: typing.Optional[ContentSentimentMin] = OMIT,
content_sentiment_max: typing.Optional[ContentSentimentMax] = OMIT,
iptc_tags: typing.Optional[IptcTags] = OMIT,
not_iptc_tags: typing.Optional[NotIptcTags] = OMIT,
robots_compliant: typing.Optional[RobotsCompliant] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> PostAggregationCountResponse:
"""
Retrieves the count of articles aggregated by day or hour based on various search criteria, such as keyword, language, country, and source.
Parameters
----------
q : Q
aggregation_by : typing.Optional[AggregationBy]
search_in : typing.Optional[SearchIn]
predefined_sources : typing.Optional[PredefinedSources]
sources : typing.Optional[Sources]
not_sources : typing.Optional[NotSources]
lang : typing.Optional[Lang]
not_lang : typing.Optional[NotLang]
countries : typing.Optional[Countries]
not_countries : typing.Optional[NotCountries]
not_author_name : typing.Optional[NotAuthorName]
from_ : typing.Optional[From]
to : typing.Optional[To]
published_date_precision : typing.Optional[PublishedDatePrecision]
by_parse_date : typing.Optional[ByParseDate]
sort_by : typing.Optional[SortBy]
ranked_only : typing.Optional[RankedOnly]
from_rank : typing.Optional[FromRank]
to_rank : typing.Optional[ToRank]
is_headline : typing.Optional[IsHeadline]
is_opinion : typing.Optional[IsOpinion]
is_paid_content : typing.Optional[IsPaidContent]
parent_url : typing.Optional[ParentUrl]
all_links : typing.Optional[AllLinks]
all_domain_links : typing.Optional[AllDomainLinks]
all_links_text : typing.Optional[AllLinksText]
word_count_min : typing.Optional[WordCountMin]
word_count_max : typing.Optional[WordCountMax]
page : typing.Optional[Page]
page_size : typing.Optional[PageSize]
include_nlp_data : typing.Optional[IncludeNlpData]
has_nlp : typing.Optional[HasNlp]
theme : typing.Optional[Theme]
not_theme : typing.Optional[NotTheme]
org_entity_name : typing.Optional[OrgEntityName]
per_entity_name : typing.Optional[PerEntityName]
loc_entity_name : typing.Optional[LocEntityName]
misc_entity_name : typing.Optional[MiscEntityName]
title_sentiment_min : typing.Optional[TitleSentimentMin]
title_sentiment_max : typing.Optional[TitleSentimentMax]
content_sentiment_min : typing.Optional[ContentSentimentMin]
content_sentiment_max : typing.Optional[ContentSentimentMax]
iptc_tags : typing.Optional[IptcTags]
not_iptc_tags : typing.Optional[NotIptcTags]
robots_compliant : typing.Optional[RobotsCompliant]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
PostAggregationCountResponse
A successful response containing aggregation count results that match the search criteria. If no matches, returns a failed aggregation response according to the defined schema.
Examples
--------
from newscatcher import NewscatcherApi
client = NewscatcherApi(
api_key="YOUR_API_KEY",
)
client.aggregation_count.post(
q='"supply chain" AND Amazon NOT China',
aggregation_by="day",
)
"""
_response = self._raw_client.post(
q=q,
aggregation_by=aggregation_by,
search_in=search_in,
predefined_sources=predefined_sources,
sources=sources,
not_sources=not_sources,
lang=lang,
not_lang=not_lang,
countries=countries,
not_countries=not_countries,
not_author_name=not_author_name,
from_=from_,
to=to,
published_date_precision=published_date_precision,
by_parse_date=by_parse_date,
sort_by=sort_by,
ranked_only=ranked_only,
from_rank=from_rank,
to_rank=to_rank,
is_headline=is_headline,
is_opinion=is_opinion,
is_paid_content=is_paid_content,
parent_url=parent_url,
all_links=all_links,
all_domain_links=all_domain_links,
all_links_text=all_links_text,
word_count_min=word_count_min,
word_count_max=word_count_max,
page=page,
page_size=page_size,
include_nlp_data=include_nlp_data,
has_nlp=has_nlp,
theme=theme,
not_theme=not_theme,
org_entity_name=org_entity_name,
per_entity_name=per_entity_name,
loc_entity_name=loc_entity_name,
misc_entity_name=misc_entity_name,
title_sentiment_min=title_sentiment_min,
title_sentiment_max=title_sentiment_max,
content_sentiment_min=content_sentiment_min,
content_sentiment_max=content_sentiment_max,
iptc_tags=iptc_tags,
not_iptc_tags=not_iptc_tags,
robots_compliant=robots_compliant,
request_options=request_options,
)
return _response.data
class AsyncAggregationCountClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper):
self._raw_client = AsyncRawAggregationCountClient(client_wrapper=client_wrapper)
@property
def with_raw_response(self) -> AsyncRawAggregationCountClient:
"""
Retrieves a raw implementation of this client that returns raw responses.
Returns
-------
AsyncRawAggregationCountClient
"""
return self._raw_client
async def get(
self,
*,
q: Q,
aggregation_by: typing.Optional[AggregationBy] = None,
search_in: typing.Optional[SearchIn] = None,
predefined_sources: typing.Optional[str] = None,
sources: typing.Optional[str] = None,
not_sources: typing.Optional[str] = None,
lang: typing.Optional[str] = None,
not_lang: typing.Optional[str] = None,
countries: typing.Optional[str] = None,
not_countries: typing.Optional[str] = None,
not_author_name: typing.Optional[str] = None,
from_: typing.Optional[From] = None,
to: typing.Optional[To] = None,
published_date_precision: typing.Optional[PublishedDatePrecision] = None,
by_parse_date: typing.Optional[ByParseDate] = None,
sort_by: typing.Optional[SortBy] = None,
ranked_only: typing.Optional[RankedOnly] = None,
from_rank: typing.Optional[FromRank] = None,
to_rank: typing.Optional[ToRank] = None,
is_headline: typing.Optional[IsHeadline] = None,
is_opinion: typing.Optional[IsOpinion] = None,
is_paid_content: typing.Optional[IsPaidContent] = None,
parent_url: typing.Optional[str] = None,
all_links: typing.Optional[str] = None,
all_domain_links: typing.Optional[str] = None,
all_links_text: typing.Optional[str] = None,
word_count_min: typing.Optional[WordCountMin] = None,
word_count_max: typing.Optional[WordCountMax] = None,
page: typing.Optional[Page] = None,
page_size: typing.Optional[PageSize] = None,
include_nlp_data: typing.Optional[IncludeNlpData] = None,
has_nlp: typing.Optional[HasNlp] = None,
theme: typing.Optional[Theme] = None,
not_theme: typing.Optional[NotTheme] = None,
org_entity_name: typing.Optional[OrgEntityName] = None,
per_entity_name: typing.Optional[PerEntityName] = None,
loc_entity_name: typing.Optional[LocEntityName] = None,
misc_entity_name: typing.Optional[MiscEntityName] = None,
title_sentiment_min: typing.Optional[TitleSentimentMin] = None,
title_sentiment_max: typing.Optional[TitleSentimentMax] = None,
content_sentiment_min: typing.Optional[ContentSentimentMin] = None,
content_sentiment_max: typing.Optional[ContentSentimentMax] = None,
iptc_tags: typing.Optional[str] = None,
not_iptc_tags: typing.Optional[str] = None,
robots_compliant: typing.Optional[RobotsCompliant] = None,
request_options: typing.Optional[RequestOptions] = None,
) -> GetAggregationCountResponse:
"""
Retrieves the count of articles aggregated by day or hour based on various search criteria, such as keyword, language, country, and source.
Parameters
----------
q : Q
aggregation_by : typing.Optional[AggregationBy]
search_in : typing.Optional[SearchIn]
predefined_sources : typing.Optional[str]
Predefined top news sources per country.
Format: start with the word `top`, followed by the number of desired sources, and then the two-letter country code [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
Multiple countries with the number of top sources can be specified as a comma-separated string.
sources : typing.Optional[str]
One or more news sources to narrow down the search. The format must be a domain URL. Subdomains, such as `finance.yahoo.com`, are also acceptable.To specify multiple sources, use a comma-separated string.
not_sources : typing.Optional[str]
The news sources to exclude from the search. To exclude multiple sources, use a comma-separated string.
lang : typing.Optional[str]
The language(s) of the search. The only accepted format is the two-letter [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code. To select multiple languages, use a comma-separated string.
To learn more, see [Enumerated parameters > Language](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#language-lang-and-not-lang).
not_lang : typing.Optional[str]
The language(s) to exclude from the search. The accepted format is the two-letter [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code. To exclude multiple languages, use a comma-separated string.
To learn more, see [Enumerated parameters > Language](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#language-lang-and-not-lang).
countries : typing.Optional[str]
The countries where the news publisher is located. The accepted format is the two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code. To select multiple countries, use a comma-separated string.
To learn more, see [Enumerated parameters > Country](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#country-country-and-not-country).
not_countries : typing.Optional[str]
The publisher location countries to exclude from the search. The accepted format is the two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code. To exclude multiple countries, use a comma-separated string.
To learn more, see [Enumerated parameters > Country](https://www.newscatcherapi.com/docs/news-api/api-reference/enumerated-parameters#country-country-and-not-country).
not_author_name : typing.Optional[str]
The list of author names to exclude from your search. To exclude articles by specific authors, use a comma-separated string.
from_ : typing.Optional[From]
to : typing.Optional[To]
published_date_precision : typing.Optional[PublishedDatePrecision]
by_parse_date : typing.Optional[ByParseDate]
sort_by : typing.Optional[SortBy]
ranked_only : typing.Optional[RankedOnly]
from_rank : typing.Optional[FromRank]
to_rank : typing.Optional[ToRank]
is_headline : typing.Optional[IsHeadline]
is_opinion : typing.Optional[IsOpinion]
is_paid_content : typing.Optional[IsPaidContent]
parent_url : typing.Optional[str]
The categorical URL(s) to filter your search. To filter your search by multiple categorical URLs, use a comma-separated string.
all_links : typing.Optional[str]
The complete URL(s) mentioned in the article. For multiple URLs, use a comma-separated string.
For more details, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
all_domain_links : typing.Optional[str]
The domain(s) mentioned in the article. For multiple domains, use a comma-separated string.
For more details, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
all_links_text : typing.Optional[str]
The text content of links mentioned in the article. Searches for links where the anchor text contains the specified terms. For multiple terms, use a comma-separated string.
**Note**: When this parameter is used, the response includes the `all_links_data` field with detailed link information.
To learn more, see [Search by URL](https://www.newscatcherapi.com/docs/news-api/how-to/search-by-url).
word_count_min : typing.Optional[WordCountMin]
word_count_max : typing.Optional[WordCountMax]
page : typing.Optional[Page]
page_size : typing.Optional[PageSize]
include_nlp_data : typing.Optional[IncludeNlpData]
has_nlp : typing.Optional[HasNlp]
theme : typing.Optional[Theme]
not_theme : typing.Optional[NotTheme]
org_entity_name : typing.Optional[OrgEntityName]
per_entity_name : typing.Optional[PerEntityName]
loc_entity_name : typing.Optional[LocEntityName]
misc_entity_name : typing.Optional[MiscEntityName]
title_sentiment_min : typing.Optional[TitleSentimentMin]
title_sentiment_max : typing.Optional[TitleSentimentMax]
content_sentiment_min : typing.Optional[ContentSentimentMin]
content_sentiment_max : typing.Optional[ContentSentimentMax]
iptc_tags : typing.Optional[str]
Filters articles based on International Press Telecommunications Council (IPTC) media topic tags. To specify multiple IPTC tags, use a comma-separated string of tag IDs.
**Note**: The `iptc_tags` parameter is only available in the `v3_nlp_iptc_tags` subscription plan.
To learn more, see [IPTC Media Topic NewsCodes](https://www.iptc.org/std/NewsCodes/treeview/mediatopic/mediatopic-en-GB.html).
not_iptc_tags : typing.Optional[str]
Inverse of the `iptc_tags` parameter. Excludes articles based on International Press Telecommunications Council (IPTC) media topic tags. To specify multiple IPTC tags to exclude, use a comma-separated string of tag IDs.
**Note**: The `not_iptc_tags` parameter is only available in the `v3_nlp_iptc_tags` subscription plan.
To learn more, see [IPTC Media Topic NewsCodes](https://www.iptc.org/std/NewsCodes/treeview/mediatopic/mediatopic-en-GB.html).
robots_compliant : typing.Optional[RobotsCompliant]
request_options : typing.Optional[RequestOptions]
Request-specific configuration.
Returns
-------
GetAggregationCountResponse
A successful response containing aggregation count results that match the search criteria. If no matches, returns a failed aggregation response according to the defined schema.
Examples
--------
import asyncio
from newscatcher import AsyncNewscatcherApi
client = AsyncNewscatcherApi(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.aggregation_count.get(
q='"supply chain" AND Amazon NOT China',
search_in="title_content, title_content_translated",
predefined_sources="top 50 US, top 20 GB",
sources="nytimes.com,finance.yahoo.com",
not_sources="cnn.com,wsj.com",
lang="en,es",
not_lang="fr,de",
countries="US,CA",
not_countries="UK,FR",
not_author_name="John Doe, Jane Doe",
from_="1 day ago",
to="now",
published_date_precision="full",
by_parse_date=True,
ranked_only=True,
from_rank=100,
to_rank=100,
is_headline=True,
is_opinion=True,
is_paid_content=False,
parent_url="wsj.com/politics,wsj.com/tech",
all_links="https://aiindex.stanford.edu/report,https://www.stateof.ai",
all_domain_links="who.int,nih.gov",
all_links_text="Nvidia,Tesla",
word_count_min=300,
word_count_max=1000,
page=2,
page_size=50,
include_nlp_data=True,
has_nlp=True,
theme="Finance,Tech",
not_theme="Crime,Sports",
org_entity_name='"Apple Inc" OR Microsoft',
per_entity_name='"Elon Musk" OR "Jeff Bezos"',
loc_entity_name='"San Francisco" OR "New York City"',
misc_entity_name='AWS OR "Microsoft Azure"',
title_sentiment_min=-0.5,
title_sentiment_max=0.5,
content_sentiment_min=-0.5,
content_sentiment_max=0.5,
iptc_tags="20000199,20000209",
not_iptc_tags="20000205,20000209",
robots_compliant=True,
)
asyncio.run(main())
"""
_response = await self._raw_client.get(
q=q,
aggregation_by=aggregation_by,
search_in=search_in,
predefined_sources=predefined_sources,
sources=sources,
not_sources=not_sources,
lang=lang,
not_lang=not_lang,
countries=countries,
not_countries=not_countries,
not_author_name=not_author_name,
from_=from_,
to=to,
published_date_precision=published_date_precision,
by_parse_date=by_parse_date,
sort_by=sort_by,
ranked_only=ranked_only,
from_rank=from_rank,
to_rank=to_rank,
is_headline=is_headline,
is_opinion=is_opinion,
is_paid_content=is_paid_content,
parent_url=parent_url,
all_links=all_links,
all_domain_links=all_domain_links,
all_links_text=all_links_text,
word_count_min=word_count_min,
word_count_max=word_count_max,
page=page,
page_size=page_size,
include_nlp_data=include_nlp_data,
has_nlp=has_nlp,
theme=theme,
not_theme=not_theme,
org_entity_name=org_entity_name,
per_entity_name=per_entity_name,
loc_entity_name=loc_entity_name,
misc_entity_name=misc_entity_name,
title_sentiment_min=title_sentiment_min,
title_sentiment_max=title_sentiment_max,
content_sentiment_min=content_sentiment_min,
content_sentiment_max=content_sentiment_max,
iptc_tags=iptc_tags,
not_iptc_tags=not_iptc_tags,
robots_compliant=robots_compliant,
request_options=request_options,
)
return _response.data
async def post(
self,
*,
q: Q,
aggregation_by: typing.Optional[AggregationBy] = OMIT,
search_in: typing.Optional[SearchIn] = OMIT,
predefined_sources: typing.Optional[PredefinedSources] = OMIT,
sources: typing.Optional[Sources] = OMIT,
not_sources: typing.Optional[NotSources] = OMIT,
lang: typing.Optional[Lang] = OMIT,
not_lang: typing.Optional[NotLang] = OMIT,
countries: typing.Optional[Countries] = OMIT,
not_countries: typing.Optional[NotCountries] = OMIT,
not_author_name: typing.Optional[NotAuthorName] = OMIT,
from_: typing.Optional[From] = OMIT,
to: typing.Optional[To] = OMIT,
published_date_precision: typing.Optional[PublishedDatePrecision] = OMIT,
by_parse_date: typing.Optional[ByParseDate] = OMIT,
sort_by: typing.Optional[SortBy] = OMIT,
ranked_only: typing.Optional[RankedOnly] = OMIT,
from_rank: typing.Optional[FromRank] = OMIT,
to_rank: typing.Optional[ToRank] = OMIT,
is_headline: typing.Optional[IsHeadline] = OMIT,
is_opinion: typing.Optional[IsOpinion] = OMIT,
is_paid_content: typing.Optional[IsPaidContent] = OMIT,
parent_url: typing.Optional[ParentUrl] = OMIT,
all_links: typing.Optional[AllLinks] = OMIT,
all_domain_links: typing.Optional[AllDomainLinks] = OMIT,
all_links_text: typing.Optional[AllLinksText] = OMIT,
word_count_min: typing.Optional[WordCountMin] = OMIT,
word_count_max: typing.Optional[WordCountMax] = OMIT,
page: typing.Optional[Page] = OMIT,
page_size: typing.Optional[PageSize] = OMIT,
include_nlp_data: typing.Optional[IncludeNlpData] = OMIT,
has_nlp: typing.Optional[HasNlp] = OMIT,
theme: typing.Optional[Theme] = OMIT,
not_theme: typing.Optional[NotTheme] = OMIT,
org_entity_name: typing.Optional[OrgEntityName] = OMIT,
per_entity_name: typing.Optional[PerEntityName] = OMIT,
loc_entity_name: typing.Optional[LocEntityName] = OMIT,
misc_entity_name: typing.Optional[MiscEntityName] = OMIT,
title_sentiment_min: typing.Optional[TitleSentimentMin] = OMIT,
title_sentiment_max: typing.Optional[TitleSentimentMax] = OMIT,
content_sentiment_min: typing.Optional[ContentSentimentMin] = OMIT,
content_sentiment_max: typing.Optional[ContentSentimentMax] = OMIT,
iptc_tags: typing.Optional[IptcTags] = OMIT,
not_iptc_tags: typing.Optional[NotIptcTags] = OMIT,
robots_compliant: typing.Optional[RobotsCompliant] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> PostAggregationCountResponse:
"""
Retrieves the count of articles aggregated by day or hour based on various search criteria, such as keyword, language, country, and source.
Parameters
----------
q : Q
aggregation_by : typing.Optional[AggregationBy]
search_in : typing.Optional[SearchIn]
predefined_sources : typing.Optional[PredefinedSources]
sources : typing.Optional[Sources]
not_sources : typing.Optional[NotSources]
lang : typing.Optional[Lang]
not_lang : typing.Optional[NotLang]
countries : typing.Optional[Countries]
not_countries : typing.Optional[NotCountries]
not_author_name : typing.Optional[NotAuthorName]
from_ : typing.Optional[From]
to : typing.Optional[To]
published_date_precision : typing.Optional[PublishedDatePrecision]
by_parse_date : typing.Optional[ByParseDate]
sort_by : typing.Optional[SortBy]
ranked_only : typing.Optional[RankedOnly]
from_rank : typing.Optional[FromRank]