webscout 3.3__py3-none-any.whl → 3.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webscout might be problematic. Click here for more details.

@@ -30,11 +30,11 @@ from .utils import (
30
30
  json_loads,
31
31
  )
32
32
 
33
- logger = logging.getLogger("webcout_search.WEBS")
33
+ logger = logging.getLogger("webscout.WEBS")
34
34
 
35
35
 
36
36
  class WEBS:
37
- """webcout_search class to get search results from duckduckgo.com."""
37
+ """webscout class to get search results from duckduckgo.com."""
38
38
 
39
39
  _executor: ThreadPoolExecutor = ThreadPoolExecutor()
40
40
 
@@ -121,16 +121,22 @@ class WEBS:
121
121
  return _extract_vqd(resp_content, keywords)
122
122
 
123
123
  def chat(self, keywords: str, model: str = "gpt-3.5") -> str:
124
- """Initiates a chat session with Webscout AI.
124
+ """Initiates a chat session with DuckDuckGo AI.
125
125
 
126
126
  Args:
127
127
  keywords (str): The initial message or question to send to the AI.
128
- model (str): The model to use: "gpt-3.5", "claude-3-haiku". Defaults to "gpt-3.5".
128
+ model (str): The model to use: "gpt-3.5", "claude-3-haiku", "llama-3-70b", "mixtral-8x7b".
129
+ Defaults to "gpt-3.5".
129
130
 
130
131
  Returns:
131
132
  str: The response from the AI.
132
133
  """
133
- models = {"claude-3-haiku": "claude-3-haiku-20240307", "gpt-3.5": "gpt-3.5-turbo-0125"}
134
+ models = {
135
+ "claude-3-haiku": "claude-3-haiku-20240307",
136
+ "gpt-3.5": "gpt-3.5-turbo-0125",
137
+ "llama-3-70b": "meta-llama/Llama-3-70b-chat-hf",
138
+ "mixtral-8x7b": "mistralai/Mixtral-8x7B-Instruct-v0.1",
139
+ }
134
140
  # vqd
135
141
  if not self._chat_vqd:
136
142
  resp = self.client.get("https://duckduckgo.com/duckchat/v1/status", headers={"x-vqd-accept": "1"})
@@ -167,7 +173,7 @@ class WEBS:
167
173
  backend: str = "api",
168
174
  max_results: Optional[int] = None,
169
175
  ) -> List[Dict[str, str]]:
170
- """Webscout text search. Query params: https://duckduckgo.com/params.
176
+ """DuckDuckGo text search. Query params: https://duckduckgo.com/params.
171
177
 
172
178
  Args:
173
179
  keywords: keywords for query.
@@ -184,7 +190,7 @@ class WEBS:
184
190
  List of dictionaries with search results, or None if there was an error.
185
191
 
186
192
  Raises:
187
- WebscoutE: Base exception for webcout_search errors.
193
+ WebscoutE: Base exception for webscout errors.
188
194
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
189
195
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
190
196
  """
@@ -195,7 +201,7 @@ class WEBS:
195
201
  if backend == "api":
196
202
  results = self._text_api(keywords, region, safesearch, timelimit, max_results)
197
203
  elif backend == "html":
198
- results = self._text_html(keywords, region, safesearch, timelimit, max_results)
204
+ results = self._text_html(keywords, region, timelimit, max_results)
199
205
  elif backend == "lite":
200
206
  results = self._text_lite(keywords, region, timelimit, max_results)
201
207
  return results
@@ -208,7 +214,7 @@ class WEBS:
208
214
  timelimit: Optional[str] = None,
209
215
  max_results: Optional[int] = None,
210
216
  ) -> List[Dict[str, str]]:
211
- """Webscout text search. Query params: https://duckduckgo.com/params.
217
+ """DuckDuckGo text search. Query params: https://duckduckgo.com/params.
212
218
 
213
219
  Args:
214
220
  keywords: keywords for query.
@@ -221,7 +227,7 @@ class WEBS:
221
227
  List of dictionaries with search results.
222
228
 
223
229
  Raises:
