webscout 8.2.9__py3-none-any.whl → 2026.1.19__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.
Files changed (413) hide show
  1. webscout/AIauto.py +524 -251
  2. webscout/AIbase.py +247 -319
  3. webscout/AIutel.py +68 -703
  4. webscout/Bard.py +1072 -1026
  5. webscout/Extra/GitToolkit/__init__.py +10 -10
  6. webscout/Extra/GitToolkit/gitapi/__init__.py +20 -12
  7. webscout/Extra/GitToolkit/gitapi/gist.py +142 -0
  8. webscout/Extra/GitToolkit/gitapi/organization.py +91 -0
  9. webscout/Extra/GitToolkit/gitapi/repository.py +308 -195
  10. webscout/Extra/GitToolkit/gitapi/search.py +162 -0
  11. webscout/Extra/GitToolkit/gitapi/trending.py +236 -0
  12. webscout/Extra/GitToolkit/gitapi/user.py +128 -96
  13. webscout/Extra/GitToolkit/gitapi/utils.py +82 -62
  14. webscout/Extra/YTToolkit/README.md +443 -375
  15. webscout/Extra/YTToolkit/YTdownloader.py +953 -957
  16. webscout/Extra/YTToolkit/__init__.py +3 -3
  17. webscout/Extra/YTToolkit/transcriber.py +595 -476
  18. webscout/Extra/YTToolkit/ytapi/README.md +230 -44
  19. webscout/Extra/YTToolkit/ytapi/__init__.py +22 -6
  20. webscout/Extra/YTToolkit/ytapi/captions.py +190 -0
  21. webscout/Extra/YTToolkit/ytapi/channel.py +302 -307
  22. webscout/Extra/YTToolkit/ytapi/errors.py +13 -13
  23. webscout/Extra/YTToolkit/ytapi/extras.py +178 -118
  24. webscout/Extra/YTToolkit/ytapi/hashtag.py +120 -0
  25. webscout/Extra/YTToolkit/ytapi/https.py +89 -88
  26. webscout/Extra/YTToolkit/ytapi/patterns.py +61 -61
  27. webscout/Extra/YTToolkit/ytapi/playlist.py +59 -59
  28. webscout/Extra/YTToolkit/ytapi/pool.py +8 -8
  29. webscout/Extra/YTToolkit/ytapi/query.py +143 -40
  30. webscout/Extra/YTToolkit/ytapi/shorts.py +122 -0
  31. webscout/Extra/YTToolkit/ytapi/stream.py +68 -63
  32. webscout/Extra/YTToolkit/ytapi/suggestions.py +97 -0
  33. webscout/Extra/YTToolkit/ytapi/utils.py +66 -62
  34. webscout/Extra/YTToolkit/ytapi/video.py +403 -232
  35. webscout/Extra/__init__.py +2 -3
  36. webscout/Extra/gguf.py +1298 -684
  37. webscout/Extra/tempmail/README.md +487 -487
  38. webscout/Extra/tempmail/__init__.py +28 -28
  39. webscout/Extra/tempmail/async_utils.py +143 -141
  40. webscout/Extra/tempmail/base.py +172 -161
  41. webscout/Extra/tempmail/cli.py +191 -187
  42. webscout/Extra/tempmail/emailnator.py +88 -84
  43. webscout/Extra/tempmail/mail_tm.py +378 -361
  44. webscout/Extra/tempmail/temp_mail_io.py +304 -292
  45. webscout/Extra/weather.py +196 -194
  46. webscout/Extra/weather_ascii.py +17 -15
  47. webscout/Provider/AISEARCH/PERPLEXED_search.py +175 -0
  48. webscout/Provider/AISEARCH/Perplexity.py +292 -333
  49. webscout/Provider/AISEARCH/README.md +106 -279
  50. webscout/Provider/AISEARCH/__init__.py +16 -9
  51. webscout/Provider/AISEARCH/brave_search.py +298 -0
  52. webscout/Provider/AISEARCH/iask_search.py +357 -410
  53. webscout/Provider/AISEARCH/monica_search.py +200 -220
  54. webscout/Provider/AISEARCH/webpilotai_search.py +242 -255
  55. webscout/Provider/Algion.py +413 -0
  56. webscout/Provider/Andi.py +74 -69
  57. webscout/Provider/Apriel.py +313 -0
  58. webscout/Provider/Ayle.py +323 -0
  59. webscout/Provider/ChatSandbox.py +329 -342
  60. webscout/Provider/ClaudeOnline.py +365 -0
  61. webscout/Provider/Cohere.py +232 -208
  62. webscout/Provider/DeepAI.py +367 -0
  63. webscout/Provider/Deepinfra.py +467 -340
  64. webscout/Provider/EssentialAI.py +217 -0
  65. webscout/Provider/ExaAI.py +274 -261
  66. webscout/Provider/Gemini.py +175 -169
  67. webscout/Provider/GithubChat.py +385 -369
  68. webscout/Provider/Gradient.py +286 -0
  69. webscout/Provider/Groq.py +556 -801
  70. webscout/Provider/HadadXYZ.py +323 -0
  71. webscout/Provider/HeckAI.py +392 -375
  72. webscout/Provider/HuggingFace.py +387 -0
  73. webscout/Provider/IBM.py +340 -0
  74. webscout/Provider/Jadve.py +317 -291
  75. webscout/Provider/K2Think.py +306 -0
  76. webscout/Provider/Koboldai.py +221 -384
  77. webscout/Provider/Netwrck.py +273 -270
  78. webscout/Provider/Nvidia.py +310 -0
  79. webscout/Provider/OPENAI/DeepAI.py +489 -0
  80. webscout/Provider/OPENAI/K2Think.py +423 -0
  81. webscout/Provider/OPENAI/PI.py +463 -0
  82. webscout/Provider/OPENAI/README.md +890 -952
  83. webscout/Provider/OPENAI/TogetherAI.py +405 -0
  84. webscout/Provider/OPENAI/TwoAI.py +255 -357
  85. webscout/Provider/OPENAI/__init__.py +148 -40
  86. webscout/Provider/OPENAI/ai4chat.py +348 -293
  87. webscout/Provider/OPENAI/akashgpt.py +436 -0
  88. webscout/Provider/OPENAI/algion.py +303 -0
  89. webscout/Provider/OPENAI/{exachat.py → ayle.py} +365 -444
  90. webscout/Provider/OPENAI/base.py +253 -249
  91. webscout/Provider/OPENAI/cerebras.py +296 -0
  92. webscout/Provider/OPENAI/chatgpt.py +870 -556
  93. webscout/Provider/OPENAI/chatsandbox.py +233 -173
  94. webscout/Provider/OPENAI/deepinfra.py +403 -322
  95. webscout/Provider/OPENAI/e2b.py +2370 -1414
  96. webscout/Provider/OPENAI/elmo.py +278 -0
  97. webscout/Provider/OPENAI/exaai.py +452 -417
  98. webscout/Provider/OPENAI/freeassist.py +446 -0
  99. webscout/Provider/OPENAI/gradient.py +448 -0
  100. webscout/Provider/OPENAI/groq.py +380 -364
  101. webscout/Provider/OPENAI/hadadxyz.py +292 -0
  102. webscout/Provider/OPENAI/heckai.py +333 -308
  103. webscout/Provider/OPENAI/huggingface.py +321 -0
  104. webscout/Provider/OPENAI/ibm.py +425 -0
  105. webscout/Provider/OPENAI/llmchat.py +253 -0
  106. webscout/Provider/OPENAI/llmchatco.py +378 -335
  107. webscout/Provider/OPENAI/meta.py +541 -0
  108. webscout/Provider/OPENAI/netwrck.py +374 -357
  109. webscout/Provider/OPENAI/nvidia.py +317 -0
  110. webscout/Provider/OPENAI/oivscode.py +348 -287
  111. webscout/Provider/OPENAI/openrouter.py +328 -0
  112. webscout/Provider/OPENAI/pydantic_imports.py +1 -172
  113. webscout/Provider/OPENAI/sambanova.py +397 -0
  114. webscout/Provider/OPENAI/sonus.py +305 -304
  115. webscout/Provider/OPENAI/textpollinations.py +370 -339
  116. webscout/Provider/OPENAI/toolbaz.py +375 -413
  117. webscout/Provider/OPENAI/typefully.py +419 -355
  118. webscout/Provider/OPENAI/typliai.py +279 -0
  119. webscout/Provider/OPENAI/utils.py +314 -318
  120. webscout/Provider/OPENAI/wisecat.py +359 -387
  121. webscout/Provider/OPENAI/writecream.py +185 -163
  122. webscout/Provider/OPENAI/x0gpt.py +462 -365
  123. webscout/Provider/OPENAI/zenmux.py +380 -0
  124. webscout/Provider/OpenRouter.py +386 -0
  125. webscout/Provider/Openai.py +337 -496
  126. webscout/Provider/PI.py +443 -429
  127. webscout/Provider/QwenLM.py +346 -254
  128. webscout/Provider/STT/__init__.py +28 -0
  129. webscout/Provider/STT/base.py +303 -0
  130. webscout/Provider/STT/elevenlabs.py +264 -0
  131. webscout/Provider/Sambanova.py +317 -0
  132. webscout/Provider/TTI/README.md +69 -82
  133. webscout/Provider/TTI/__init__.py +37 -7
  134. webscout/Provider/TTI/base.py +147 -64
  135. webscout/Provider/TTI/claudeonline.py +393 -0
  136. webscout/Provider/TTI/magicstudio.py +292 -201
  137. webscout/Provider/TTI/miragic.py +180 -0
  138. webscout/Provider/TTI/pollinations.py +331 -221
  139. webscout/Provider/TTI/together.py +334 -0
  140. webscout/Provider/TTI/utils.py +14 -11
  141. webscout/Provider/TTS/README.md +186 -192
  142. webscout/Provider/TTS/__init__.py +43 -10
  143. webscout/Provider/TTS/base.py +523 -159
  144. webscout/Provider/TTS/deepgram.py +286 -156
  145. webscout/Provider/TTS/elevenlabs.py +189 -111
  146. webscout/Provider/TTS/freetts.py +218 -0
  147. webscout/Provider/TTS/murfai.py +288 -113
  148. webscout/Provider/TTS/openai_fm.py +364 -129
  149. webscout/Provider/TTS/parler.py +203 -111
  150. webscout/Provider/TTS/qwen.py +334 -0
  151. webscout/Provider/TTS/sherpa.py +286 -0
  152. webscout/Provider/TTS/speechma.py +693 -580
  153. webscout/Provider/TTS/streamElements.py +275 -333
  154. webscout/Provider/TTS/utils.py +280 -280
  155. webscout/Provider/TextPollinationsAI.py +331 -308
  156. webscout/Provider/TogetherAI.py +450 -0
  157. webscout/Provider/TwoAI.py +309 -475
  158. webscout/Provider/TypliAI.py +311 -305
  159. webscout/Provider/UNFINISHED/ChatHub.py +219 -209
  160. webscout/Provider/{OPENAI/glider.py → UNFINISHED/ChutesAI.py} +331 -326
  161. webscout/Provider/{GizAI.py → UNFINISHED/GizAI.py} +300 -295
  162. webscout/Provider/{Marcus.py → UNFINISHED/Marcus.py} +218 -198
  163. webscout/Provider/UNFINISHED/Qodo.py +481 -0
  164. webscout/Provider/{MCPCore.py → UNFINISHED/XenAI.py} +330 -315
  165. webscout/Provider/UNFINISHED/Youchat.py +347 -330
  166. webscout/Provider/UNFINISHED/aihumanizer.py +41 -0
  167. webscout/Provider/UNFINISHED/grammerchecker.py +37 -0
  168. webscout/Provider/UNFINISHED/liner.py +342 -0
  169. webscout/Provider/UNFINISHED/liner_api_request.py +246 -263
  170. webscout/Provider/{samurai.py → UNFINISHED/samurai.py} +231 -224
  171. webscout/Provider/WiseCat.py +256 -233
  172. webscout/Provider/WrDoChat.py +390 -370
  173. webscout/Provider/__init__.py +115 -174
  174. webscout/Provider/ai4chat.py +181 -174
  175. webscout/Provider/akashgpt.py +330 -335
  176. webscout/Provider/cerebras.py +397 -290
  177. webscout/Provider/cleeai.py +236 -213
  178. webscout/Provider/elmo.py +291 -283
  179. webscout/Provider/geminiapi.py +343 -208
  180. webscout/Provider/julius.py +245 -223
  181. webscout/Provider/learnfastai.py +333 -325
  182. webscout/Provider/llama3mitril.py +230 -215
  183. webscout/Provider/llmchat.py +308 -258
  184. webscout/Provider/llmchatco.py +321 -306
  185. webscout/Provider/meta.py +996 -801
  186. webscout/Provider/oivscode.py +332 -309
  187. webscout/Provider/searchchat.py +316 -292
  188. webscout/Provider/sonus.py +264 -258
  189. webscout/Provider/toolbaz.py +359 -353
  190. webscout/Provider/turboseek.py +332 -266
  191. webscout/Provider/typefully.py +262 -202
  192. webscout/Provider/x0gpt.py +332 -299
  193. webscout/__init__.py +31 -39
  194. webscout/__main__.py +5 -5
  195. webscout/cli.py +585 -524
  196. webscout/client.py +1497 -70
  197. webscout/conversation.py +140 -436
  198. webscout/exceptions.py +383 -362
  199. webscout/litagent/__init__.py +29 -29
  200. webscout/litagent/agent.py +492 -455
  201. webscout/litagent/constants.py +60 -60
  202. webscout/models.py +505 -181
  203. webscout/optimizers.py +74 -420
  204. webscout/prompt_manager.py +376 -288
  205. webscout/sanitize.py +1514 -0
  206. webscout/scout/README.md +452 -404
  207. webscout/scout/__init__.py +8 -8
  208. webscout/scout/core/__init__.py +7 -7
  209. webscout/scout/core/crawler.py +330 -210
  210. webscout/scout/core/scout.py +800 -607
  211. webscout/scout/core/search_result.py +51 -96
  212. webscout/scout/core/text_analyzer.py +64 -63
  213. webscout/scout/core/text_utils.py +412 -277
  214. webscout/scout/core/web_analyzer.py +54 -52
  215. webscout/scout/element.py +872 -478
  216. webscout/scout/parsers/__init__.py +70 -69
  217. webscout/scout/parsers/html5lib_parser.py +182 -172
  218. webscout/scout/parsers/html_parser.py +238 -236
  219. webscout/scout/parsers/lxml_parser.py +203 -178
  220. webscout/scout/utils.py +38 -37
  221. webscout/search/__init__.py +47 -0
  222. webscout/search/base.py +201 -0
  223. webscout/search/bing_main.py +45 -0
  224. webscout/search/brave_main.py +92 -0
  225. webscout/search/duckduckgo_main.py +57 -0
  226. webscout/search/engines/__init__.py +127 -0
  227. webscout/search/engines/bing/__init__.py +15 -0
  228. webscout/search/engines/bing/base.py +35 -0
  229. webscout/search/engines/bing/images.py +114 -0
  230. webscout/search/engines/bing/news.py +96 -0
  231. webscout/search/engines/bing/suggestions.py +36 -0
  232. webscout/search/engines/bing/text.py +109 -0
  233. webscout/search/engines/brave/__init__.py +19 -0
  234. webscout/search/engines/brave/base.py +47 -0
  235. webscout/search/engines/brave/images.py +213 -0
  236. webscout/search/engines/brave/news.py +353 -0
  237. webscout/search/engines/brave/suggestions.py +318 -0
  238. webscout/search/engines/brave/text.py +167 -0
  239. webscout/search/engines/brave/videos.py +364 -0
  240. webscout/search/engines/duckduckgo/__init__.py +25 -0
  241. webscout/search/engines/duckduckgo/answers.py +80 -0
  242. webscout/search/engines/duckduckgo/base.py +189 -0
  243. webscout/search/engines/duckduckgo/images.py +100 -0
  244. webscout/search/engines/duckduckgo/maps.py +183 -0
  245. webscout/search/engines/duckduckgo/news.py +70 -0
  246. webscout/search/engines/duckduckgo/suggestions.py +22 -0
  247. webscout/search/engines/duckduckgo/text.py +221 -0
  248. webscout/search/engines/duckduckgo/translate.py +48 -0
  249. webscout/search/engines/duckduckgo/videos.py +80 -0
  250. webscout/search/engines/duckduckgo/weather.py +84 -0
  251. webscout/search/engines/mojeek.py +61 -0
  252. webscout/search/engines/wikipedia.py +77 -0
  253. webscout/search/engines/yahoo/__init__.py +41 -0
  254. webscout/search/engines/yahoo/answers.py +19 -0
  255. webscout/search/engines/yahoo/base.py +34 -0
  256. webscout/search/engines/yahoo/images.py +323 -0
  257. webscout/search/engines/yahoo/maps.py +19 -0
  258. webscout/search/engines/yahoo/news.py +258 -0
  259. webscout/search/engines/yahoo/suggestions.py +140 -0
  260. webscout/search/engines/yahoo/text.py +273 -0
  261. webscout/search/engines/yahoo/translate.py +19 -0
  262. webscout/search/engines/yahoo/videos.py +302 -0
  263. webscout/search/engines/yahoo/weather.py +220 -0
  264. webscout/search/engines/yandex.py +67 -0
  265. webscout/search/engines/yep/__init__.py +13 -0
  266. webscout/search/engines/yep/base.py +34 -0
  267. webscout/search/engines/yep/images.py +101 -0
  268. webscout/search/engines/yep/suggestions.py +38 -0
  269. webscout/search/engines/yep/text.py +99 -0
  270. webscout/search/http_client.py +172 -0
  271. webscout/search/results.py +141 -0
  272. webscout/search/yahoo_main.py +57 -0
  273. webscout/search/yep_main.py +48 -0
  274. webscout/server/__init__.py +48 -0
  275. webscout/server/config.py +78 -0
  276. webscout/server/exceptions.py +69 -0
  277. webscout/server/providers.py +286 -0
  278. webscout/server/request_models.py +131 -0
  279. webscout/server/request_processing.py +404 -0
  280. webscout/server/routes.py +642 -0
  281. webscout/server/server.py +351 -0
  282. webscout/server/ui_templates.py +1171 -0
  283. webscout/swiftcli/__init__.py +79 -95
  284. webscout/swiftcli/core/__init__.py +7 -7
  285. webscout/swiftcli/core/cli.py +574 -297
  286. webscout/swiftcli/core/context.py +98 -104
  287. webscout/swiftcli/core/group.py +268 -241
  288. webscout/swiftcli/decorators/__init__.py +28 -28
  289. webscout/swiftcli/decorators/command.py +243 -221
  290. webscout/swiftcli/decorators/options.py +247 -220
  291. webscout/swiftcli/decorators/output.py +392 -252
  292. webscout/swiftcli/exceptions.py +21 -21
  293. webscout/swiftcli/plugins/__init__.py +9 -9
  294. webscout/swiftcli/plugins/base.py +134 -135
  295. webscout/swiftcli/plugins/manager.py +269 -269
  296. webscout/swiftcli/utils/__init__.py +58 -59
  297. webscout/swiftcli/utils/formatting.py +251 -252
  298. webscout/swiftcli/utils/parsing.py +368 -267
  299. webscout/update_checker.py +280 -136
  300. webscout/utils.py +28 -14
  301. webscout/version.py +2 -1
  302. webscout/version.py.bak +3 -0
  303. webscout/zeroart/__init__.py +218 -135
  304. webscout/zeroart/base.py +70 -66
  305. webscout/zeroart/effects.py +155 -101
  306. webscout/zeroart/fonts.py +1799 -1239
  307. webscout-2026.1.19.dist-info/METADATA +638 -0
  308. webscout-2026.1.19.dist-info/RECORD +312 -0
  309. {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/WHEEL +1 -1
  310. {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/entry_points.txt +1 -1
  311. webscout/DWEBS.py +0 -520
  312. webscout/Extra/Act.md +0 -309
  313. webscout/Extra/GitToolkit/gitapi/README.md +0 -110
  314. webscout/Extra/autocoder/__init__.py +0 -9
  315. webscout/Extra/autocoder/autocoder.py +0 -1105
  316. webscout/Extra/autocoder/autocoder_utiles.py +0 -332
  317. webscout/Extra/gguf.md +0 -430
  318. webscout/Extra/weather.md +0 -281
  319. webscout/Litlogger/README.md +0 -10
  320. webscout/Litlogger/__init__.py +0 -15
  321. webscout/Litlogger/formats.py +0 -4
  322. webscout/Litlogger/handlers.py +0 -103
  323. webscout/Litlogger/levels.py +0 -13
  324. webscout/Litlogger/logger.py +0 -92
  325. webscout/Provider/AI21.py +0 -177
  326. webscout/Provider/AISEARCH/DeepFind.py +0 -254
  327. webscout/Provider/AISEARCH/felo_search.py +0 -202
  328. webscout/Provider/AISEARCH/genspark_search.py +0 -324
  329. webscout/Provider/AISEARCH/hika_search.py +0 -186
  330. webscout/Provider/AISEARCH/scira_search.py +0 -298
  331. webscout/Provider/Aitopia.py +0 -316
  332. webscout/Provider/AllenAI.py +0 -440
  333. webscout/Provider/Blackboxai.py +0 -791
  334. webscout/Provider/ChatGPTClone.py +0 -237
  335. webscout/Provider/ChatGPTGratis.py +0 -194
  336. webscout/Provider/Cloudflare.py +0 -324
  337. webscout/Provider/ExaChat.py +0 -358
  338. webscout/Provider/Flowith.py +0 -217
  339. webscout/Provider/FreeGemini.py +0 -250
  340. webscout/Provider/Glider.py +0 -225
  341. webscout/Provider/HF_space/__init__.py +0 -0
  342. webscout/Provider/HF_space/qwen_qwen2.py +0 -206
  343. webscout/Provider/HuggingFaceChat.py +0 -469
  344. webscout/Provider/Hunyuan.py +0 -283
  345. webscout/Provider/LambdaChat.py +0 -411
  346. webscout/Provider/Llama3.py +0 -259
  347. webscout/Provider/Nemotron.py +0 -218
  348. webscout/Provider/OLLAMA.py +0 -396
  349. webscout/Provider/OPENAI/BLACKBOXAI.py +0 -766
  350. webscout/Provider/OPENAI/Cloudflare.py +0 -378
  351. webscout/Provider/OPENAI/FreeGemini.py +0 -283
  352. webscout/Provider/OPENAI/NEMOTRON.py +0 -232
  353. webscout/Provider/OPENAI/Qwen3.py +0 -283
  354. webscout/Provider/OPENAI/api.py +0 -969
  355. webscout/Provider/OPENAI/c4ai.py +0 -373
  356. webscout/Provider/OPENAI/chatgptclone.py +0 -494
  357. webscout/Provider/OPENAI/copilot.py +0 -242
  358. webscout/Provider/OPENAI/flowith.py +0 -162
  359. webscout/Provider/OPENAI/freeaichat.py +0 -359
  360. webscout/Provider/OPENAI/mcpcore.py +0 -389
  361. webscout/Provider/OPENAI/multichat.py +0 -376
  362. webscout/Provider/OPENAI/opkfc.py +0 -496
  363. webscout/Provider/OPENAI/scirachat.py +0 -477
  364. webscout/Provider/OPENAI/standardinput.py +0 -433
  365. webscout/Provider/OPENAI/typegpt.py +0 -364
  366. webscout/Provider/OPENAI/uncovrAI.py +0 -463
  367. webscout/Provider/OPENAI/venice.py +0 -431
  368. webscout/Provider/OPENAI/yep.py +0 -382
  369. webscout/Provider/OpenGPT.py +0 -209
  370. webscout/Provider/Perplexitylabs.py +0 -415
  371. webscout/Provider/Reka.py +0 -214
  372. webscout/Provider/StandardInput.py +0 -290
  373. webscout/Provider/TTI/aiarta.py +0 -365
  374. webscout/Provider/TTI/artbit.py +0 -0
  375. webscout/Provider/TTI/fastflux.py +0 -200
  376. webscout/Provider/TTI/piclumen.py +0 -203
  377. webscout/Provider/TTI/pixelmuse.py +0 -225
  378. webscout/Provider/TTS/gesserit.py +0 -128
  379. webscout/Provider/TTS/sthir.py +0 -94
  380. webscout/Provider/TeachAnything.py +0 -229
  381. webscout/Provider/UNFINISHED/puterjs.py +0 -635
  382. webscout/Provider/UNFINISHED/test_lmarena.py +0 -119
  383. webscout/Provider/Venice.py +0 -258
  384. webscout/Provider/VercelAI.py +0 -253
  385. webscout/Provider/Writecream.py +0 -246
  386. webscout/Provider/WritingMate.py +0 -269
  387. webscout/Provider/asksteve.py +0 -220
  388. webscout/Provider/chatglm.py +0 -215
  389. webscout/Provider/copilot.py +0 -425
  390. webscout/Provider/freeaichat.py +0 -285
  391. webscout/Provider/granite.py +0 -235
  392. webscout/Provider/hermes.py +0 -266
  393. webscout/Provider/koala.py +0 -170
  394. webscout/Provider/lmarena.py +0 -198
  395. webscout/Provider/multichat.py +0 -364
  396. webscout/Provider/scira_chat.py +0 -299
  397. webscout/Provider/scnet.py +0 -243
  398. webscout/Provider/talkai.py +0 -194
  399. webscout/Provider/typegpt.py +0 -289
  400. webscout/Provider/uncovr.py +0 -368
  401. webscout/Provider/yep.py +0 -389
  402. webscout/litagent/Readme.md +0 -276
  403. webscout/litprinter/__init__.py +0 -59
  404. webscout/swiftcli/Readme.md +0 -323
  405. webscout/tempid.py +0 -128
  406. webscout/webscout_search.py +0 -1184
  407. webscout/webscout_search_async.py +0 -654
  408. webscout/yep_search.py +0 -347
  409. webscout/zeroart/README.md +0 -89
  410. webscout-8.2.9.dist-info/METADATA +0 -1033
  411. webscout-8.2.9.dist-info/RECORD +0 -289
  412. {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/licenses/LICENSE.md +0 -0
  413. {webscout-8.2.9.dist-info → webscout-2026.1.19.dist-info}/top_level.txt +0 -0
@@ -1,1184 +0,0 @@
1
- from __future__ import annotations
2
-
3
- # import logging
4
- import json
5
- from urllib.parse import quote
6
- import warnings
7
- from concurrent.futures import ThreadPoolExecutor
8
- from datetime import datetime, timezone
9
- from decimal import Decimal
10
- from functools import cached_property
11
- from itertools import cycle, islice
12
- from random import choice, shuffle
13
- from threading import Event
14
- from time import sleep, time
15
- from types import TracebackType
16
- from typing import Any, cast
17
- import os
18
- from typing import Literal, Iterator
19
-
20
- import curl_cffi.requests # type: ignore
21
-
22
- try:
23
- from lxml.etree import _Element
24
- from lxml.html import HTMLParser as LHTMLParser
25
- from lxml.html import document_fromstring
26
-
27
- LXML_AVAILABLE = True
28
- except ImportError:
29
- LXML_AVAILABLE = False
30
-
31
- from .exceptions import ConversationLimitException, WebscoutE, RatelimitE, TimeoutE
32
- from .utils import (
33
- _calculate_distance,
34
- _expand_proxy_tb_alias,
35
- _extract_vqd,
36
- _normalize,
37
- _normalize_url,
38
- _text_extract_json,
39
- json_loads,
40
- )
41
-
42
- # logger = logging.getLogger("webscout.WEBS")
43
-
44
-
45
- class WEBS:
46
- """webscout class to get search results from duckduckgo.com."""
47
-
48
- _executor: ThreadPoolExecutor = ThreadPoolExecutor()
49
- # curl_cffi supports different browser versions than primp
50
- _impersonates = (
51
- "chrome99", "chrome100", "chrome101", "chrome104", "chrome107", "chrome110",
52
- "chrome116", "chrome119", "chrome120", "chrome123", "chrome124", "chrome131", "chrome133a",
53
- "chrome99_android", "chrome131_android",
54
- "safari15_3", "safari15_5", "safari17_0", "safari17_2_ios", "safari18_0", "safari18_0_ios",
55
- "edge99", "edge101",
56
- "firefox133", "firefox135",
57
- ) # fmt: skip
58
- _impersonates_os = ("android", "ios", "linux", "macos", "windows")
59
-
60
-
61
- def __init__(
62
- self,
63
- headers: dict[str, str] | None = None,
64
- proxy: str | None = None,
65
- proxies: dict[str, str] | str | None = None, # deprecated
66
- timeout: int | None = 10,
67
- verify: bool = True,
68
- ) -> None:
69
- """Initialize the WEBS object.
70
-
71
- Args:
72
- headers (dict, optional): Dictionary of headers for the HTTP client. Defaults to None.
73
- proxy (str, optional): proxy for the HTTP client, supports http/https/socks5 protocols.
74
- example: "http://user:pass@example.com:3128". Defaults to None.
75
- timeout (int, optional): Timeout value for the HTTP client. Defaults to 10.
76
- verify (bool): SSL verification when making the request. Defaults to True.
77
- """
78
- ddgs_proxy: str | None = os.environ.get("DDGS_PROXY")
79
- self.proxy: str | None = ddgs_proxy if ddgs_proxy else _expand_proxy_tb_alias(proxy)
80
- assert self.proxy is None or isinstance(self.proxy, str), "proxy must be a str"
81
- if not proxy and proxies:
82
- warnings.warn("'proxies' is deprecated, use 'proxy' instead.", stacklevel=1)
83
- self.proxy = proxies.get("http") or proxies.get("https") if isinstance(proxies, dict) else proxies
84
-
85
- default_headers = {
86
- "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
87
- "Accept-Language": "en-US,en;q=0.5",
88
- "Accept-Encoding": "gzip, deflate, br",
89
- "DNT": "1",
90
- "Connection": "keep-alive",
91
- "Upgrade-Insecure-Requests": "1",
92
- "Sec-Fetch-Dest": "document",
93
- "Sec-Fetch-Mode": "navigate",
94
- "Sec-Fetch-Site": "none",
95
- "Sec-Fetch-User": "?1",
96
- "Referer": "https://duckduckgo.com/",
97
- }
98
-
99
- self.headers = headers if headers else {}
100
- self.headers.update(default_headers)
101
-
102
- # curl_cffi has different parameters than primp
103
- impersonate_browser = choice(self._impersonates)
104
- self.client = curl_cffi.requests.Session(
105
- headers=self.headers,
106
- proxies={'http': self.proxy, 'https': self.proxy} if self.proxy else None,
107
- timeout=timeout,
108
- # curl_cffi doesn't accept cookies=True, it needs a dict or None
109
- impersonate=impersonate_browser,
110
- verify=verify,
111
- )
112
- self.timeout = timeout
113
- self.sleep_timestamp = 0.0
114
-
115
- self._exception_event = Event()
116
-
117
- def __enter__(self) -> WEBS:
118
- return self
119
-
120
- def __exit__(
121
- self,
122
- exc_type: type[BaseException] | None = None,
123
- exc_val: BaseException | None = None,
124
- exc_tb: TracebackType | None = None,
125
- ) -> None:
126
- pass
127
-
128
- @cached_property
129
- def parser(self) -> LHTMLParser:
130
- """Get HTML parser."""
131
- return LHTMLParser(remove_blank_text=True, remove_comments=True, remove_pis=True, collect_ids=False)
132
-
133
- def _sleep(self, sleeptime: float = 0.75) -> None:
134
- """Sleep between API requests."""
135
- delay = 0.0 if not self.sleep_timestamp else 0.0 if time() - self.sleep_timestamp >= 20 else sleeptime
136
- self.sleep_timestamp = time()
137
- sleep(delay)
138
-
139
- def _get_url(
140
- self,
141
- method: Literal["GET", "HEAD", "OPTIONS", "DELETE", "POST", "PUT", "PATCH"],
142
- url: str,
143
- params: dict[str, str] | None = None,
144
- content: bytes | None = None,
145
- data: dict[str, str] | None = None,
146
- headers: dict[str, str] | None = None,
147
- cookies: dict[str, str] | None = None,
148
- json: Any = None,
149
- timeout: float | None = None,
150
- ) -> Any:
151
- self._sleep()
152
- try:
153
- # curl_cffi doesn't accept cookies=True in request methods
154
- request_kwargs = {
155
- "params": params,
156
- "headers": headers,
157
- "json": json,
158
- "timeout": timeout or self.timeout,
159
- }
160
-
161
- # Add cookies if they're a dict, not a bool
162
- if isinstance(cookies, dict):
163
- request_kwargs["cookies"] = cookies
164
-
165
- if method == "GET":
166
- # curl_cffi uses data instead of content
167
- if content:
168
- request_kwargs["data"] = content
169
- resp = self.client.get(url, **request_kwargs)
170
- elif method == "POST":
171
- # handle both data and content
172
- if data or content:
173
- request_kwargs["data"] = data or content
174
- resp = self.client.post(url, **request_kwargs)
175
- else:
176
- # handle both data and content
177
- if data or content:
178
- request_kwargs["data"] = data or content
179
- resp = self.client.request(method, url, **request_kwargs)
180
- except Exception as ex:
181
- if "time" in str(ex).lower():
182
- raise TimeoutE(f"{url} {type(ex).__name__}: {ex}") from ex
183
- raise WebscoutE(f"{url} {type(ex).__name__}: {ex}") from ex
184
- if resp.status_code == 200:
185
- return resp
186
- elif resp.status_code in (202, 301, 403, 400, 429, 418):
187
- raise RatelimitE(f"{resp.url} {resp.status_code} Ratelimit")
188
- raise WebscoutE(f"{resp.url} return None. {params=} {content=} {data=}")
189
-
190
- def _get_vqd(self, keywords: str) -> str:
191
- """Get vqd value for a search query."""
192
- resp_content = self._get_url("GET", "https://duckduckgo.com", params={"q": keywords}).content
193
- return _extract_vqd(resp_content, keywords)
194
-
195
-
196
-
197
- def text(
198
- self,
199
- keywords: str,
200
- region: str = "wt-wt",
201
- safesearch: str = "moderate",
202
- timelimit: str | None = None,
203
- backend: str = "auto",
204
- max_results: int | None = None,
205
- ) -> list[dict[str, str]]:
206
- """webscout text search. Query params: https://duckduckgo.com/params.
207
-
208
- Args:
209
- keywords: keywords for query.
210
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
211
- safesearch: on, moderate, off. Defaults to "moderate".
212
- timelimit: d, w, m, y. Defaults to None.
213
- backend: auto, html, lite. Defaults to auto.
214
- auto - try all backends in random order,
215
- html - collect data from https://html.duckduckgo.com,
216
- lite - collect data from https://lite.duckduckgo.com.
217
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
218
-
219
- Returns:
220
- List of dictionaries with search results.
221
-
222
- Raises:
223
- WebscoutE: Base exception for webscout errors.
224
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
225
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
226
- """
227
- if backend in ("api", "ecosia"):
228
- warnings.warn(f"{backend=} is deprecated, using backend='auto'", stacklevel=2)
229
- backend = "auto"
230
- backends = ["html", "lite"] if backend == "auto" else [backend]
231
- shuffle(backends)
232
-
233
- results, err = [], None
234
- for b in backends:
235
- try:
236
- if b == "html":
237
- results = self._text_html(keywords, region, timelimit, max_results)
238
- elif b == "lite":
239
- results = self._text_lite(keywords, region, timelimit, max_results)
240
- return results
241
- except Exception as ex:
242
- err = ex
243
-
244
- raise WebscoutE(err)
245
-
246
- def _text_api(
247
- self,
248
- keywords: str,
249
- region: str = "wt-wt",
250
- safesearch: str = "moderate",
251
- timelimit: str | None = None,
252
- max_results: int | None = None,
253
- ) -> list[dict[str, str]]:
254
- """webscout text search. Query params: https://duckduckgo.com/params.
255
-
256
- Args:
257
- keywords: keywords for query.
258
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
259
- safesearch: on, moderate, off. Defaults to "moderate".
260
- timelimit: d, w, m, y. Defaults to None.
261
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
262
-
263
- Returns:
264
- List of dictionaries with search results.
265
-
266
- Raises:
267
- WebscoutE: Base exception for webscout errors.
268
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
269
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
270
- """
271
- assert keywords, "keywords is mandatory"
272
-
273
- vqd = self._get_vqd(keywords)
274
-
275
- payload = {
276
- "q": keywords,
277
- "kl": region,
278
- "l": region,
279
- "p": "",
280
- "s": "0",
281
- "df": "",
282
- "vqd": vqd,
283
- "bing_market": f"{region[3:]}-{region[:2].upper()}",
284
- "ex": "",
285
- }
286
- safesearch = safesearch.lower()
287
- if safesearch == "moderate":
288
- payload["ex"] = "-1"
289
- elif safesearch == "off":
290
- payload["ex"] = "-2"
291
- elif safesearch == "on": # strict
292
- payload["p"] = "1"
293
- if timelimit:
294
- payload["df"] = timelimit
295
-
296
- cache = set()
297
- results: list[dict[str, str]] = []
298
-
299
- def _text_api_page(s: int) -> list[dict[str, str]]:
300
- payload["s"] = f"{s}"
301
- resp_content = self._get_url("GET", "https://links.duckduckgo.com/d.js", params=payload).content
302
- page_data = _text_extract_json(resp_content, keywords)
303
- page_results = []
304
- for row in page_data:
305
- href = row.get("u", None)
306
- if href and href not in cache and href != f"http://www.google.com/search?q={keywords}":
307
- cache.add(href)
308
- body = _normalize(row["a"])
309
- if body:
310
- result = {
311
- "title": _normalize(row["t"]),
312
- "href": _normalize_url(href),
313
- "body": body,
314
- }
315
- page_results.append(result)
316
- return page_results
317
-
318
- slist = [0]
319
- if max_results:
320
- max_results = min(max_results, 2023)
321
- slist.extend(range(23, max_results, 50))
322
- try:
323
- for r in self._executor.map(_text_api_page, slist):
324
- results.extend(r)
325
- except Exception as e:
326
- raise e
327
-
328
- return list(islice(results, max_results))
329
-
330
- def _text_html(
331
- self,
332
- keywords: str,
333
- region: str = "wt-wt",
334
- timelimit: str | None = None,
335
- max_results: int | None = None,
336
- ) -> list[dict[str, str]]:
337
- """webscout text search. Query params: https://duckduckgo.com/params.
338
-
339
- Args:
340
- keywords: keywords for query.
341
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
342
- timelimit: d, w, m, y. Defaults to None.
343
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
344
-
345
- Returns:
346
- List of dictionaries with search results.
347
-
348
- Raises:
349
- WebscoutE: Base exception for webscout errors.
350
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
351
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
352
- """
353
- assert keywords, "keywords is mandatory"
354
-
355
- payload = {
356
- "q": keywords,
357
- "s": "0",
358
- "o": "json",
359
- "api": "d.js",
360
- "vqd": "",
361
- "kl": region,
362
- "bing_market": region,
363
- }
364
- if timelimit:
365
- payload["df"] = timelimit
366
- if max_results and max_results > 20:
367
- vqd = self._get_vqd(keywords)
368
- payload["vqd"] = vqd
369
-
370
- cache = set()
371
- results: list[dict[str, str]] = []
372
-
373
- def _text_html_page(s: int) -> list[dict[str, str]]:
374
- payload["s"] = f"{s}"
375
- resp_content = self._get_url("POST", "https://html.duckduckgo.com/html", data=payload).content
376
- if b"No results." in resp_content:
377
- return []
378
-
379
- page_results = []
380
- # curl_cffi returns bytes, not a file-like object
381
- tree = document_fromstring(resp_content)
382
- elements = tree.xpath("//div[h2]")
383
- if not isinstance(elements, list):
384
- return []
385
- for e in elements:
386
- if isinstance(e, _Element):
387
- hrefxpath = e.xpath("./a/@href")
388
- href = str(hrefxpath[0]) if hrefxpath and isinstance(hrefxpath, list) else None
389
- if (
390
- href
391
- and href not in cache
392
- and not href.startswith(
393
- ("http://www.google.com/search?q=", "https://duckduckgo.com/y.js?ad_domain")
394
- )
395
- ):
396
- cache.add(href)
397
- titlexpath = e.xpath("./h2/a/text()")
398
- title = str(titlexpath[0]) if titlexpath and isinstance(titlexpath, list) else ""
399
- bodyxpath = e.xpath("./a//text()")
400
- body = "".join(str(x) for x in bodyxpath) if bodyxpath and isinstance(bodyxpath, list) else ""
401
- result = {
402
- "title": _normalize(title),
403
- "href": _normalize_url(href),
404
- "body": _normalize(body),
405
- }
406
- page_results.append(result)
407
- return page_results
408
-
409
- slist = [0]
410
- if max_results:
411
- max_results = min(max_results, 2023)
412
- slist.extend(range(23, max_results, 50))
413
- try:
414
- for r in self._executor.map(_text_html_page, slist):
415
- results.extend(r)
416
- except Exception as e:
417
- raise e
418
-
419
- return list(islice(results, max_results))
420
-
421
- def _text_lite(
422
- self,
423
- keywords: str,
424
- region: str = "wt-wt",
425
- timelimit: str | None = None,
426
- max_results: int | None = None,
427
- ) -> list[dict[str, str]]:
428
- """webscout text search. Query params: https://duckduckgo.com/params.
429
-
430
- Args:
431
- keywords: keywords for query.
432
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
433
- timelimit: d, w, m, y. Defaults to None.
434
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
435
-
436
- Returns:
437
- List of dictionaries with search results.
438
-
439
- Raises:
440
- WebscoutE: Base exception for webscout errors.
441
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
442
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
443
- """
444
- assert keywords, "keywords is mandatory"
445
-
446
- payload = {
447
- "q": keywords,
448
- "s": "0",
449
- "o": "json",
450
- "api": "d.js",
451
- "vqd": "",
452
- "kl": region,
453
- "bing_market": region,
454
- }
455
- if timelimit:
456
- payload["df"] = timelimit
457
-
458
- cache = set()
459
- results: list[dict[str, str]] = []
460
-
461
- def _text_lite_page(s: int) -> list[dict[str, str]]:
462
- payload["s"] = f"{s}"
463
- resp_content = self._get_url("POST", "https://lite.duckduckgo.com/lite/", data=payload).content
464
- if b"No more results." in resp_content:
465
- return []
466
-
467
- page_results = []
468
- # curl_cffi returns bytes, not a file-like object
469
- tree = document_fromstring(resp_content)
470
- elements = tree.xpath("//table[last()]//tr")
471
- if not isinstance(elements, list):
472
- return []
473
-
474
- data = zip(cycle(range(1, 5)), elements)
475
- for i, e in data:
476
- if isinstance(e, _Element):
477
- if i == 1:
478
- hrefxpath = e.xpath(".//a//@href")
479
- href = str(hrefxpath[0]) if hrefxpath and isinstance(hrefxpath, list) else None
480
- if (
481
- href is None
482
- or href in cache
483
- or href.startswith(
484
- ("http://www.google.com/search?q=", "https://duckduckgo.com/y.js?ad_domain")
485
- )
486
- ):
487
- [next(data, None) for _ in range(3)] # skip block(i=1,2,3,4)
488
- else:
489
- cache.add(href)
490
- titlexpath = e.xpath(".//a//text()")
491
- title = str(titlexpath[0]) if titlexpath and isinstance(titlexpath, list) else ""
492
- elif i == 2:
493
- bodyxpath = e.xpath(".//td[@class='result-snippet']//text()")
494
- body = (
495
- "".join(str(x) for x in bodyxpath).strip()
496
- if bodyxpath and isinstance(bodyxpath, list)
497
- else ""
498
- )
499
- if href:
500
- result = {
501
- "title": _normalize(title),
502
- "href": _normalize_url(href),
503
- "body": _normalize(body),
504
- }
505
- page_results.append(result)
506
- return page_results
507
-
508
- slist = [0]
509
- if max_results:
510
- max_results = min(max_results, 2023)
511
- slist.extend(range(23, max_results, 50))
512
- try:
513
- for r in self._executor.map(_text_lite_page, slist):
514
- results.extend(r)
515
- except Exception as e:
516
- raise e
517
-
518
- return list(islice(results, max_results))
519
-
520
- def images(
521
- self,
522
- keywords: str,
523
- region: str = "wt-wt",
524
- safesearch: str = "moderate",
525
- timelimit: str | None = None,
526
- size: str | None = None,
527
- color: str | None = None,
528
- type_image: str | None = None,
529
- layout: str | None = None,
530
- license_image: str | None = None,
531
- max_results: int | None = None,
532
- ) -> list[dict[str, str]]:
533
- """webscout images search. Query params: https://duckduckgo.com/params.
534
-
535
- Args:
536
- keywords: keywords for query.
537
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
538
- safesearch: on, moderate, off. Defaults to "moderate".
539
- timelimit: Day, Week, Month, Year. Defaults to None.
540
- size: Small, Medium, Large, Wallpaper. Defaults to None.
541
- color: color, Monochrome, Red, Orange, Yellow, Green, Blue,
542
- Purple, Pink, Brown, Black, Gray, Teal, White. Defaults to None.
543
- type_image: photo, clipart, gif, transparent, line.
544
- Defaults to None.
545
- layout: Square, Tall, Wide. Defaults to None.
546
- license_image: any (All Creative Commons), Public (PublicDomain),
547
- Share (Free to Share and Use), ShareCommercially (Free to Share and Use Commercially),
548
- Modify (Free to Modify, Share, and Use), ModifyCommercially (Free to Modify, Share, and
549
- Use Commercially). Defaults to None.
550
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
551
-
552
- Returns:
553
- List of dictionaries with images search results.
554
-
555
- Raises:
556
- WebscoutE: Base exception for webscout errors.
557
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
558
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
559
- """
560
- assert keywords, "keywords is mandatory"
561
-
562
- vqd = self._get_vqd(keywords)
563
-
564
- safesearch_base = {"on": "1", "moderate": "1", "off": "-1"}
565
- timelimit = f"time:{timelimit}" if timelimit else ""
566
- size = f"size:{size}" if size else ""
567
- color = f"color:{color}" if color else ""
568
- type_image = f"type:{type_image}" if type_image else ""
569
- layout = f"layout:{layout}" if layout else ""
570
- license_image = f"license:{license_image}" if license_image else ""
571
- payload = {
572
- "l": region,
573
- "o": "json",
574
- "q": keywords,
575
- "vqd": vqd,
576
- "f": f"{timelimit},{size},{color},{type_image},{layout},{license_image}",
577
- "p": safesearch_base[safesearch.lower()],
578
- }
579
-
580
- cache = set()
581
- results: list[dict[str, str]] = []
582
-
583
- def _images_page(s: int) -> list[dict[str, str]]:
584
- payload["s"] = f"{s}"
585
- resp_content = self._get_url("GET", "https://duckduckgo.com/i.js", params=payload).content
586
- resp_json = json_loads(resp_content)
587
-
588
- page_data = resp_json.get("results", [])
589
- page_results = []
590
- for row in page_data:
591
- image_url = row.get("image")
592
- if image_url and image_url not in cache:
593
- cache.add(image_url)
594
- result = {
595
- "title": row["title"],
596
- "image": _normalize_url(image_url),
597
- "thumbnail": _normalize_url(row["thumbnail"]),
598
- "url": _normalize_url(row["url"]),
599
- "height": row["height"],
600
- "width": row["width"],
601
- "source": row["source"],
602
- }
603
- page_results.append(result)
604
- return page_results
605
-
606
- slist = [0]
607
- if max_results:
608
- max_results = min(max_results, 500)
609
- slist.extend(range(100, max_results, 100))
610
- try:
611
- for r in self._executor.map(_images_page, slist):
612
- results.extend(r)
613
- except Exception as e:
614
- raise e
615
-
616
- return list(islice(results, max_results))
617
-
618
- def videos(
619
- self,
620
- keywords: str,
621
- region: str = "wt-wt",
622
- safesearch: str = "moderate",
623
- timelimit: str | None = None,
624
- resolution: str | None = None,
625
- duration: str | None = None,
626
- license_videos: str | None = None,
627
- max_results: int | None = None,
628
- ) -> list[dict[str, str]]:
629
- """webscout videos search. Query params: https://duckduckgo.com/params.
630
-
631
- Args:
632
- keywords: keywords for query.
633
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
634
- safesearch: on, moderate, off. Defaults to "moderate".
635
- timelimit: d, w, m. Defaults to None.
636
- resolution: high, standart. Defaults to None.
637
- duration: short, medium, long. Defaults to None.
638
- license_videos: creativeCommon, youtube. Defaults to None.
639
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
640
-
641
- Returns:
642
- List of dictionaries with videos search results.
643
-
644
- Raises:
645
- WebscoutE: Base exception for webscout errors.
646
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
647
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
648
- """
649
- assert keywords, "keywords is mandatory"
650
-
651
- vqd = self._get_vqd(keywords)
652
-
653
- safesearch_base = {"on": "1", "moderate": "-1", "off": "-2"}
654
- timelimit = f"publishedAfter:{timelimit}" if timelimit else ""
655
- resolution = f"videoDefinition:{resolution}" if resolution else ""
656
- duration = f"videoDuration:{duration}" if duration else ""
657
- license_videos = f"videoLicense:{license_videos}" if license_videos else ""
658
- payload = {
659
- "l": region,
660
- "o": "json",
661
- "q": keywords,
662
- "vqd": vqd,
663
- "f": f"{timelimit},{resolution},{duration},{license_videos}",
664
- "p": safesearch_base[safesearch.lower()],
665
- }
666
-
667
- cache = set()
668
- results: list[dict[str, str]] = []
669
-
670
- def _videos_page(s: int) -> list[dict[str, str]]:
671
- payload["s"] = f"{s}"
672
- resp_content = self._get_url("GET", "https://duckduckgo.com/v.js", params=payload).content
673
- resp_json = json_loads(resp_content)
674
-
675
- page_data = resp_json.get("results", [])
676
- page_results = []
677
- for row in page_data:
678
- if row["content"] not in cache:
679
- cache.add(row["content"])
680
- page_results.append(row)
681
- return page_results
682
-
683
- slist = [0]
684
- if max_results:
685
- max_results = min(max_results, 400)
686
- slist.extend(range(60, max_results, 60))
687
- try:
688
- for r in self._executor.map(_videos_page, slist):
689
- results.extend(r)
690
- except Exception as e:
691
- raise e
692
-
693
- return list(islice(results, max_results))
694
-
695
- def news(
696
- self,
697
- keywords: str,
698
- region: str = "wt-wt",
699
- safesearch: str = "moderate",
700
- timelimit: str | None = None,
701
- max_results: int | None = None,
702
- ) -> list[dict[str, str]]:
703
- """webscout news search. Query params: https://duckduckgo.com/params.
704
-
705
- Args:
706
- keywords: keywords for query.
707
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
708
- safesearch: on, moderate, off. Defaults to "moderate".
709
- timelimit: d, w, m. Defaults to None.
710
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
711
-
712
- Returns:
713
- List of dictionaries with news search results.
714
-
715
- Raises:
716
- WebscoutE: Base exception for webscout errors.
717
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
718
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
719
- """
720
- assert keywords, "keywords is mandatory"
721
-
722
- vqd = self._get_vqd(keywords)
723
-
724
- safesearch_base = {"on": "1", "moderate": "-1", "off": "-2"}
725
- payload = {
726
- "l": region,
727
- "o": "json",
728
- "noamp": "1",
729
- "q": keywords,
730
- "vqd": vqd,
731
- "p": safesearch_base[safesearch.lower()],
732
- }
733
- if timelimit:
734
- payload["df"] = timelimit
735
-
736
- cache = set()
737
- results: list[dict[str, str]] = []
738
-
739
- def _news_page(s: int) -> list[dict[str, str]]:
740
- payload["s"] = f"{s}"
741
- resp_content = self._get_url("GET", "https://duckduckgo.com/news.js", params=payload).content
742
- resp_json = json_loads(resp_content)
743
- page_data = resp_json.get("results", [])
744
- page_results = []
745
- for row in page_data:
746
- if row["url"] not in cache:
747
- cache.add(row["url"])
748
- image_url = row.get("image", None)
749
- result = {
750
- "date": datetime.fromtimestamp(row["date"], timezone.utc).isoformat(),
751
- "title": row["title"],
752
- "body": _normalize(row["excerpt"]),
753
- "url": _normalize_url(row["url"]),
754
- "image": _normalize_url(image_url),
755
- "source": row["source"],
756
- }
757
- page_results.append(result)
758
- return page_results
759
-
760
- slist = [0]
761
- if max_results:
762
- max_results = min(max_results, 120)
763
- slist.extend(range(30, max_results, 30))
764
- try:
765
- for r in self._executor.map(_news_page, slist):
766
- results.extend(r)
767
- except Exception as e:
768
- raise e
769
-
770
- return list(islice(results, max_results))
771
-
772
- def answers(self, keywords: str) -> list[dict[str, str]]:
773
- """webscout instant answers. Query params: https://duckduckgo.com/params.
774
-
775
- Args:
776
- keywords: keywords for query,
777
-
778
- Returns:
779
- List of dictionaries with instant answers results.
780
-
781
- Raises:
782
- WebscoutE: Base exception for webscout errors.
783
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
784
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
785
- """
786
- assert keywords, "keywords is mandatory"
787
-
788
- payload = {
789
- "q": f"what is {keywords}",
790
- "format": "json",
791
- }
792
- resp_content = self._get_url("GET", "https://api.duckduckgo.com/", params=payload).content
793
- page_data = json_loads(resp_content)
794
-
795
- results = []
796
- answer = page_data.get("AbstractText")
797
- url = page_data.get("AbstractURL")
798
- if answer:
799
- results.append(
800
- {
801
- "icon": None,
802
- "text": answer,
803
- "topic": None,
804
- "url": url,
805
- }
806
- )
807
-
808
- # related
809
- payload = {
810
- "q": f"{keywords}",
811
- "format": "json",
812
- }
813
- resp_content = self._get_url("GET", "https://api.duckduckgo.com/", params=payload).content
814
- resp_json = json_loads(resp_content)
815
- page_data = resp_json.get("RelatedTopics", [])
816
-
817
- for row in page_data:
818
- topic = row.get("Name")
819
- if not topic:
820
- icon = row["Icon"].get("URL")
821
- results.append(
822
- {
823
- "icon": f"https://duckduckgo.com{icon}" if icon else "",
824
- "text": row["Text"],
825
- "topic": None,
826
- "url": row["FirstURL"],
827
- }
828
- )
829
- else:
830
- for subrow in row["Topics"]:
831
- icon = subrow["Icon"].get("URL")
832
- results.append(
833
- {
834
- "icon": f"https://duckduckgo.com{icon}" if icon else "",
835
- "text": subrow["Text"],
836
- "topic": topic,
837
- "url": subrow["FirstURL"],
838
- }
839
- )
840
-
841
- return results
842
-
843
- def suggestions(self, keywords: str, region: str = "wt-wt") -> list[dict[str, str]]:
844
- """webscout suggestions. Query params: https://duckduckgo.com/params.
845
-
846
- Args:
847
- keywords: keywords for query.
848
- region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
849
-
850
- Returns:
851
- List of dictionaries with suggestions results.
852
-
853
- Raises:
854
- WebscoutE: Base exception for webscout errors.
855
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
856
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
857
- """
858
- assert keywords, "keywords is mandatory"
859
-
860
- payload = {
861
- "q": keywords,
862
- "kl": region,
863
- }
864
- resp_content = self._get_url("GET", "https://duckduckgo.com/ac/", params=payload).content
865
- page_data = json_loads(resp_content)
866
- return [r for r in page_data]
867
-
868
- def maps(
869
- self,
870
- keywords: str,
871
- place: str | None = None,
872
- street: str | None = None,
873
- city: str | None = None,
874
- county: str | None = None,
875
- state: str | None = None,
876
- country: str | None = None,
877
- postalcode: str | None = None,
878
- latitude: str | None = None,
879
- longitude: str | None = None,
880
- radius: int = 0,
881
- max_results: int | None = None,
882
- ) -> list[dict[str, str]]:
883
- """webscout maps search. Query params: https://duckduckgo.com/params.
884
-
885
- Args:
886
- keywords: keywords for query
887
- place: if set, the other parameters are not used. Defaults to None.
888
- street: house number/street. Defaults to None.
889
- city: city of search. Defaults to None.
890
- county: county of search. Defaults to None.
891
- state: state of search. Defaults to None.
892
- country: country of search. Defaults to None.
893
- postalcode: postalcode of search. Defaults to None.
894
- latitude: geographic coordinate (north-south position). Defaults to None.
895
- longitude: geographic coordinate (east-west position); if latitude and
896
- longitude are set, the other parameters are not used. Defaults to None.
897
- radius: expand the search square by the distance in kilometers. Defaults to 0.
898
- max_results: max number of results. If None, returns results only from the first response. Defaults to None.
899
-
900
- Returns:
901
- List of dictionaries with maps search results, or None if there was an error.
902
-
903
- Raises:
904
- WebscoutE: Base exception for webscout errors.
905
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
906
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
907
- """
908
- assert keywords, "keywords is mandatory"
909
-
910
- vqd = self._get_vqd(keywords)
911
-
912
- # if longitude and latitude are specified, skip the request about bbox to the nominatim api
913
- if latitude and longitude:
914
- lat_t = Decimal(latitude.replace(",", "."))
915
- lat_b = Decimal(latitude.replace(",", "."))
916
- lon_l = Decimal(longitude.replace(",", "."))
917
- lon_r = Decimal(longitude.replace(",", "."))
918
- if radius == 0:
919
- radius = 1
920
- # otherwise request about bbox to nominatim api
921
- else:
922
- if place:
923
- params = {
924
- "q": place,
925
- "polygon_geojson": "0",
926
- "format": "jsonv2",
927
- }
928
- else:
929
- params = {
930
- "polygon_geojson": "0",
931
- "format": "jsonv2",
932
- }
933
- if street:
934
- params["street"] = street
935
- if city:
936
- params["city"] = city
937
- if county:
938
- params["county"] = county
939
- if state:
940
- params["state"] = state
941
- if country:
942
- params["country"] = country
943
- if postalcode:
944
- params["postalcode"] = postalcode
945
- # request nominatim api to get coordinates box
946
- resp_content = self._get_url(
947
- "GET",
948
- "https://nominatim.openstreetmap.org/search.php",
949
- params=params,
950
- ).content
951
- if resp_content == b"[]":
952
- raise WebscoutE("maps() Coordinates are not found, check function parameters.")
953
- resp_json = json_loads(resp_content)
954
- coordinates = resp_json[0]["boundingbox"]
955
- lat_t, lon_l = Decimal(coordinates[1]), Decimal(coordinates[2])
956
- lat_b, lon_r = Decimal(coordinates[0]), Decimal(coordinates[3])
957
-
958
- # if a radius is specified, expand the search square
959
- lat_t += Decimal(radius) * Decimal(0.008983)
960
- lat_b -= Decimal(radius) * Decimal(0.008983)
961
- lon_l -= Decimal(radius) * Decimal(0.008983)
962
- lon_r += Decimal(radius) * Decimal(0.008983)
963
- # logger.debug(f"bbox coordinates\n{lat_t} {lon_l}\n{lat_b} {lon_r}")
964
-
965
- cache = set()
966
- results: list[dict[str, str]] = []
967
-
968
- def _maps_page(
969
- bbox: tuple[Decimal, Decimal, Decimal, Decimal],
970
- ) -> list[dict[str, str]] | None:
971
- if max_results and len(results) >= max_results:
972
- return None
973
- lat_t, lon_l, lat_b, lon_r = bbox
974
- params = {
975
- "q": keywords,
976
- "vqd": vqd,
977
- "tg": "maps_places",
978
- "rt": "D",
979
- "mkexp": "b",
980
- "wiki_info": "1",
981
- "is_requery": "1",
982
- "bbox_tl": f"{lat_t},{lon_l}",
983
- "bbox_br": f"{lat_b},{lon_r}",
984
- "strict_bbox": "1",
985
- }
986
- resp_content = self._get_url("GET", "https://duckduckgo.com/local.js", params=params).content
987
- resp_json = json_loads(resp_content)
988
- page_data = resp_json.get("results", [])
989
-
990
- page_results = []
991
- for res in page_data:
992
- r_name = f'{res["name"]} {res["address"]}'
993
- if r_name in cache:
994
- continue
995
- else:
996
- cache.add(r_name)
997
- result = {
998
- "title": res["name"],
999
- "address": res["address"],
1000
- "country_code": res["country_code"],
1001
- "url": _normalize_url(res["website"]),
1002
- "phone": res["phone"] or "",
1003
- "latitude": res["coordinates"]["latitude"],
1004
- "longitude": res["coordinates"]["longitude"],
1005
- "source": _normalize_url(res["url"]),
1006
- "image": x.get("image", "") if (x := res["embed"]) else "",
1007
- "desc": x.get("description", "") if (x := res["embed"]) else "",
1008
- "hours": res["hours"] or "",
1009
- "category": res["ddg_category"] or "",
1010
- "facebook": f"www.facebook.com/profile.php?id={x}" if (x := res["facebook_id"]) else "",
1011
- "instagram": f"https://www.instagram.com/{x}" if (x := res["instagram_id"]) else "",
1012
- "twitter": f"https://twitter.com/{x}" if (x := res["twitter_id"]) else "",
1013
- }
1014
- page_results.append(result)
1015
- return page_results
1016
-
1017
- # search squares (bboxes)
1018
- start_bbox = (lat_t, lon_l, lat_b, lon_r)
1019
- work_bboxes = [start_bbox]
1020
- while work_bboxes:
1021
- queue_bboxes = [] # for next iteration, at the end of the iteration work_bboxes = queue_bboxes
1022
- tasks = []
1023
- for bbox in work_bboxes:
1024
- tasks.append(bbox)
1025
- # if distance between coordinates > 1, divide the square into 4 parts and save them in queue_bboxes
1026
- if _calculate_distance(lat_t, lon_l, lat_b, lon_r) > 1:
1027
- lat_t, lon_l, lat_b, lon_r = bbox
1028
- lat_middle = (lat_t + lat_b) / 2
1029
- lon_middle = (lon_l + lon_r) / 2
1030
- bbox1 = (lat_t, lon_l, lat_middle, lon_middle)
1031
- bbox2 = (lat_t, lon_middle, lat_middle, lon_r)
1032
- bbox3 = (lat_middle, lon_l, lat_b, lon_middle)
1033
- bbox4 = (lat_middle, lon_middle, lat_b, lon_r)
1034
- queue_bboxes.extend([bbox1, bbox2, bbox3, bbox4])
1035
-
1036
- # gather tasks using asyncio.wait_for and timeout
1037
- work_bboxes_results = []
1038
- try:
1039
- for r in self._executor.map(_maps_page, tasks):
1040
- if r:
1041
- work_bboxes_results.extend(r)
1042
- except Exception as e:
1043
- raise e
1044
-
1045
- for x in work_bboxes_results:
1046
- if isinstance(x, list):
1047
- results.extend(x)
1048
- elif isinstance(x, dict):
1049
- results.append(x)
1050
-
1051
- work_bboxes = queue_bboxes
1052
- if not max_results or len(results) >= max_results or len(work_bboxes_results) == 0:
1053
- break
1054
-
1055
- return list(islice(results, max_results))
1056
-
1057
- def translate(self, keywords: list[str] | str, from_: str | None = None, to: str = "en") -> list[dict[str, str]]:
1058
- """webscout translate.
1059
-
1060
- Args:
1061
- keywords: string or list of strings to translate.
1062
- from_: translate from (defaults automatically). Defaults to None.
1063
- to: what language to translate. Defaults to "en".
1064
-
1065
- Returns:
1066
- List od dictionaries with translated keywords.
1067
-
1068
- Raises:
1069
- WebscoutE: Base exception for webscout errors.
1070
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
1071
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
1072
- """
1073
- assert keywords, "keywords is mandatory"
1074
-
1075
- vqd = self._get_vqd("translate")
1076
-
1077
- payload = {
1078
- "vqd": vqd,
1079
- "query": "translate",
1080
- "to": to,
1081
- }
1082
- if from_:
1083
- payload["from"] = from_
1084
-
1085
- def _translate_keyword(keyword: str) -> dict[str, str]:
1086
- resp_content = self._get_url(
1087
- "POST",
1088
- "https://duckduckgo.com/translation.js",
1089
- params=payload,
1090
- content=keyword.encode(),
1091
- ).content
1092
- page_data: dict[str, str] = json_loads(resp_content)
1093
- page_data["original"] = keyword
1094
- return page_data
1095
-
1096
- if isinstance(keywords, str):
1097
- keywords = [keywords]
1098
-
1099
- results = []
1100
- try:
1101
- for r in self._executor.map(_translate_keyword, keywords):
1102
- results.append(r)
1103
- except Exception as e:
1104
- raise e
1105
-
1106
- return results
1107
-
1108
- def weather(
1109
- self,
1110
- location: str,
1111
- language: str = "en",
1112
- ) -> dict[str, Any]:
1113
- """Get weather information for a location from DuckDuckGo.
1114
-
1115
- Args:
1116
- location: Location to get weather for.
1117
- language: Language code (e.g. 'en', 'es'). Defaults to "en".
1118
-
1119
- Returns:
1120
- Dictionary containing weather data with structure described in docstring.
1121
-
1122
- Raises:
1123
- WebscoutE: Base exception for webscout errors.
1124
- RatelimitE: Inherits from WebscoutE, raised for exceeding API request rate limits.
1125
- TimeoutE: Inherits from WebscoutE, raised for API request timeouts.
1126
- """
1127
- assert location, "location is mandatory"
1128
- lang = language.split('-')[0]
1129
- url = f"https://duckduckgo.com/js/spice/forecast/{quote(location)}/{lang}"
1130
-
1131
- resp = self._get_url("GET", url).content
1132
- resp_text = resp.decode('utf-8')
1133
-
1134
- if "ddg_spice_forecast(" not in resp_text:
1135
- raise WebscoutE(f"No weather data found for {location}")
1136
-
1137
- json_text = resp_text[resp_text.find('(') + 1:resp_text.rfind(')')]
1138
- try:
1139
- result = json.loads(json_text)
1140
- except Exception as e:
1141
- raise WebscoutE(f"Error parsing weather JSON: {e}")
1142
-
1143
- if not result or 'currentWeather' not in result or 'forecastDaily' not in result:
1144
- raise WebscoutE(f"Invalid weather data format for {location}")
1145
-
1146
- formatted_data = {
1147
- "location": result["currentWeather"]["metadata"].get("ddg-location", "Unknown"),
1148
- "current": {
1149
- "condition": result["currentWeather"].get("conditionCode"),
1150
- "temperature_c": result["currentWeather"].get("temperature"),
1151
- "feels_like_c": result["currentWeather"].get("temperatureApparent"),
1152
- "humidity": result["currentWeather"].get("humidity"),
1153
- "wind_speed_ms": result["currentWeather"].get("windSpeed"),
1154
- "wind_direction": result["currentWeather"].get("windDirection"),
1155
- "visibility_m": result["currentWeather"].get("visibility"),
1156
- },
1157
- "daily_forecast": [],
1158
- "hourly_forecast": []
1159
- }
1160
-
1161
- for day in result["forecastDaily"]["days"]:
1162
- formatted_data["daily_forecast"].append({
1163
- "date": datetime.fromisoformat(day["forecastStart"].replace("Z", "+00:00")).strftime("%Y-%m-%d"),
1164
- "condition": day["daytimeForecast"].get("conditionCode"),
1165
- "max_temp_c": day["temperatureMax"],
1166
- "min_temp_c": day["temperatureMin"],
1167
- "sunrise": datetime.fromisoformat(day["sunrise"].replace("Z", "+00:00")).strftime("%H:%M"),
1168
- "sunset": datetime.fromisoformat(day["sunset"].replace("Z", "+00:00")).strftime("%H:%M"),
1169
- })
1170
-
1171
- if 'forecastHourly' in result and 'hours' in result['forecastHourly']:
1172
- for hour in result['forecastHourly']['hours']:
1173
- formatted_data["hourly_forecast"].append({
1174
- "time": datetime.fromisoformat(hour["forecastStart"].replace("Z", "+00:00")).strftime("%H:%M"),
1175
- "condition": hour.get("conditionCode"),
1176
- "temperature_c": hour.get("temperature"),
1177
- "feels_like_c": hour.get("temperatureApparent"),
1178
- "humidity": hour.get("humidity"),
1179
- "wind_speed_ms": hour.get("windSpeed"),
1180
- "wind_direction": hour.get("windDirection"),
1181
- "visibility_m": hour.get("visibility"),
1182
- })
1183
-
1184
- return formatted_data