webscout 2025.10.14.1__py3-none-any.whl → 2025.10.16__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 (70) hide show
  1. webscout/Extra/YTToolkit/README.md +1 -1
  2. webscout/Extra/tempmail/README.md +3 -3
  3. webscout/Provider/OPENAI/README.md +1 -1
  4. webscout/Provider/TTI/bing.py +4 -4
  5. webscout/__init__.py +1 -1
  6. webscout/cli.py +0 -147
  7. webscout/client.py +4 -5
  8. webscout/litprinter/__init__.py +0 -42
  9. webscout/scout/README.md +59 -8
  10. webscout/scout/core/scout.py +62 -0
  11. webscout/scout/element.py +251 -45
  12. webscout/search/__init__.py +5 -8
  13. webscout/search/bing_main.py +42 -0
  14. webscout/search/engines/bing/__init__.py +1 -0
  15. webscout/search/engines/bing/base.py +33 -0
  16. webscout/search/engines/bing/images.py +108 -0
  17. webscout/search/engines/bing/news.py +91 -0
  18. webscout/search/engines/bing/suggestions.py +34 -0
  19. webscout/search/engines/bing/text.py +106 -0
  20. webscout/search/engines/duckduckgo/maps.py +13 -0
  21. webscout/search/engines/yahoo/__init__.py +41 -0
  22. webscout/search/engines/yahoo/answers.py +16 -0
  23. webscout/search/engines/yahoo/base.py +34 -0
  24. webscout/search/engines/yahoo/images.py +324 -0
  25. webscout/search/engines/yahoo/maps.py +16 -0
  26. webscout/search/engines/yahoo/news.py +258 -0
  27. webscout/search/engines/yahoo/suggestions.py +140 -0
  28. webscout/search/engines/yahoo/text.py +273 -0
  29. webscout/search/engines/yahoo/translate.py +16 -0
  30. webscout/search/engines/yahoo/videos.py +302 -0
  31. webscout/search/engines/yahoo/weather.py +220 -0
  32. webscout/search/http_client.py +1 -1
  33. webscout/search/yahoo_main.py +54 -0
  34. webscout/{auth → server}/__init__.py +2 -23
  35. webscout/server/config.py +84 -0
  36. webscout/{auth → server}/request_processing.py +3 -28
  37. webscout/{auth → server}/routes.py +14 -170
  38. webscout/server/schemas.py +23 -0
  39. webscout/{auth → server}/server.py +11 -43
  40. webscout/server/simple_logger.py +84 -0
  41. webscout/version.py +1 -1
  42. webscout/version.py.bak +1 -1
  43. webscout/zeroart/README.md +17 -9
  44. webscout/zeroart/__init__.py +78 -6
  45. webscout/zeroart/effects.py +51 -1
  46. webscout/zeroart/fonts.py +559 -1
  47. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/METADATA +15 -332
  48. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/RECORD +55 -48
  49. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/entry_points.txt +1 -1
  50. webscout/Bing_search.py +0 -417
  51. webscout/DWEBS.py +0 -529
  52. webscout/auth/api_key_manager.py +0 -189
  53. webscout/auth/auth_system.py +0 -85
  54. webscout/auth/config.py +0 -175
  55. webscout/auth/database.py +0 -755
  56. webscout/auth/middleware.py +0 -248
  57. webscout/auth/models.py +0 -185
  58. webscout/auth/rate_limiter.py +0 -254
  59. webscout/auth/schemas.py +0 -103
  60. webscout/auth/simple_logger.py +0 -236
  61. webscout/search/engines/bing.py +0 -84
  62. webscout/search/engines/bing_news.py +0 -52
  63. webscout/search/engines/yahoo.py +0 -65
  64. webscout/search/engines/yahoo_news.py +0 -64
  65. /webscout/{auth → server}/exceptions.py +0 -0
  66. /webscout/{auth → server}/providers.py +0 -0
  67. /webscout/{auth → server}/request_models.py +0 -0
  68. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/WHEEL +0 -0
  69. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/licenses/LICENSE.md +0 -0
  70. {webscout-2025.10.14.1.dist-info → webscout-2025.10.16.dist-info}/top_level.txt +0 -0
