webscout 6.2b0__py3-none-any.whl → 6.4__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.

Files changed (97) hide show
  1. webscout/AIauto.py +191 -176
  2. webscout/AIbase.py +112 -239
  3. webscout/AIutel.py +488 -1130
  4. webscout/Agents/functioncall.py +248 -198
  5. webscout/Bing_search.py +250 -153
  6. webscout/DWEBS.py +454 -178
  7. webscout/Extra/__init__.py +2 -1
  8. webscout/Extra/autocoder/__init__.py +9 -0
  9. webscout/Extra/autocoder/autocoder_utiles.py +121 -0
  10. webscout/Extra/autocoder/rawdog.py +681 -0
  11. webscout/Extra/autollama.py +246 -195
  12. webscout/Extra/gguf.py +441 -226
  13. webscout/Extra/weather.py +172 -67
  14. webscout/LLM.py +442 -100
  15. webscout/Litlogger/__init__.py +681 -0
  16. webscout/Local/formats.py +4 -2
  17. webscout/Provider/Amigo.py +19 -10
  18. webscout/Provider/Andi.py +0 -33
  19. webscout/Provider/Blackboxai.py +4 -204
  20. webscout/Provider/DARKAI.py +1 -1
  21. webscout/Provider/EDITEE.py +1 -1
  22. webscout/Provider/Llama3.py +1 -1
  23. webscout/Provider/Marcus.py +137 -0
  24. webscout/Provider/NinjaChat.py +1 -1
  25. webscout/Provider/PI.py +221 -207
  26. webscout/Provider/Perplexity.py +598 -598
  27. webscout/Provider/RoboCoders.py +206 -0
  28. webscout/Provider/TTI/AiForce/__init__.py +22 -0
  29. webscout/Provider/TTI/AiForce/async_aiforce.py +257 -0
  30. webscout/Provider/TTI/AiForce/sync_aiforce.py +242 -0
  31. webscout/Provider/TTI/Nexra/__init__.py +22 -0
  32. webscout/Provider/TTI/Nexra/async_nexra.py +286 -0
  33. webscout/Provider/TTI/Nexra/sync_nexra.py +258 -0
  34. webscout/Provider/TTI/PollinationsAI/__init__.py +23 -0
  35. webscout/Provider/TTI/PollinationsAI/async_pollinations.py +330 -0
  36. webscout/Provider/TTI/PollinationsAI/sync_pollinations.py +285 -0
  37. webscout/Provider/TTI/__init__.py +3 -4
  38. webscout/Provider/TTI/artbit/__init__.py +22 -0
  39. webscout/Provider/TTI/artbit/async_artbit.py +184 -0
  40. webscout/Provider/TTI/artbit/sync_artbit.py +176 -0
  41. webscout/Provider/TTI/blackbox/__init__.py +4 -0
  42. webscout/Provider/TTI/blackbox/async_blackbox.py +212 -0
  43. webscout/Provider/TTI/{blackboximage.py → blackbox/sync_blackbox.py} +199 -153
  44. webscout/Provider/TTI/deepinfra/__init__.py +4 -0
  45. webscout/Provider/TTI/deepinfra/async_deepinfra.py +227 -0
  46. webscout/Provider/TTI/deepinfra/sync_deepinfra.py +199 -0
  47. webscout/Provider/TTI/huggingface/__init__.py +22 -0
  48. webscout/Provider/TTI/huggingface/async_huggingface.py +199 -0
  49. webscout/Provider/TTI/huggingface/sync_huggingface.py +195 -0
  50. webscout/Provider/TTI/imgninza/__init__.py +4 -0
  51. webscout/Provider/TTI/imgninza/async_ninza.py +214 -0
  52. webscout/Provider/TTI/{imgninza.py → imgninza/sync_ninza.py} +209 -136
  53. webscout/Provider/TTI/talkai/__init__.py +4 -0
  54. webscout/Provider/TTI/talkai/async_talkai.py +229 -0
  55. webscout/Provider/TTI/talkai/sync_talkai.py +207 -0
  56. webscout/Provider/__init__.py +146 -132
  57. webscout/Provider/askmyai.py +158 -0
  58. webscout/Provider/cerebras.py +227 -206
  59. webscout/Provider/geminiapi.py +208 -198
  60. webscout/Provider/llama3mitril.py +180 -0
  61. webscout/Provider/llmchat.py +203 -0
  62. webscout/Provider/mhystical.py +176 -0
  63. webscout/Provider/perplexitylabs.py +265 -0
  64. webscout/Provider/talkai.py +196 -0
  65. webscout/Provider/twitterclone.py +251 -244
  66. webscout/Provider/typegpt.py +359 -0
  67. webscout/__init__.py +28 -23
  68. webscout/__main__.py +5 -5
  69. webscout/cli.py +327 -347
  70. webscout/conversation.py +227 -0
  71. webscout/exceptions.py +161 -29
  72. webscout/litagent/__init__.py +172 -0
  73. webscout/litprinter/__init__.py +831 -0
  74. webscout/optimizers.py +270 -0
  75. webscout/prompt_manager.py +279 -0
  76. webscout/swiftcli/__init__.py +810 -0
  77. webscout/transcriber.py +479 -551
  78. webscout/update_checker.py +125 -0
  79. webscout/version.py +1 -1
  80. webscout-6.4.dist-info/LICENSE.md +211 -0
  81. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/METADATA +34 -55
  82. webscout-6.4.dist-info/RECORD +154 -0
  83. webscout/Provider/TTI/AIuncensored.py +0 -103
  84. webscout/Provider/TTI/Nexra.py +0 -120
  85. webscout/Provider/TTI/PollinationsAI.py +0 -138
  86. webscout/Provider/TTI/WebSimAI.py +0 -142
  87. webscout/Provider/TTI/aiforce.py +0 -160
  88. webscout/Provider/TTI/artbit.py +0 -141
  89. webscout/Provider/TTI/deepinfra.py +0 -148
  90. webscout/Provider/TTI/huggingface.py +0 -155
  91. webscout/models.py +0 -23
  92. webscout-6.2b0.dist-info/LICENSE.md +0 -50
  93. webscout-6.2b0.dist-info/RECORD +0 -118
  94. /webscout/{g4f.py → gpt4free.py} +0 -0
  95. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/WHEEL +0 -0
  96. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/entry_points.txt +0 -0
  97. {webscout-6.2b0.dist-info → webscout-6.4.dist-info}/top_level.txt +0 -0