224
- WebscoutE: Base exception for webcout_search errors.
230
+ WebscoutE: Base exception for webscout errors.
225
231
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
226
232
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
227
233
  """
@@ -237,6 +243,7 @@ class WEBS:
237
243
  "s": "0",
238
244
  "df": "",
239
245
  "vqd": vqd,
246
+ "bing_market": f"{region[3:]}-{region[:2].upper()}",
240
247
  "ex": "",
241
248
  }
242
249
  safesearch = safesearch.lower()
@@ -273,7 +280,7 @@ class WEBS:
273
280
 
274
281
  slist = [0]
275
282
  if max_results:
276
- max_results = min(max_results, 500)
283
+ max_results = min(max_results, 2023)
277
284
  slist.extend(range(23, max_results, 50))
278
285
  try:
279
286
  for r in self._executor.map(_text_api_page, slist):
@@ -287,16 +294,14 @@ class WEBS:
287
294
  self,
288
295
  keywords: str,
289
296
  region: str = "wt-wt",
290
- safesearch: str = "moderate",
291
297
  timelimit: Optional[str] = None,
292
298
  max_results: Optional[int] = None,
293
299
  ) -> List[Dict[str, str]]:
294
- """Webscout text search. Query params: https://duckduckgo.com/params.
300
+ """DuckDuckGo text search. Query params: https://duckduckgo.com/params.
295
301
 
296
302
  Args:
297
303
  keywords: keywords for query.
298
304
  region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
299
- safesearch: on, moderate, off. Defaults to "moderate".
300
305
  timelimit: d, w, m, y. Defaults to None.
301
306
  max_results: max number of results. If None, returns results only from the first response. Defaults to None.
302
307
 
@@ -304,19 +309,20 @@ class WEBS:
304
309
  List of dictionaries with search results.
305
310
 
306
311
  Raises:
307
- WebscoutE: Base exception for webcout_search errors.
312
+ WebscoutE: Base exception for webscout errors.
308
313
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
309
314
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
310
315
  """
311
316
  assert keywords, "keywords is mandatory"
312
317
 
313
- safesearch_base = {"on": "1", "moderate": "-1", "off": "-2"}
314
318
  payload = {
315
319
  "q": keywords,
316
- "kl": region,
317
- "p": safesearch_base[safesearch.lower()],
320
+ "s": "0",
318
321
  "o": "json",
319
322
  "api": "d.js",
323
+ "vqd": "",
324
+ "kl": region,
325
+ "bing_market": region,
320
326
  }
321
327
  if timelimit:
322
328
  payload["df"] = timelimit
@@ -364,7 +370,7 @@ class WEBS:
364
370
 
365
371
  slist = [0]
366
372
  if max_results:
367
- max_results = min(max_results, 500)
373
+ max_results = min(max_results, 2023)
368
374
  slist.extend(range(23, max_results, 50))
369
375
  try:
370
376
  for r in self._executor.map(_text_html_page, slist):
@@ -381,7 +387,7 @@ class WEBS:
381
387
  timelimit: Optional[str] = None,
382
388
  max_results: Optional[int] = None,
383
389
  ) -> List[Dict[str, str]]:
384
- """Webscout text search. Query params: https://duckduckgo.com/params.
390
+ """DuckDuckGo text search. Query params: https://duckduckgo.com/params.
385
391
 
386
392
  Args:
387
393
  keywords: keywords for query.
@@ -393,7 +399,7 @@ class WEBS:
393
399
  List of dictionaries with search results.
394
400
 
395
401
  Raises:
396
- WebscoutE: Base exception for webcout_search errors.
402
+ WebscoutE: Base exception for webscout errors.
397
403
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
398
404
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
399
405
  """
@@ -401,9 +407,12 @@ class WEBS:
401
407
 
402
408
  payload = {
403
409
  "q": keywords,
410
+ "s": "0",
404
411
  "o": "json",
405
412
  "api": "d.js",
413
+ "vqd": "",
406
414
  "kl": region,
415
+ "bing_market": region,
407
416
  }
408
417
  if timelimit:
409
418
  payload["df"] = timelimit
@@ -455,7 +464,7 @@ class WEBS:
455
464
 
456
465
  slist = [0]
457
466
  if max_results:
458
- max_results = min(max_results, 500)
467
+ max_results = min(max_results, 2023)
459
468
  slist.extend(range(23, max_results, 50))
460
469
  try:
461
470
  for r in self._executor.map(_text_lite_page, slist):
@@ -478,7 +487,7 @@ class WEBS:
478
487
  license_image: Optional[str] = None,
479
488
  max_results: Optional[int] = None,
480
489
  ) -> List[Dict[str, str]]:
481
- """Webscout images search. Query params: https://duckduckgo.com/params.
490
+ """DuckDuckGo images search. Query params: https://duckduckgo.com/params.
482
491
 
483
492
  Args:
484
493
  keywords: keywords for query.
@@ -501,7 +510,7 @@ class WEBS:
501
510
  List of dictionaries with images search results.
502
511
 
503
512
  Raises:
504
- WebscoutE: Base exception for webcout_search errors.
513
+ WebscoutE: Base exception for webscout errors.
505
514
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
506
515
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
507
516
  """
@@ -574,7 +583,7 @@ class WEBS:
574
583
  license_videos: Optional[str] = None,
575
584
  max_results: Optional[int] = None,
576
585
  ) -> List[Dict[str, str]]:
577
- """Webscout videos search. Query params: https://duckduckgo.com/params.
586
+ """DuckDuckGo videos search. Query params: https://duckduckgo.com/params.
578
587
 
579
588
  Args:
580
589
  keywords: keywords for query.
@@ -590,7 +599,7 @@ class WEBS:
590
599
  List of dictionaries with videos search results.
591
600
 
592
601
  Raises:
593
- WebscoutE: Base exception for webcout_search errors.
602
+ WebscoutE: Base exception for webscout errors.
594
603
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
595
604
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
596
605
  """
@@ -631,7 +640,7 @@ class WEBS:
631
640
  slist = [0]
632
641
  if max_results:
633
642
  max_results = min(max_results, 400)
634
- slist.extend(range(59, max_results, 59))
643
+ slist.extend(range(60, max_results, 60))
635
644
  try:
636
645
  for r in self._executor.map(_videos_page, slist):
637
646
  results.extend(r)
@@ -648,7 +657,7 @@ class WEBS:
648
657
  timelimit: Optional[str] = None,
649
658
  max_results: Optional[int] = None,
650
659
  ) -> List[Dict[str, str]]:
651
- """Webscout news search. Query params: https://duckduckgo.com/params.
660
+ """DuckDuckGo news search. Query params: https://duckduckgo.com/params.
652
661
 
653
662
  Args:
654
663
  keywords: keywords for query.
@@ -661,7 +670,7 @@ class WEBS:
661
670
  List of dictionaries with news search results.
662
671
 
663
672
  Raises:
664
- WebscoutE: Base exception for webcout_search errors.
673
+ WebscoutE: Base exception for webscout errors.
665
674
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
666
675
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
667
676
  """
@@ -707,8 +716,8 @@ class WEBS:
707
716
 
708
717
  slist = [0]
709
718
  if max_results:
710
- max_results = min(max_results, 200)
711
- slist.extend(range(29, max_results, 29))
719
+ max_results = min(max_results, 120)
720
+ slist.extend(range(30, max_results, 30))
712
721
  try:
713
722
  for r in self._executor.map(_news_page, slist):
714
723
  results.extend(r)
@@ -718,7 +727,7 @@ class WEBS:
718
727
  return list(islice(results, max_results))
719
728
 
720
729
  def answers(self, keywords: str) -> List[Dict[str, str]]:
721
- """Webscout instant answers. Query params: https://duckduckgo.com/params.
730
+ """DuckDuckGo instant answers. Query params: https://duckduckgo.com/params.
722
731
 
723
732
  Args:
724
733
  keywords: keywords for query,
@@ -727,7 +736,7 @@ class WEBS:
727
736
  List of dictionaries with instant answers results.
728
737
 
729
738
  Raises:
730
- WebscoutE: Base exception for webcout_search errors.
739
+ WebscoutE: Base exception for webscout errors.
731
740
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
732
741
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
733
742
  """
@@ -789,7 +798,7 @@ class WEBS:
789
798
  return results
790
799
 
791
800
  def suggestions(self, keywords: str, region: str = "wt-wt") -> List[Dict[str, str]]:
792
- """Webscout suggestions. Query params: https://duckduckgo.com/params.
801
+ """DuckDuckGo suggestions. Query params: https://duckduckgo.com/params.
793
802
 
794
803
  Args:
795
804
  keywords: keywords for query.
@@ -799,7 +808,7 @@ class WEBS:
799
808
  List of dictionaries with suggestions results.
800
809
 
801
810
  Raises:
802
- WebscoutE: Base exception for webcout_search errors.
811
+ WebscoutE: Base exception for webscout errors.
803
812
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
804
813
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
805
814
  """
@@ -828,7 +837,7 @@ class WEBS:
828
837
  radius: int = 0,
829
838
  max_results: Optional[int] = None,
830
839
  ) -> List[Dict[str, str]]:
831
- """Webscout maps search. Query params: https://duckduckgo.com/params.
840
+ """DuckDuckGo maps search. Query params: https://duckduckgo.com/params.
832
841
 
833
842
  Args:
834
843
  keywords: keywords for query
@@ -849,7 +858,7 @@ class WEBS:
849
858
  List of dictionaries with maps search results, or None if there was an error.
850
859
 
851
860
  Raises:
852
- WebscoutE: Base exception for webcout_search errors.
861
+ WebscoutE: Base exception for webscout errors.
853
862
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
854
863
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
855
864
  """
@@ -1005,7 +1014,7 @@ class WEBS:
1005
1014
  def translate(
1006
1015
  self, keywords: Union[List[str], str], from_: Optional[str] = None, to: str = "en"
1007
1016
  ) -> List[Dict[str, str]]:
1008
- """Webscout translate.
1017
+ """DuckDuckGo translate.
1009
1018
 
1010
1019
  Args:
1011
1020
  keywords: string or list of strings to translate.
@@ -1016,7 +1025,7 @@ class WEBS:
1016
1025
  List od dictionaries with translated keywords.
1017
1026
 
1018
1027
  Raises:
1019
- WebscoutE: Base exception for webcout_search errors.
1028
+ WebscoutE: Base exception for webscout errors.
1020
1029
  RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
1021
1030
  TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
1022
1031
  """