@@ -1,189 +0,0 @@
1
- # webscout/auth/api_key_manager.py
2
-
3
- import secrets
4
- import string
5
- from datetime import datetime, timezone, timedelta
6
- from typing import Optional, Tuple
7
- import hashlib
8
- import logging
9
-
10
- from .models import User, APIKey
11
- from .database import DatabaseManager
12
-
13
- logger = logging.getLogger(__name__)
14
-
15
-
16
- class APIKeyManager:
17
- """Manages API key generation, validation, and lifecycle."""
18
-
19
- def __init__(self, database_manager: DatabaseManager):
20
- self.db = database_manager
21
- self.key_prefix = "ws_" # webscout prefix
22
- self.key_length = 32 # Length of the random part
23
-
24
- def generate_api_key(self) -> str:
25
- """Generate a secure API key."""
26
- # Generate random string
27
- alphabet = string.ascii_letters + string.digits
28
- random_part = ''.join(secrets.choice(alphabet) for _ in range(self.key_length))
29
-
30
- # Add prefix
31
- api_key = f"{self.key_prefix}{random_part}"
32
-
33
- return api_key
34
-
35
- def hash_api_key(self, api_key: str) -> str:
36
- """Hash an API key for secure storage (optional, for extra security)."""
37
- return hashlib.sha256(api_key.encode()).hexdigest()
38
-
39
- async def create_api_key(
40
- self,
41
- username: str,
42
- telegram_id: str,
43
- name: Optional[str] = None,
44
- rate_limit: int = 10,
45
- expires_in_days: Optional[int] = None
46
- ) -> Tuple[APIKey, User]:
47
- """Create a new API key and associated user if needed. Only one API key per user allowed."""
48
-
49
- # Check if user already exists by telegram_id
50
- user = await self.db.get_user_by_telegram_id(telegram_id)
51
-
52
- if user:
53
- # Check if user already has an API key
54
- existing_keys = await self.db.get_api_keys_by_user(user.id)
55
- active_keys = [key for key in existing_keys if key.is_active and not key.is_expired()]
56
-
57
- if active_keys:
58
- raise ValueError(f"User with Telegram ID {telegram_id} already has an active API key. Only one API key per user is allowed.")
59
- else:
60
- # Check if username is already taken
61
- existing_user = await self.db.get_user_by_username(username)
62
- if existing_user:
63
- raise ValueError(f"Username '{username}' is already taken")
64
-
65
- # Create new user
66
- user = User(
67
- username=username,
68
- telegram_id=telegram_id,
69
- created_at=datetime.now(timezone.utc),
70
- updated_at=datetime.now(timezone.utc)
71
- )
72
- try:
73
- user = await self.db.create_user(user)
74
- logger.info(f"Created new user: {user.username} (Telegram ID: {telegram_id})")
75
- except ValueError as e:
76
- # User might already exist, try to get it
77
- if "already exists" in str(e):
78
- user = await self.db.get_user_by_telegram_id(telegram_id)
79
- if not user:
80
- raise e
81
- else:
82
- raise e
83
-
84
- # Generate API key
85
- api_key_value = self.generate_api_key()
86
-
87
- # Calculate expiration
88
- expires_at = None
89
- if expires_in_days:
90
- expires_at = datetime.now(timezone.utc) + timedelta(days=expires_in_days)
91
-
92
- # Create API key object
93
- api_key = APIKey(
94
- key=api_key_value,
95
- user_id=user.id,
96
- name=name,
97
- created_at=datetime.now(timezone.utc),
98
- expires_at=expires_at,
99
- rate_limit=rate_limit,
100
- is_active=True
101
- )
102
-
103
- # Store in database
104
- try:
105
- api_key = await self.db.create_api_key(api_key)
106
- logger.info(f"Created API key for user {user.username}: {api_key.id}")
107
- return api_key, user
108
- except ValueError as e:
109
- # Key collision (very unlikely), try again
110
- if "already exists" in str(e):
111
- logger.warning("API key collision detected, regenerating...")
112
- return await self.create_api_key(username, telegram_id, name, rate_limit, expires_in_days)
113
- raise e
114
-
115
- async def validate_api_key(self, api_key: str) -> Tuple[bool, Optional[APIKey], Optional[str]]:
116
- """
117
- Validate an API key.
118
-
119
- Returns:
120
- Tuple of (is_valid, api_key_object, error_message)
121
- """
122
- if not api_key:
123
- return False, None, "API key is required"
124
-
125
- if not api_key.startswith(self.key_prefix):
126
- return False, None, "Invalid API key format"
127
-
128
- try:
129
- # Get API key from database
130
- key_obj = await self.db.get_api_key(api_key)
131
-
132
- if not key_obj:
133
- return False, None, "API key not found"
134
-
135
- if not key_obj.is_active:
136
- return False, None, "API key is inactive"
137
-
138
- if key_obj.is_expired():
139
- return False, None, "API key has expired"
140
-
141
- # Update last used timestamp
142
- key_obj.last_used_at = datetime.now(timezone.utc)
143
- key_obj.usage_count += 1
144
-
145
- try:
146
- await self.db.update_api_key(key_obj)
147
- except Exception as e:
148
- logger.warning(f"Failed to update API key usage: {e}")
149
-
150
- return True, key_obj, None
151
-
152
- except Exception as e:
153
- logger.error(f"Error validating API key: {e}")
154
- return False, None, "Internal error during validation"
155
-
156
- async def revoke_api_key(self, api_key: str) -> bool:
157
- """Revoke an API key by marking it as inactive."""
158
- try:
159
- key_obj = await self.db.get_api_key(api_key)
160
-
161
- if not key_obj:
162
- return False
163
-
164
- key_obj.is_active = False
165
- key_obj.updated_at = datetime.now(timezone.utc)
166
-
167
- await self.db.update_api_key(key_obj)
168
- logger.info(f"Revoked API key: {key_obj.id}")
169
- return True
170
-
171
- except Exception as e:
172
- logger.error(f"Error revoking API key: {e}")
173
- return False
174
-
175
- async def get_user_api_keys(self, user_id: str) -> list[APIKey]:
176
- """Get all API keys for a user."""
177
- try:
178
- return await self.db.get_api_keys_by_user(user_id)
179
- except Exception as e:
180
- logger.error(f"Error getting user API keys: {e}")
181
- return []
182
-
183
- async def cleanup_expired_keys(self) -> int:
184
- """Clean up expired API keys (mark as inactive)."""
185
- # This would require a method to get all API keys, which we haven't implemented
186
- # For now, we'll just return 0
187
- # In a production system, you'd want to implement this properly
188
- logger.info("Cleanup expired keys called (not implemented)")
189
- return 0
@@ -1,85 +0,0 @@
1
- """
2
- Authentication system initialization for the Webscout API.
3
- """
4
-
5
- import os
6
- import sys
7
- from typing import Optional
8
- from fastapi import FastAPI
9
-
10
- from webscout.Litlogger import Logger, LogLevel, LogFormat, ConsoleHandler
11
- from .database import DatabaseManager
12
- from .api_key_manager import APIKeyManager
13
- from .rate_limiter import RateLimiter
14
- from .middleware import AuthMiddleware
15
-
16
- # Setup logger
17
- logger = Logger(
18
- name="webscout.api",
19
- level=LogLevel.INFO,
20
- handlers=[ConsoleHandler(stream=sys.stdout)],
21
- fmt=LogFormat.DEFAULT
22
- )
23
-
24
- # Global authentication system instances
25
- db_manager: Optional[DatabaseManager] = None
26
- api_key_manager: Optional[APIKeyManager] = None
27
- rate_limiter: Optional[RateLimiter] = None
28
- auth_middleware: Optional[AuthMiddleware] = None
29
-
30
-
31
- def initialize_auth_system(app: FastAPI, auth_required: bool = True, rate_limit_enabled: bool = True) -> None:
32
- """Initialize the authentication system."""
33
- global db_manager, api_key_manager, rate_limiter, auth_middleware
34
-
35
- try:
36
- # Initialize database manager (always needed for request logging)
37
- mongo_url = os.getenv("MONGODB_URL")
38
- data_dir = os.getenv("WEBSCOUT_DATA_DIR", "data")
39
-
40
- db_manager = DatabaseManager(mongo_url, data_dir)
41
-
42
- if not auth_required:
43
- logger.info("Auth system is disabled (no-auth mode): initializing only database for request logging.")
44
- api_key_manager = None
45
- rate_limiter = None
46
- auth_middleware = None
47
- else:
48
- # Initialize API key manager
49
- api_key_manager = APIKeyManager(db_manager)
50
-
51
- # Initialize rate limiter
52
- rate_limiter = RateLimiter(db_manager)
53
-
54
- # Initialize auth middleware with configuration
55
- auth_middleware = AuthMiddleware(
56
- api_key_manager,
57
- rate_limiter,
58
- auth_required=auth_required,
59
- rate_limit_enabled=rate_limit_enabled
60
- )
61
-
62
- # Add auth middleware to app
63
- app.middleware("http")(auth_middleware)
64
-
65
- # Add startup event to initialize database
66
- async def startup_event():
67
- if db_manager:
68
- await db_manager.initialize()
69
- logger.info("Database system initialized successfully")
70
- logger.info(f"Auth required: {auth_required}, Rate limiting: {rate_limit_enabled}")
71
-
72
- # Store startup function for later use
73
- app.state.startup_event = startup_event
74
-
75
- logger.info("Authentication system setup completed")
76
-
77
- except Exception as e:
78
- logger.error(f"Failed to initialize authentication system: {e}")
79
- # Fall back to legacy auth if new system fails
80
- logger.warning("Falling back to legacy authentication system")
81
-
82
-
83
- def get_auth_components():
84
- """Get the initialized authentication components."""
85
- return api_key_manager, db_manager, rate_limiter
webscout/auth/config.py DELETED
@@ -1,175 +0,0 @@
1
- """
2
- Configuration management for the Webscout API server.
3
- """
4
-
5
- import os
6
- from typing import List, Dict, Optional, Any
7
- from webscout.Litlogger import Logger, LogLevel, LogFormat, ConsoleHandler
8
- import sys
9
-
10
- # Configuration constants
11
- DEFAULT_PORT = 8000
12
- DEFAULT_HOST = "0.0.0.0"
13
-
14
- # Setup logger
15
- logger = Logger(
16
- name="webscout.api",
17
- level=LogLevel.INFO,
18
- handlers=[ConsoleHandler(stream=sys.stdout)],
19
- fmt=LogFormat.DEFAULT
20
- )
21
-
22
-
23
- def _get_supabase_url() -> Optional[str]:
24
- """Get Supabase URL from environment variables or GitHub secrets."""
25
- # Try environment variable first
26
- url = os.getenv("SUPABASE_URL")
27
- if url:
28
- logger.info("📍 Using SUPABASE_URL from environment")
29
- return url
30
-
31
- # Try to get from GitHub secrets (if running in GitHub Actions)
32
- github_url = os.getenv("GITHUB_SUPABASE_URL") # GitHub Actions secret
33
- if github_url:
34
- logger.info("📍 Using SUPABASE_URL from GitHub secrets")
35
- return github_url
36
-
37
- # Don't log error during import - only when actually needed
38
- return None
39
-
40
-
41
- def _get_supabase_anon_key() -> Optional[str]:
42
- """Get Supabase anon key from environment variables or GitHub secrets."""
43
- # Try environment variable first
44
- key = os.getenv("SUPABASE_ANON_KEY")
45
- if key:
46
- logger.info("🔑 Using SUPABASE_ANON_KEY from environment")
47
- return key
48
-
49
- # Try to get from GitHub secrets (if running in GitHub Actions)
50
- github_key = os.getenv("GITHUB_SUPABASE_ANON_KEY") # GitHub Actions secret
51
- if github_key:
52
- logger.info("🔑 Using SUPABASE_ANON_KEY from GitHub secrets")
53
- return github_key
54
-
55
- # Don't log error during import - only when actually needed
56
- return None
57
-
58
-
59
- class ServerConfig:
60
- """Centralized configuration management for the API server."""
61
-
62
- def __init__(self):
63
- self.api_key: Optional[str] = None
64
- self.provider_map: Dict[str, Any] = {}
65
- self.default_provider: str = "ChatGPT"
66
- self.base_url: Optional[str] = None
67
- self.host: str = DEFAULT_HOST
68
- self.port: int = DEFAULT_PORT
69
- self.debug: bool = False
70
- self.cors_origins: List[str] = ["*"]
71
- self.max_request_size: int = 10 * 1024 * 1024 # 10MB
72
- self.request_timeout: int = 300 # 5 minutes
73
- self.auth_required: bool = os.getenv("WEBSCOUT_AUTH_REQUIRED", "false").lower() == "true" # Default to no auth
74
- self.rate_limit_enabled: bool = os.getenv("WEBSCOUT_RATE_LIMIT_ENABLED", "false").lower() == "true" # Default to no rate limit
75
- self.default_rate_limit: int = 60 # Default rate limit for no-auth mode
76
- self.request_logging_enabled: bool = os.getenv("WEBSCOUT_REQUEST_LOGGING", "true").lower() == "true" # Enable request logging by default
77
-
78
- # Database configuration - lazy initialization
79
- self._supabase_url: Optional[str] = None
80
- self._supabase_anon_key: Optional[str] = None
81
- self._supabase_url_checked: bool = False
82
- self._supabase_anon_key_checked: bool = False
83
- self.mongodb_url: Optional[str] = os.getenv("MONGODB_URL")
84
-
85
- @property
86
- def supabase_url(self) -> Optional[str]:
87
- """Get Supabase URL with lazy initialization."""
88
- if not self._supabase_url_checked:
89
- self._supabase_url = _get_supabase_url()
90
- self._supabase_url_checked = True
91
- return self._supabase_url
92
-
93
- @property
94
- def supabase_anon_key(self) -> Optional[str]:
95
- """Get Supabase anon key with lazy initialization."""
96
- if not self._supabase_anon_key_checked:
97
- self._supabase_anon_key = _get_supabase_anon_key()
98
- self._supabase_anon_key_checked = True
99
- return self._supabase_anon_key
100
-
101
- def update(self, **kwargs) -> None:
102
- """Update configuration with provided values."""
103
- for key, value in kwargs.items():
104
- if hasattr(self, key) and value is not None:
105
- setattr(self, key, value)
106
- logger.info(f"Config updated: {key} = {value}")
107
-
108
- def validate(self) -> None:
109
- """Validate configuration settings."""
110
- if self.port < 1 or self.port > 65535:
111
- raise ValueError(f"Invalid port number: {self.port}")
112
-
113
- if self.default_provider not in self.provider_map and self.provider_map:
114
- available_providers = list(set(v.__name__ for v in self.provider_map.values()))
115
- logger.warning(f"Default provider '{self.default_provider}' not found. Available: {available_providers}")
116
-
117
-
118
- class AppConfig:
119
- """Legacy configuration class for backward compatibility."""
120
- api_key: Optional[str] = None
121
- provider_map = {}
122
- tti_provider_map = {} # Add TTI provider map
123
- default_provider = "ChatGPT"
124
- default_tti_provider = "PollinationsAI" # Add default TTI provider
125
- base_url: Optional[str] = None
126
- auth_required: bool = os.getenv("WEBSCOUT_AUTH_REQUIRED", "false").lower() == "true" # Default to no auth
127
- rate_limit_enabled: bool = os.getenv("WEBSCOUT_RATE_LIMIT_ENABLED", "false").lower() == "true" # Default to no rate limit
128
- default_rate_limit: int = 60 # Default rate limit for no-auth mode
129
- request_logging_enabled: bool = os.getenv("WEBSCOUT_REQUEST_LOGGING", "true").lower() == "true" # Enable request logging by default
130
-
131
- # Database configuration - lazy initialization
132
- _supabase_url: Optional[str] = None
133
- _supabase_anon_key: Optional[str] = None
134
- _supabase_url_checked: bool = False
135
- _supabase_anon_key_checked: bool = False
136
- mongodb_url: Optional[str] = os.getenv("MONGODB_URL")
137
-
138
- @classmethod
139
- def get_supabase_url(cls) -> Optional[str]:
140
- """Get Supabase URL with lazy initialization."""
141
- if not cls._supabase_url_checked:
142
- cls._supabase_url = _get_supabase_url()
143
- cls._supabase_url_checked = True
144
- return cls._supabase_url
145
-
146
- @classmethod
147
- def get_supabase_anon_key(cls) -> Optional[str]:
148
- """Get Supabase anon key with lazy initialization."""
149
- if not cls._supabase_anon_key_checked:
150
- cls._supabase_anon_key = _get_supabase_anon_key()
151
- cls._supabase_anon_key_checked = True
152
- return cls._supabase_anon_key
153
-
154
- # For backward compatibility, provide properties that call the methods
155
- @property
156
- def supabase_url(self) -> Optional[str]:
157
- return self.__class__.get_supabase_url()
158
-
159
- @property
160
- def supabase_anon_key(self) -> Optional[str]:
161
- return self.__class__.get_supabase_anon_key()
162
-
163
- @classmethod
164
- def set_config(cls, **data):
165
- """Set configuration values."""
166
- for key, value in data.items():
167
- setattr(cls, key, value)
168
- # Sync with new config system
169
- try:
170
- from .server import get_config
171
- config = get_config()
172
- config.update(**data)
173
- except ImportError:
174
- # Handle case where server module is not available
175
- pass