webscout/cli.py CHANGED
@@ -1,347 +1,327 @@
1
- import csv
2
- import logging
3
- import os
4
- from concurrent.futures import ThreadPoolExecutor, as_completed
5
- from datetime import datetime
6
- from urllib.parse import unquote
7
- from pathlib import Path
8
- import click
9
- from curl_cffi import requests
10
- import pyreqwest_impersonate as pri
11
- from .webscout_search import WEBS
12
- from .utils import json_dumps, json_loads
13
- from .version import __version__
14
-
15
- # Import rich for panel interface
16
- from rich.panel import Panel
17
- from rich.markdown import Markdown
18
- from rich.console import Console
19
- from rich.table import Table
20
- from rich.style import Style
21
- from rich.text import Text
22
- from rich.align import Align
23
- from rich.progress import track, Progress
24
- from rich.prompt import Prompt, Confirm
25
- from rich.columns import Columns
26
- from pyfiglet import figlet_format
27
-
28
- logger = logging.getLogger(__name__)
29
-
30
- COLORS = {
31
- 0: "black",
32
- 1: "red",
33
- 2: "green",
34
- 3: "yellow",
35
- 4: "blue",
36
- 5: "magenta",
37
- 6: "cyan",
38
- 7: "bright_black",
39
- 8: "bright_red",
40
- 9: "bright_green",
41
- 10: "bright_yellow",
42
- 11: "bright_blue",
43
- 12: "bright_magenta",
44
- 13: "bright_cyan",
45
- 14: "white",
46
- 15: "bright_white",
47
- }
48
-
49
- def _print_data(data):
50
- """Prints data using rich panels and markdown."""
51
- console = Console()
52
- if data:
53
- for i, e in enumerate(data, start=1):
54
- table = Table(show_header=False, show_lines=True, expand=True, box=None) # Removed duplicate title
55
- table.add_column("Key", style="cyan", no_wrap=True, width=15)
56
- table.add_column("Value", style="white")
57
-
58
- for j, (k, v) in enumerate(e.items(), start=1):
59
- if v:
60
- width = 300 if k in ("content", "href", "image", "source", "thumbnail", "url") else 78
61
- k = "language" if k == "detected_language" else k
62
- text = click.wrap_text(
63
- f"{v}", width=width, initial_indent="", subsequent_indent=" " * 18, preserve_paragraphs=True
64
- ).replace("\n", "\n\n")
65
- else:
66
- text = v
67
- table.add_row(k, text)
68
-
69
- # Only the Panel has the title now
70
- console.print(Panel(table, title=f"Result {i}", expand=False, style="green on black"))
71
- console.print("\n")
72
-
73
-
74
- def _sanitize_keywords(keywords):
75
- """Sanitizes keywords for file names and paths. Removes invalid characters like ':'. """
76
- keywords = (
77
- keywords.replace("filetype", "")
78
- .replace(":", "")
79
- .replace('"', "'")
80
- .replace("site", "")
81
- .replace(" ", "_")
82
- .replace("/", "_")
83
- .replace("\\", "_")
84
- .replace(" ", "")
85
- )
86
- return keywords
87
-
88
- @click.group(chain=True)
89
- def cli():
90
- """webscout CLI tool - Search the web with a rich UI."""
91
- console = Console()
92
- console.print(f"[bold blue]{figlet_format('Webscout')}[/]\n", justify="center")
93
-
94
- def safe_entry_point():
95
- try:
96
- cli()
97
- except Exception as ex:
98
- click.echo(f"{type(ex).__name__}: {ex}")
99
-
100
-
101
- @cli.command()
102
- def version():
103
- """Shows the current version of webscout."""
104
- console = Console()
105
- console.print(Panel(Text(f"webscout v{__version__}", style="cyan"), title="Version", expand=False))
106
-
107
-
108
- @cli.command()
109
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
110
- def chat(proxy):
111
- """Interactive AI chat using DuckDuckGo's AI."""
112
- models = ["gpt-3.5", "claude-3-haiku", "llama-3-70b", "mixtral-8x7b"]
113
- client = WEBS(proxy=proxy)
114
-
115
- console = Console()
116
- console.print(Panel(Text("Available AI Models:", style="cyan"), title="DuckDuckGo AI Chat", expand=False))
117
- console.print(Columns([Panel(Text(model, justify="center"), expand=True) for model in models]))
118
- chosen_model_idx = Prompt.ask("[bold cyan]Choose a model by entering its number[/] [1]", choices=[str(i) for i in range(1, len(models) + 1)], default="1")
119
- chosen_model_idx = int(chosen_model_idx) - 1
120
- model = models[chosen_model_idx]
121
- console.print(f"[bold green]Using model:[/] {model}")
122
-
123
- while True:
124
- user_input = Prompt.ask(f"{'-'*78}\n[bold blue]You:[/]")
125
- if not user_input.strip():
126
- break
127
-
128
- resp_answer = client.chat(keywords=user_input, model=model)
129
- text = click.wrap_text(resp_answer, width=78, preserve_paragraphs=True)
130
- console.print(Panel(Text(f"AI: {text}", style="green"), title="AI Response"))
131
-
132
- if "exit" in user_input.lower() or "quit" in user_input.lower():
133
- console.print(Panel(Text("Exiting chat session.", style="cyan"), title="Goodbye", expand=False))
134
- break
135
-
136
-
137
- @cli.command()
138
- @click.option("-k", "--keywords", required=True, help="Keywords for text search.")
139
- @click.option("-r", "--region", default="wt-wt", help="Region (e.g., wt-wt, us-en, ru-ru) - See https://duckduckgo.com/params for more options.")
140
- @click.option("-s", "--safesearch", default="moderate", type=click.Choice(["on", "moderate", "off"]), help="Safe search level.")
141
- @click.option("-t", "--timelimit", default=None, type=click.Choice(["d", "w", "m", "y"]), help="Time limit (d: day, w: week, m: month, y: year).")
142
- @click.option("-m", "--max_results", default=20, help="Maximum number of results to retrieve (default: 20).")
143
- @click.option("-b", "--backend", default="api", type=click.Choice(["api", "html", "lite"]), help="Backend to use (api, html, lite).")
144
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
145
- def text(keywords, region, safesearch, timelimit, backend, max_results, proxy):
146
- """Performs a text search using DuckDuckGo API with a rich UI."""
147
- data = WEBS(proxy=proxy).text(
148
- keywords=keywords,
149
- region=region,
150
- safesearch=safesearch,
151
- timelimit=timelimit,
152
- backend=backend,
153
- max_results=max_results,
154
- )
155
- _print_data(data)
156
-
157
- @cli.command()
158
- @click.option("-k", "--keywords", required=True, help="Keywords for answers search.")
159
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
160
- def answers(keywords, proxy):
161
- """Performs an answers search using DuckDuckGo API with a rich UI."""
162
- data = WEBS(proxy=proxy).answers(keywords=keywords)
163
- _print_data(data)
164
-
165
-
166
- @cli.command()
167
- @click.option("-k", "--keywords", required=True, help="Keywords for images search.")
168
- @click.option("-r", "--region", default="wt-wt", help="Region (e.g., wt-wt, us-en, ru-ru) - See https://duckduckgo.com/params for more options.")
169
- @click.option("-s", "--safesearch", default="moderate", type=click.Choice(["on", "moderate", "off"]), help="Safe search level.")
170
- @click.option("-t", "--timelimit", default=None, type=click.Choice(["Day", "Week", "Month", "Year"]), help="Time limit (Day, Week, Month, Year).")
171
- @click.option("-size", "--size", default=None, type=click.Choice(["Small", "Medium", "Large", "Wallpaper"]), help="Image size (Small, Medium, Large, Wallpaper).")
172
- @click.option(
173
- "-c",
174
- "--color",
175
- default=None,
176
- type=click.Choice(
177
- [
178
- "color",
179
- "Monochrome",
180
- "Red",
181
- "Orange",
182
- "Yellow",
183
- "Green",
184
- "Blue",
185
- "Purple",
186
- "Pink",
187
- "Brown",
188
- "Black",
189
- "Gray",
190
- "Teal",
191
- "White",
192
- ]
193
- ),
194
- help="Image color (color, Monochrome, Red, Orange, Yellow, Green, Blue, Purple, Pink, Brown, Black, Gray, Teal, White).",
195
- )
196
- @click.option(
197
- "-type", "--type_image", default=None, type=click.Choice(["photo", "clipart", "gif", "transparent", "line"]), help="Image type (photo, clipart, gif, transparent, line)."
198
- )
199
- @click.option("-l", "--layout", default=None, type=click.Choice(["Square", "Tall", "Wide"]), help="Image layout (Square, Tall, Wide).")
200
- @click.option(
201
- "-lic",
202
- "--license_image",
203
- default=None,
204
- type=click.Choice(["any", "Public", "Share", "Modify", "ModifyCommercially"]),
205
- help="Image license (any, Public, Share, Modify, ModifyCommercially).",
206
- )
207
- @click.option("-m", "--max_results", default=90, help="Maximum number of results to retrieve (default: 90).")
208
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
209
- def images(
210
- keywords,
211
- region,
212
- safesearch,
213
- timelimit,
214
- size,
215
- color,
216
- type_image,
217
- layout,
218
- license_image,
219
- max_results,
220
- proxy,
221
- ):
222
- """Performs an images search using DuckDuckGo API with a rich UI."""
223
- data = WEBS(proxy=proxy).images(
224
- keywords=keywords,
225
- region=region,
226
- safesearch=safesearch,
227
- timelimit=timelimit,
228
- size=size,
229
- color=color,
230
- type_image=type_image,
231
- layout=layout,
232
- license_image=license_image,
233
- max_results=max_results,
234
- )
235
- _print_data(data)
236
-
237
-
238
- @cli.command()
239
- @click.option("-k", "--keywords", required=True, help="Keywords for videos search.")
240
- @click.option("-r", "--region", default="wt-wt", help="Region (e.g., wt-wt, us-en, ru-ru) - See https://duckduckgo.com/params for more options.")
241
- @click.option("-s", "--safesearch", default="moderate", type=click.Choice(["on", "moderate", "off"]), help="Safe search level.")
242
- @click.option("-t", "--timelimit", default=None, type=click.Choice(["d", "w", "m"]), help="Time limit (d: day, w: week, m: month).")
243
- @click.option("-res", "--resolution", default=None, type=click.Choice(["high", "standart"]), help="Video resolution (high, standart).")
244
- @click.option("-d", "--duration", default=None, type=click.Choice(["short", "medium", "long"]), help="Video duration (short, medium, long).")
245
- @click.option("-lic", "--license_videos", default=None, type=click.Choice(["creativeCommon", "youtube"]), help="Video license (creativeCommon, youtube).")
246
- @click.option("-m", "--max_results", default=50, help="Maximum number of results to retrieve (default: 50).")
247
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
248
- def videos(keywords, region, safesearch, timelimit, resolution, duration, license_videos, max_results, proxy):
249
- """Performs a videos search using DuckDuckGo API with a rich UI."""
250
- data = WEBS(proxy=proxy).videos(
251
- keywords=keywords,
252
- region=region,
253
- safesearch=safesearch,
254
- timelimit=timelimit,
255
- resolution=resolution,
256
- duration=duration,
257
- license_videos=license_videos,
258
- max_results=max_results,
259
- )
260
- _print_data(data)
261
-
262
-
263
- @cli.command()
264
- @click.option("-k", "--keywords", required=True, help="Keywords for news search.")
265
- @click.option("-r", "--region", default="wt-wt", help="Region (e.g., wt-wt, us-en, ru-ru) - See https://duckduckgo.com/params for more options.")
266
- @click.option("-s", "--safesearch", default="moderate", type=click.Choice(["on", "moderate", "off"]), help="Safe search level.")
267
- @click.option("-t", "--timelimit", default=None, type=click.Choice(["d", "w", "m", "y"]), help="Time limit (d: day, w: week, m: month, y: year).")
268
- @click.option("-m", "--max_results", default=25, help="Maximum number of results to retrieve (default: 25).")
269
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
270
- def news(keywords, region, safesearch, timelimit, max_results, proxy):
271
- """Performs a news search using DuckDuckGo API with a rich UI."""
272
- data = WEBS(proxy=proxy).news(
273
- keywords=keywords, region=region, safesearch=safesearch, timelimit=timelimit, max_results=max_results
274
- )
275
- _print_data(data)
276
-
277
-
278
- @cli.command()
279
- @click.option("-k", "--keywords", required=True, help="Keywords for maps search.")
280
- @click.option("-p", "--place", default=None, help="Simplified search - if set, the other parameters are not used.")
281
- @click.option("-s", "--street", default=None, help="House number/street.")
282
- @click.option("-c", "--city", default=None, help="City of search.")
283
- @click.option("-county", "--county", default=None, help="County of search.")
284
- @click.option("-state", "--state", default=None, help="State of search.")
285
- @click.option("-country", "--country", default=None, help="Country of search.")
286
- @click.option("-post", "--postalcode", default=None, help="Postal code of search.")
287
- @click.option("-lat", "--latitude", default=None, help="Geographic coordinate (north-south position).")
288
- @click.option("-lon", "--longitude", default=None, help="Geographic coordinate (east-west position); if latitude and longitude are set, the other parameters are not used.")
289
- @click.option("-r", "--radius", default=0, help="Expand the search square by the distance in kilometers.")
290
- @click.option("-m", "--max_results", default=50, help="Number of results (default: 50).")
291
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
292
- def maps(
293
- keywords,
294
- place,
295
- street,
296
- city,
297
- county,
298
- state,
299
- country,
300
- postalcode,
301
- latitude,
302
- longitude,
303
- radius,
304
- max_results,
305
- proxy,
306
- ):
307
- """Performs a maps search using DuckDuckGo API with a rich UI."""
308
- data = WEBS(proxy=proxy).maps(
309
- keywords=keywords,
310
- place=place,
311
- street=street,
312
- city=city,
313
- county=county,
314
- state=state,
315
- country=country,
316
- postalcode=postalcode,
317
- latitude=latitude,
318
- longitude=longitude,
319
- radius=radius,
320
- max_results=max_results,
321
- )
322
- _print_data(data)
323
-
324
-
325
- @cli.command()
326
- @click.option("-k", "--keywords", required=True, help="Text for translation.")
327
- @click.option("-f", "--from_", help="Language to translate from (defaults automatically).")
328
- @click.option("-t", "--to", default="en", help="Language to translate to (default: 'en').")
329
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
330
- def translate(keywords, from_, to, proxy):
331
- """Performs translation using DuckDuckGo API with a rich UI."""
332
- data = WEBS(proxy=proxy).translate(keywords=keywords, from_=from_, to=to)
333
- _print_data(data)
334
-
335
-
336
- @cli.command()
337
- @click.option("-k", "--keywords", required=True, help="Keywords for query.")
338
- @click.option("-r", "--region", default="wt-wt", help="Region (e.g., wt-wt, us-en, ru-ru) - See https://duckduckgo.com/params for more options.")
339
- @click.option("-p", "--proxy", default=None, help="Proxy to send requests (e.g., socks5://localhost:9150)")
340
- def suggestions(keywords, region, proxy):
341
- """Performs a suggestions search using DuckDuckGo API with a rich UI."""
342
- data = WEBS(proxy=proxy).suggestions(keywords=keywords, region=region)
343
- _print_data(data)
344
-
345
-
346
- if __name__ == "__main__":
347
- cli(prog_name="WEBS")
1
+ import os
2
+ import sys
3
+ from concurrent.futures import ThreadPoolExecutor, as_completed
4
+ from datetime import datetime
5
+ from urllib.parse import unquote
6
+ from pathlib import Path
7
+ from .swiftcli import CLI, option, argument, group
8
+ from curl_cffi import requests
9
+ import pyreqwest_impersonate as pri
10
+ from .webscout_search import WEBS
11
+ from .utils import json_dumps, json_loads
12
+ from .version import __version__
13
+ from .Litlogger import LitLogger, LogFormat, ColorScheme
14
+ from rich.console import Console
15
+ from rich.panel import Panel
16
+ from rich.markdown import Markdown
17
+ from rich.table import Table
18
+ from rich.style import Style
19
+ from rich.text import Text
20
+ from rich.align import Align
21
+ from rich.progress import track, Progress
22
+ from rich.prompt import Prompt, Confirm
23
+ from rich.columns import Columns
24
+ from pyfiglet import figlet_format
25
+
26
+ logger = LitLogger(
27
+ name="webscout",
28
+ format=LogFormat.MODERN_EMOJI,
29
+ color_scheme=ColorScheme.CYBERPUNK,
30
+ console_output=True
31
+ )
32
+
33
+ COLORS = {
34
+ 0: "black",
35
+ 1: "red",
36
+ 2: "green",
37
+ 3: "yellow",
38
+ 4: "blue",
39
+ 5: "magenta",
40
+ 6: "cyan",
41
+ 7: "bright_black",
42
+ 8: "bright_red",
43
+ 9: "bright_green",
44
+ 10: "bright_yellow",
45
+ 11: "bright_blue",
46
+ 12: "bright_magenta",
47
+ 13: "bright_cyan",
48
+ 14: "white",
49
+ 15: "bright_white",
50
+ }
51
+
52
+ def _print_data(data):
53
+ """Prints data using rich panels and markdown."""
54
+ console = Console()
55
+ if data:
56
+ for i, e in enumerate(data, start=1):
57
+ table = Table(show_header=False, show_lines=True, expand=True, box=None) # Removed duplicate title
58
+ table.add_column("Key", style="cyan", no_wrap=True, width=15)
59
+ table.add_column("Value", style="white")
60
+
61
+ for j, (k, v) in enumerate(e.items(), start=1):
62
+ if v:
63
+ width = 300 if k in ("content", "href", "image", "source", "thumbnail", "url") else 78
64
+ k = "language" if k == "detected_language" else k
65
+ text = Text(f"{v}", style="white")
66
+ text = text.wrap(width=width, initial_indent="", subsequent_indent=" " * 18, preserve_paragraphs=True)
67
+ else:
68
+ text = Text(v, style="white")
69
+ table.add_row(k, text)
70
+
71
+ # Only the Panel has the title now
72
+ console.print(Panel(table, title=f"Result {i}", expand=False, style="green on black"))
73
+ console.print("\n")
74
+
75
+ # Initialize CLI app
76
+ app = CLI(name="webscout", help="Search the web with a rich UI", version=__version__)
77
+
78
+ @app.command()
79
+ def version():
80
+ """Show the version of webscout."""
81
+ console = Console()
82
+ console.print(f"[bold green]webscout[/bold green] version: {__version__}")
83
+
84
+ @app.command()
85
+ @option("--proxy", help="Proxy URL to use for requests")
86
+ @option("--model", "-m", help="AI model to use", default="gpt-4o-mini", type=str)
87
+ def chat(proxy: str = None, model: str = "gpt-4o-mini"):
88
+ """Interactive AI chat using DuckDuckGo's AI."""
89
+ webs = WEBS(proxy=proxy)
90
+ console = Console()
91
+
92
+ # Display header
93
+ console.print(f"[bold blue]{figlet_format('Webscout Chat')}[/]\n", justify="center")
94
+ console.print(f"[bold green]Using model:[/] {model}\n")
95
+ console.print("[cyan]Type your message and press Enter. Press Ctrl+C or type 'exit' to quit.[/]\n")
96
+
97
+ # Start chat loop
98
+ try:
99
+ while True:
100
+ try:
101
+ user_input = input("You: ").strip()
102
+ if not user_input or user_input.lower() in ['exit', 'quit']:
103
+ break
104
+
105
+ logger.info(f"Sending message to {model}")
106
+ response = webs.chat(keywords=user_input, model=model)
107
+ console.print(f"\nAI: {response}\n")
108
+ logger.success("Received response from AI")
109
+
110
+ except Exception as e:
111
+ logger.error(f"Error in chat: {str(e)}")
112
+ console.print(f"[bold red]Error:[/] {str(e)}\n")
113
+
114
+ except KeyboardInterrupt:
115
+ logger.info("Chat session terminated by user")
116
+
117
+ console.print("\n[cyan]Chat session ended. Goodbye![/]")
118
+
119
+ @app.command()
120
+ @option("--keywords", "-k", help="Search keywords")
121
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
122
+ @option("--safesearch", "-s", help="SafeSearch setting", default="moderate")
123
+ @option("--timelimit", "-t", help="Time limit for results", default=None)
124
+ @option("--backend", "-b", help="Search backend to use", default="api")
125
+ @option("--max-results", "-m", help="Maximum number of results", type=int, default=25)
126
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
127
+ def text(keywords: str, region: str, safesearch: str, timelimit: str, backend: str, max_results: int, proxy: str = None):
128
+ """Perform a text search using DuckDuckGo API."""
129
+ webs = WEBS(proxy=proxy)
130
+ try:
131
+ webs.text(keywords, region, safesearch, timelimit, backend, max_results)
132
+ except Exception as e:
133
+ logger.error(f"Error in text search: {e}")
134
+ raise e
135
+
136
+ @app.command()
137
+ @option("--keywords", "-k", help="Search keywords")
138
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
139
+ @option("--safesearch", "-s", help="SafeSearch setting", default="moderate")
140
+ @option("--timelimit", "-t", help="Time limit for results", default=None)
141
+ @option("--max-results", "-m", help="Maximum number of results", type=int, default=25)
142
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
143
+ def answers(keywords: str, region: str, safesearch: str, timelimit: str, max_results: int, proxy: str = None):
144
+ """Perform an answers search using DuckDuckGo API."""
145
+ webs = WEBS(proxy=proxy)
146
+ try:
147
+ webs.answers(keywords, region, safesearch, timelimit, max_results)
148
+ except Exception as e:
149
+ logger.error(f"Error in answers search: {e}")
150
+ raise e
151
+
152
+ @app.command()
153
+ @option("--keywords", "-k", help="Search keywords")
154
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
155
+ @option("--safesearch", "-s", help="SafeSearch setting", default="moderate")
156
+ @option("--timelimit", "-t", help="Time limit for results", default=None)
157
+ @option("--size", "-size", help="Image size", default=None)
158
+ @option("--color", "-c", help="Image color", default=None)
159
+ @option("--type", "-type", help="Image type", default=None)
160
+ @option("--layout", "-l", help="Image layout", default=None)
161
+ @option("--license", "-lic", help="Image license", default=None)
162
+ @option("--max-results", "-m", help="Maximum number of results", type=int, default=90)
163
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
164
+ def images(
165
+ keywords: str,
166
+ region: str,
167
+ safesearch: str,
168
+ timelimit: str,
169
+ size: str,
170
+ color: str,
171
+ type: str,
172
+ layout: str,
173
+ license: str,
174
+ max_results: int,
175
+ proxy: str = None,
176
+ ):
177
+ """Perform an images search using DuckDuckGo API."""
178
+ webs = WEBS(proxy=proxy)
179
+ try:
180
+ webs.images(keywords, region, safesearch, timelimit, size, color, type, layout, license, max_results)
181
+ except Exception as e:
182
+ logger.error(f"Error in images search: {e}")
183
+ raise e
184
+
185
+ @app.command()
186
+ @option("--keywords", "-k", help="Search keywords")
187
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
188
+ @option("--safesearch", "-s", help="SafeSearch setting", default="moderate")
189
+ @option("--timelimit", "-t", help="Time limit for results", default=None)
190
+ @option("--resolution", "-res", help="Video resolution", default=None)
191
+ @option("--duration", "-d", help="Video duration", default=None)
192
+ @option("--license", "-lic", help="Video license", default=None)
193
+ @option("--max-results", "-m", help="Maximum number of results", type=int, default=50)
194
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
195
+ def videos(
196
+ keywords: str,
197
+ region: str,
198
+ safesearch: str,
199
+ timelimit: str,
200
+ resolution: str,
201
+ duration: str,
202
+ license: str,
203
+ max_results: int,
204
+ proxy: str = None,
205
+ ):
206
+ """Perform a videos search using DuckDuckGo API."""
207
+ webs = WEBS(proxy=proxy)
208
+ try:
209
+ webs.videos(keywords, region, safesearch, timelimit, resolution, duration, license, max_results)
210
+ except Exception as e:
211
+ logger.error(f"Error in videos search: {e}")
212
+ raise e
213
+
214
+ @app.command()
215
+ @option("--keywords", "-k", help="Search keywords")
216
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
217
+ @option("--safesearch", "-s", help="SafeSearch setting", default="moderate")
218
+ @option("--timelimit", "-t", help="Time limit for results", default=None)
219
+ @option("--max-results", "-m", help="Maximum number of results", type=int, default=25)
220
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
221
+ def news(keywords: str, region: str, safesearch: str, timelimit: str, max_results: int, proxy: str = None):
222
+ """Perform a news search using DuckDuckGo API."""
223
+ webs = WEBS(proxy=proxy)
224
+ try:
225
+ webs.news(keywords, region, safesearch, timelimit, max_results)
226
+ except Exception as e:
227
+ logger.error(f"Error in news search: {e}")
228
+ raise e
229
+
230
+ @app.command()
231
+ @option("--keywords", "-k", help="Search keywords")
232
+ @option("--place", "-p", help="Simplified search - if set, the other parameters are not used")
233
+ @option("--street", "-s", help="House number/street")
234
+ @option("--city", "-c", help="City of search")
235
+ @option("--county", "-county", help="County of search")
236
+ @option("--state", "-state", help="State of search")
237
+ @option("--country", "-country", help="Country of search")
238
+ @option("--postalcode", "-post", help="Postal code of search")
239
+ @option("--latitude", "-lat", help="Geographic coordinate (north-south position)")
240
+ @option("--longitude", "-lon", help="Geographic coordinate (east-west position); if latitude and longitude are set, the other parameters are not used")
241
+ @option("--radius", "-r", help="Expand the search square by the distance in kilometers", type=int, default=0)
242
+ @option("--max-results", "-m", help="Number of results", type=int, default=50)
243
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
244
+ def maps(
245
+ keywords: str,
246
+ place: str,
247
+ street: str,
248
+ city: str,
249
+ county: str,
250
+ state: str,
251
+ country: str,
252
+ postalcode: str,
253
+ latitude: str,
254
+ longitude: str,
255
+ radius: int,
256
+ max_results: int,
257
+ proxy: str = None,
258
+ ):
259
+ """Perform a maps search using DuckDuckGo API."""
260
+ webs = WEBS(proxy=proxy)
261
+ try:
262
+ webs.maps(
263
+ keywords,
264
+ place,
265
+ street,
266
+ city,
267
+ county,
268
+ state,
269
+ country,
270
+ postalcode,
271
+ latitude,
272
+ longitude,
273
+ radius,
274
+ max_results,
275
+ )
276
+ except Exception as e:
277
+ logger.error(f"Error in maps search: {e}")
278
+ raise e
279
+
280
+ @app.command()
281
+ @option("--keywords", "-k", help="Text for translation")
282
+ @option("--from", "-f", help="Language to translate from (defaults automatically)")
283
+ @option("--to", "-t", help="Language to translate to (default: 'en')", default="en")
284
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
285
+ def translate(keywords: str, from_: str, to: str, proxy: str = None):
286
+ """Perform translation using DuckDuckGo API."""
287
+ webs = WEBS(proxy=proxy)
288
+ try:
289
+ webs.translate(keywords, from_, to)
290
+ except Exception as e:
291
+ logger.error(f"Error in translation: {e}")
292
+ raise e
293
+
294
+ @app.command()
295
+ @option("--keywords", "-k", help="Search keywords")
296
+ @option("--region", "-r", help="Region for search results", default="wt-wt")
297
+ @option("--proxy", "-p", help="Proxy URL to use for requests")
298
+ def suggestions(keywords: str, region: str, proxy: str = None):
299
+ """Perform a suggestions search using DuckDuckGo API."""
300
+ webs = WEBS(proxy=proxy)
301
+ try:
302
+ webs.suggestions(keywords, region)
303
+ except Exception as e:
304
+ logger.error(f"Error in suggestions search: {e}")
305
+ raise e
306
+
307
+ @app.command()
308
+ @option("--proxy", help="Proxy URL to use for requests")
309
+ def interactive(proxy: str = None):
310
+ """Start an interactive search session with AI-powered responses."""
311
+ webs = WEBS(proxy=proxy)
312
+ try:
313
+ webs.interactive()
314
+ except Exception as e:
315
+ logger.error(f"Error in interactive mode: {e}")
316
+ raise e
317
+
318
+ def main():
319
+ """Main entry point for the CLI."""
320
+ try:
321
+ app.run()
322
+ except Exception as e:
323
+ logger.error(f"Error: {e}")
324
+ sys.exit(1)
325
+
326
+ if __name__ == "__main__":
327
+ main()