@@ -37,11 +37,12 @@ class AsyncWEBS(WEBS):
37
37
  pass
38
38
 
39
39
  async def achat(self, keywords: str, model: str = "gpt-3.5") -> str:
40
- """Initiates async chat session with Webscout AI.
40
+ """Initiates async chat session with DuckDuckGo AI.
41
41
 
42
42
  Args:
43
43
  keywords (str): The initial message or question to send to the AI.
44
- model (str): The model to use: "gpt-3.5", "claude-3-haiku". Defaults to "gpt-3.5".
44
+ model (str): The model to use: "gpt-3.5", "claude-3-haiku", "llama-3-70b", "mixtral-8x7b".
45
+ Defaults to "gpt-3.5".
45
46
 
46
47
  Returns:
47
48
  str: The response from the AI.
@@ -58,7 +59,7 @@ class AsyncWEBS(WEBS):
58
59
  backend: str = "api",
59
60
  max_results: Optional[int] = None,
60
61
  ) -> List[Dict[str, str]]:
61
- """Webscout async text search. Query params: https://duckduckgo.com/params.
62
+ """DuckDuckGo async text search. Query params: https://duckduckgo.com/params.
62
63
 
63
64
  Args:
64
65
  keywords: keywords for query.
@@ -97,7 +98,7 @@ class AsyncWEBS(WEBS):
97
98
  license_image: Optional[str] = None,
98
99
  max_results: Optional[int] = None,
99
100
  ) -> List[Dict[str, str]]:
100
- """Webscout async images search. Query params: https://duckduckgo.com/params.
101
+ """DuckDuckGo async images search. Query params: https://duckduckgo.com/params.
101
102
 
102
103
  Args:
103
104
  keywords: keywords for query.
@@ -151,7 +152,7 @@ class AsyncWEBS(WEBS):
151
152
  license_videos: Optional[str] = None,
152
153
  max_results: Optional[int] = None,
153
154
  ) -> List[Dict[str, str]]:
154
- """Webscout async videos search. Query params: https://duckduckgo.com/params.
155
+ """DuckDuckGo async videos search. Query params: https://duckduckgo.com/params.
155
156
 
156
157
  Args:
157
158
  keywords: keywords for query.
@@ -193,7 +194,7 @@ class AsyncWEBS(WEBS):
193
194
  timelimit: Optional[str] = None,
194
195
  max_results: Optional[int] = None,
195
196
  ) -> List[Dict[str, str]]:
196
- """Webscout async news search. Query params: https://duckduckgo.com/params.
197
+ """DuckDuckGo async news search. Query params: https://duckduckgo.com/params.
197
198
 
198
199
  Args:
199
200
  keywords: keywords for query.
@@ -225,7 +226,7 @@ class AsyncWEBS(WEBS):
225
226
  self,
226
227
  keywords: str,
227
228
  ) -> List[Dict[str, str]]:
228
- """Webscout async instant answers. Query params: https://duckduckgo.com/params.
229
+ """DuckDuckGo async instant answers. Query params: https://duckduckgo.com/params.
229
230
 
230
231
  Args:
231
232
  keywords: keywords for query,
@@ -250,7 +251,7 @@ class AsyncWEBS(WEBS):
250
251
  keywords: str,
251
252
  region: str = "wt-wt",
252
253
  ) -> List[Dict[str, str]]:
253
- """Webscout async suggestions. Query params: https://duckduckgo.com/params.
254
+ """DuckDuckGo async suggestions. Query params: https://duckduckgo.com/params.
254
255
 
255
256
  Args:
256
257
  keywords: keywords for query.
@@ -287,7 +288,7 @@ class AsyncWEBS(WEBS):
287
288
  radius: int = 0,
288
289
  max_results: Optional[int] = None,
289
290
  ) -> List[Dict[str, str]]:
290
- """Webscout async maps search. Query params: https://duckduckgo.com/params.
291
+ """DuckDuckGo async maps search. Query params: https://duckduckgo.com/params.
291
292
 
292
293
  Args:
293
294
  keywords: keywords for query
@@ -336,7 +337,7 @@ class AsyncWEBS(WEBS):
336
337
  from_: Optional[str] = None,
337
338
  to: str = "en",
338
339
  ) -> List[Dict[str, str]]:
339
- """Webscout async translate.
340
+ """DuckDuckGo async translate.
340
341
 
341
342
  Args:
342
343
  keywords: string or list of strings to translate.