# Directory Structure
```
├── .aider.conf.yml
├── .bing.code-workspace
├── .env.example
├── .gitignore
├── CLAUDEME.md
├── README.md
├── SPECIFICATIONS.md
└── UPDATES.md
```
# Files
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
```
1 |
```
--------------------------------------------------------------------------------
/.bing.code-workspace:
--------------------------------------------------------------------------------
```
1 | {
2 | "folders": [
3 | {
4 | "path": "."
5 | }
6 | ],
7 | "settings": {
8 | "git.enabled": false,
9 | "files.exclude": {
10 | "*/": false, // Show all subdirectories
11 | "*/.git": true // Hide .git folders in projects
12 | },
13 | "files.associations": {
14 | "template.*": "plaintext",
15 | "reference.*": "plaintext",
16 | ".cheatsheet": "plaintext"
17 | }
18 | }
19 | }
```
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
```
1 | # Ignore all subdirectories (where individual projects live)
2 | */
3 |
4 | # Standard ignores
5 | .DS_Store
6 | .DS_Store?
7 | ._*
8 | .Spotlight-V100
9 | .Trashes
10 | ehthumbs.db
11 | Thumbs.db
12 | .env
13 |
14 | # IDE/Editor files
15 | .idea/
16 | .vscode/
17 | *.swp
18 | *.swo
19 |
20 | # Aider cache files
21 | .aider.tags.cache.v3
22 |
23 | # Make sure we don't accidentally commit any actual project files
24 | # that might end up in the root temporarily
25 | *.log
26 | *.lock
27 | node_modules/
```
--------------------------------------------------------------------------------
/.aider.conf.yml:
--------------------------------------------------------------------------------
```yaml
1 | ##########################################################
2 | # Sample .aider.conf.yml
3 | # This file lists *all* the valid configuration entries.
4 | # Place in your home dir, or at the root of your git repo.
5 | ##########################################################
6 |
7 | # Note: You can only put OpenAI and Anthropic API keys in the yaml
8 | # config file. Keys for all APIs can be stored in a .env file
9 | # https://aider.chat/docs/config/dotenv.html
10 |
11 | ##########
12 | # options:
13 |
14 | ## show this help message and exit
15 | #help: xxx
16 |
17 | #############
18 | # Main model:
19 |
20 | ## Specify the model to use for the main chat
21 | #model: xxx
22 |
23 | ## Use claude-3-opus-20240229 model for the main chat
24 | #opus: false
25 |
26 | ## Use claude-3-5-sonnet-20241022 model for the main chat
27 | #sonnet: false
28 |
29 | ## Use claude-3-5-haiku-20241022 model for the main chat
30 | #haiku: false
31 |
32 | ## Use gpt-4-0613 model for the main chat
33 | #4: false
34 |
35 | ## Use gpt-4o model for the main chat
36 | #4o: false
37 |
38 | ## Use gpt-4o-mini model for the main chat
39 | #mini: false
40 |
41 | ## Use gpt-4-1106-preview model for the main chat
42 | #4-turbo: false
43 |
44 | ## Use gpt-3.5-turbo model for the main chat
45 | #35turbo: false
46 |
47 | ## Use deepseek/deepseek-chat model for the main chat
48 | #deepseek: false
49 |
50 | ## Use o1-mini model for the main chat
51 | #o1-mini: false
52 |
53 | ## Use o1-preview model for the main chat
54 | #o1-preview: false
55 |
56 | ########################
57 | # API Keys and settings:
58 |
59 | ## Specify the OpenAI API key
60 | #openai-api-key: xxx
61 |
62 | ## Specify the Anthropic API key
63 | #anthropic-api-key: xxx
64 |
65 | ## Specify the api base url
66 | #openai-api-base: xxx
67 |
68 | ## (deprecated, use --set-env OPENAI_API_TYPE=<value>)
69 | #openai-api-type: xxx
70 |
71 | ## (deprecated, use --set-env OPENAI_API_VERSION=<value>)
72 | #openai-api-version: xxx
73 |
74 | ## (deprecated, use --set-env OPENAI_API_DEPLOYMENT_ID=<value>)
75 | #openai-api-deployment-id: xxx
76 |
77 | ## (deprecated, use --set-env OPENAI_ORGANIZATION=<value>)
78 | #openai-organization-id: xxx
79 |
80 | ## Set an environment variable (to control API settings, can be used multiple times)
81 | #set-env: xxx
82 | ## Specify multiple values like this:
83 | #set-env:
84 | # - xxx
85 | # - yyy
86 | # - zzz
87 |
88 | ## Set an API key for a provider (eg: --api-key provider=<key> sets PROVIDER_API_KEY=<key>)
89 | #api-key: xxx
90 | ## Specify multiple values like this:
91 | #api-key:
92 | # - xxx
93 | # - yyy
94 | # - zzz
95 |
96 | #################
97 | # Model settings:
98 |
99 | ## List known models which match the (partial) MODEL name
100 | #list-models: xxx
101 |
102 | ## Specify a file with aider model settings for unknown models
103 | #model-settings-file: .aider.model.settings.yml
104 |
105 | ## Specify a file with context window and costs for unknown models
106 | #model-metadata-file: .aider.model.metadata.json
107 |
108 | ## Add a model alias (can be used multiple times)
109 | #alias: xxx
110 | ## Specify multiple values like this:
111 | #alias:
112 | # - xxx
113 | # - yyy
114 | # - zzz
115 |
116 | ## Verify the SSL cert when connecting to models (default: True)
117 | #verify-ssl: true
118 |
119 | ## Timeout in seconds for API calls (default: None)
120 | #timeout: xxx
121 |
122 | ## Specify what edit format the LLM should use (default depends on model)
123 | #edit-format: xxx
124 |
125 | ## Use architect edit format for the main chat
126 | #architect: false
127 |
128 | ## Specify the model to use for commit messages and chat history summarization (default depends on --model)
129 | #weak-model: xxx
130 |
131 | ## Specify the model to use for editor tasks (default depends on --model)
132 | #editor-model: xxx
133 |
134 | ## Specify the edit format for the editor model (default: depends on editor model)
135 | #editor-edit-format: xxx
136 |
137 | ## Only work with models that have meta-data available (default: True)
138 | #show-model-warnings: true
139 |
140 | ## Soft limit on tokens for chat history, after which summarization begins. If unspecified, defaults to the model's max_chat_history_tokens.
141 | #max-chat-history-tokens: xxx
142 |
143 | #################
144 | # Cache settings:
145 |
146 | ## Enable caching of prompts (default: False)
147 | #cache-prompts: false
148 |
149 | ## Number of times to ping at 5min intervals to keep prompt cache warm (default: 0)
150 | #cache-keepalive-pings: false
151 |
152 | ###################
153 | # Repomap settings:
154 |
155 | ## Suggested number of tokens to use for repo map, use 0 to disable
156 | #map-tokens: xxx
157 |
158 | ## Control how often the repo map is refreshed. Options: auto, always, files, manual (default: auto)
159 | #map-refresh: auto
160 |
161 | ## Multiplier for map tokens when no files are specified (default: 2)
162 | #map-multiplier-no-files: true
163 |
164 | ################
165 | # History Files:
166 |
167 | ## Specify the chat input history file (default: .aider.input.history)
168 | #input-history-file: .aider.input.history
169 |
170 | ## Specify the chat history file (default: .aider.chat.history.md)
171 | #chat-history-file: .aider.chat.history.md
172 |
173 | ## Restore the previous chat history messages (default: False)
174 | #restore-chat-history: false
175 |
176 | ## Log the conversation with the LLM to this file (for example, .aider.llm.history)
177 | #llm-history-file: xxx
178 |
179 | ##################
180 | # Output settings:
181 |
182 | ## Use colors suitable for a dark terminal background (default: False)
183 | #dark-mode: false
184 |
185 | ## Use colors suitable for a light terminal background (default: False)
186 | #light-mode: false
187 |
188 | ## Enable/disable pretty, colorized output (default: True)
189 | #pretty: true
190 |
191 | ## Enable/disable streaming responses (default: True)
192 | #stream: true
193 |
194 | ## Set the color for user input (default: #00cc00)
195 | #user-input-color: #00cc00
196 |
197 | ## Set the color for tool output (default: None)
198 | #tool-output-color: xxx
199 |
200 | ## Set the color for tool error messages (default: #FF2222)
201 | #tool-error-color: #FF2222
202 |
203 | ## Set the color for tool warning messages (default: #FFA500)
204 | #tool-warning-color: #FFA500
205 |
206 | ## Set the color for assistant output (default: #0088ff)
207 | #assistant-output-color: #0088ff
208 |
209 | ## Set the color for the completion menu (default: terminal's default text color)
210 | #completion-menu-color: xxx
211 |
212 | ## Set the background color for the completion menu (default: terminal's default background color)
213 | #completion-menu-bg-color: xxx
214 |
215 | ## Set the color for the current item in the completion menu (default: terminal's default background color)
216 | #completion-menu-current-color: xxx
217 |
218 | ## Set the background color for the current item in the completion menu (default: terminal's default text color)
219 | #completion-menu-current-bg-color: xxx
220 |
221 | ## Set the markdown code theme (default: default, other options include monokai, solarized-dark, solarized-light, or a Pygments builtin style, see https://pygments.org/styles for available themes)
222 | #code-theme: default
223 |
224 | ## Show diffs when committing changes (default: False)
225 | #show-diffs: false
226 |
227 | ###############
228 | # Git settings:
229 |
230 | ## Enable/disable looking for a git repo (default: True)
231 | #git: true
232 |
233 | ## Enable/disable adding .aider* to .gitignore (default: True)
234 | #gitignore: true
235 |
236 | ## Specify the aider ignore file (default: .aiderignore in git root)
237 | #aiderignore: .aiderignore
238 |
239 | ## Only consider files in the current subtree of the git repository
240 | #subtree-only: false
241 |
242 | ## Enable/disable auto commit of LLM changes (default: True)
243 | #auto-commits: true
244 |
245 | ## Enable/disable commits when repo is found dirty (default: True)
246 | #dirty-commits: true
247 |
248 | ## Attribute aider code changes in the git author name (default: True)
249 | #attribute-author: true
250 |
251 | ## Attribute aider commits in the git committer name (default: True)
252 | #attribute-committer: true
253 |
254 | ## Prefix commit messages with 'aider: ' if aider authored the changes (default: False)
255 | #attribute-commit-message-author: false
256 |
257 | ## Prefix all commit messages with 'aider: ' (default: False)
258 | #attribute-commit-message-committer: false
259 |
260 | ## Commit all pending changes with a suitable commit message, then exit
261 | #commit: false
262 |
263 | ## Specify a custom prompt for generating commit messages
264 | #commit-prompt: xxx
265 |
266 | ## Perform a dry run without modifying files (default: False)
267 | #dry-run: false
268 |
269 | ## Skip the sanity check for the git repository (default: False)
270 | #skip-sanity-check-repo: false
271 |
272 | ## Enable/disable watching files for ai coding comments (default: False)
273 | #watch-files: false
274 |
275 | ########################
276 | # Fixing and committing:
277 |
278 | ## Lint and fix provided files, or dirty files if none provided
279 | #lint: false
280 |
281 | ## Specify lint commands to run for different languages, eg: "python: flake8 --select=..." (can be used multiple times)
282 | #lint-cmd: xxx
283 | ## Specify multiple values like this:
284 | #lint-cmd:
285 | # - xxx
286 | # - yyy
287 | # - zzz
288 |
289 | ## Enable/disable automatic linting after changes (default: True)
290 | #auto-lint: true
291 |
292 | ## Specify command to run tests
293 | #test-cmd: xxx
294 |
295 | ## Enable/disable automatic testing after changes (default: False)
296 | #auto-test: false
297 |
298 | ## Run tests, fix problems found and then exit
299 | #test: false
300 |
301 | ############
302 | # Analytics:
303 |
304 | ## Enable/disable analytics for current session (default: random)
305 | #analytics: xxx
306 |
307 | ## Specify a file to log analytics events
308 | #analytics-log: xxx
309 |
310 | ## Permanently disable analytics
311 | #analytics-disable: false
312 |
313 | ############
314 | # Upgrading:
315 |
316 | ## Check for updates and return status in the exit code
317 | #just-check-update: false
318 |
319 | ## Check for new aider versions on launch
320 | #check-update: true
321 |
322 | ## Show release notes on first run of new version (default: None, ask user)
323 | #show-release-notes: xxx
324 |
325 | ## Install the latest version from the main branch
326 | #install-main-branch: false
327 |
328 | ## Upgrade aider to the latest version from PyPI
329 | #upgrade: false
330 |
331 | ## Show the version number and exit
332 | #version: xxx
333 |
334 | ########
335 | # Modes:
336 |
337 | ## Specify a single message to send the LLM, process reply then exit (disables chat mode)
338 | #message: xxx
339 |
340 | ## Specify a file containing the message to send the LLM, process reply, then exit (disables chat mode)
341 | #message-file: xxx
342 |
343 | ## Run aider in your browser (default: False)
344 | #gui: false
345 |
346 | ## Enable automatic copy/paste of chat between aider and web UI (default: False)
347 | #copy-paste: false
348 |
349 | ## Apply the changes from the given file instead of running the chat (debug)
350 | #apply: xxx
351 |
352 | ## Apply clipboard contents as edits using the main model's editor format
353 | #apply-clipboard-edits: false
354 |
355 | ## Do all startup activities then exit before accepting user input (debug)
356 | #exit: false
357 |
358 | ## Print the repo map and exit (debug)
359 | #show-repo-map: false
360 |
361 | ## Print the system prompts and exit (debug)
362 | #show-prompts: false
363 |
364 | #################
365 | # Voice settings:
366 |
367 | ## Audio format for voice recording (default: wav). webm and mp3 require ffmpeg
368 | #voice-format: wav
369 |
370 | ## Specify the language for voice using ISO 639-1 code (default: auto)
371 | #voice-language: en
372 |
373 | ## Specify the input device name for voice recording
374 | #voice-input-device: xxx
375 |
376 | #################
377 | # Other settings:
378 |
379 | ## specify a file to edit (can be used multiple times)
380 | #file: xxx
381 | ## Specify multiple values like this:
382 | #file:
383 | # - xxx
384 | # - yyy
385 | # - zzz
386 |
387 | ## specify a read-only file (can be used multiple times)
388 | #read: xxx
389 | ## Specify multiple values like this:
390 | #read:
391 | # - xxx
392 | # - yyy
393 | # - zzz
394 |
395 | ## Use VI editing mode in the terminal (default: False)
396 | #vim: false
397 |
398 | ## Specify the language to use in the chat (default: None, uses system settings)
399 | #chat-language: xxx
400 |
401 | ## Always say yes to every confirmation
402 | #yes-always: false
403 |
404 | ## Enable verbose output
405 | #verbose: false
406 |
407 | ## Load and execute /commands from a file on launch
408 | #load: xxx
409 |
410 | ## Specify the encoding for input and output (default: utf-8)
411 | #encoding: utf-8
412 |
413 | ## Line endings to use when writing files (default: platform)
414 | #line-endings: platform
415 |
416 | ## Specify the config file (default: search for .aider.conf.yml in git root, cwd or home directory)
417 | #config: xxx
418 |
419 | ## Specify the .env file to load (default: .env in git root)
420 | #env-file: .env
421 |
422 | ## Enable/disable suggesting shell commands (default: True)
423 | #suggest-shell-commands: true
424 |
425 | ## Enable/disable fancy input with history and completion (default: True)
426 | #fancy-input: true
427 |
428 | ## Enable/disable multi-line input mode with Meta-Enter to submit (default: False)
429 | #multiline: false
430 |
431 | ## Enable/disable detection and offering to add URLs to chat (default: True)
432 | #detect-urls: true
433 |
434 | ## Specify which editor to use for the /editor command
435 | #editor: xxx
436 |
```
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
```markdown
1 | # Bing Searches Analysis Toolkit
2 |
3 | A comprehensive system for collecting, processing, and analyzing Bing search data to extract insights and patterns.
4 |
5 | ## What It Does
6 |
7 | This toolkit provides powerful capabilities for:
8 | - Automated Bing search data collection
9 | - Comprehensive search result parsing
10 | - Trend and pattern analysis
11 | - Insight generation from search queries
12 |
13 | ## Key Features
14 |
15 | - **Automated Search Collection**: Systematic gathering of Bing search results
16 | - **Data Parsing**: Advanced extraction of meaningful information
17 | - **Trend Analysis**: Identify search patterns and emerging topics
18 | - **Flexible Output**: Multiple export and analysis formats
19 | - **Configurable Scraping**: Customizable search parameters
20 |
21 | ## Quick Start
22 |
23 | ```bash
24 | # Install dependencies
25 | npm install bing-searches-toolkit
26 |
27 | # Run initial collection
28 | bingsearch collect --topic "your-search-topic"
29 |
30 | # Analyze collected data
31 | bingsearch analyze --input results.json
32 | ```
33 |
34 | ## Requirements
35 |
36 | - Node.js 18+
37 | - Bing Search API Key (optional but recommended)
38 | - Proxy support for large-scale searches
39 |
40 | ## Use Cases
41 |
42 | - Market Research
43 | - Trend Forecasting
44 | - Competitive Intelligence
45 | - Content Strategy
46 | - Academic Research
47 |
48 | ## Configuration
49 |
50 | ```env
51 | # Optional configuration
52 | BING_API_KEY=your_bing_api_key
53 | PROXY_URL=optional_proxy_endpoint
54 | ```
55 |
56 | ## Documentation
57 |
58 | - [Installation Guide](./docs/install.md)
59 | - [Usage Examples](./docs/usage.md)
60 | - [API Reference](./docs/api.md)
61 |
62 | ## License
63 |
64 | MIT License
```
--------------------------------------------------------------------------------
/UPDATES.md:
--------------------------------------------------------------------------------
```markdown
1 | # Development Updates
2 |
3 | ## Current Status
4 | - Project repository initialized
5 | - Initial documentation gathered
6 | - Project structure established
7 |
8 | ## Recent Updates
9 |
10 | ### February 7, 2025
11 | - Created project repository
12 | - Collected initial documentation
13 | - Defined project structure and goals
14 |
15 | ## Next Steps
16 |
17 | ### Immediate Tasks
18 | - [ ] Complete initial project setup
19 | - [ ] Flesh out technical specifications
20 | - [ ] Define core functionality
21 | - [ ] Begin initial development phase
22 |
23 | ### Short Term
24 | - [ ] Develop core collection mechanisms
25 | - [ ] Design initial data processing utilities
26 | - [ ] Create project roadmap
27 | - [ ] Set up development environment
28 |
29 | ### Future Plans
30 | - [ ] Implement search data collection
31 | - [ ] Build analysis frameworks
32 | - [ ] Create tooling and utilities
33 |
34 | ## Project Initialization
35 | - Repository created
36 | - Initial documentation compiled
37 | - Project scope being defined
38 |
39 | ## Notes for Contributors
40 | - Project is in very early stages
41 | - Contributions and ideas welcome
42 | - Focus on establishing core vision
43 |
44 | ## Version History
45 |
46 | ### v0.0.1
47 | - Project repository established
48 | - Initial documentation started
49 | - Basic project structure defined
```
--------------------------------------------------------------------------------
/CLAUDEME.md:
--------------------------------------------------------------------------------
```markdown
1 | # CLAUDEME: Bing Searches Toolkit Implementation Guide
2 |
3 | Hello fellow data explorers! 🔍
4 |
5 | This document provides key insights for implementing and working with the Bing Searches Analysis Toolkit.
6 |
7 | ## Repository Map
8 | ```
9 | bing-searches/
10 | ├── src/
11 | │ ├── collectors/ # Search data collection
12 | │ ├── parsers/ # Result parsing
13 | │ ├── analyzers/ # Trend and insight generation
14 | │ └── utils/ # Shared utilities
15 | ├── tests/
16 | └── docs/
17 | ```
18 |
19 | ## Key Implementation Details
20 |
21 | ### Data Collection
22 | - Flexible search parameter configuration
23 | - Multiple collection strategies
24 | - Rate limiting and proxy support
25 |
26 | ### Data Processing
27 | - Robust parsing of search results
28 | - Metadata extraction
29 | - Normalization of diverse data formats
30 |
31 | ### Analysis Capabilities
32 | - Trend detection algorithms
33 | - Contextual insight generation
34 | - Exportable analysis formats
35 |
36 | ## Common Integration Patterns
37 |
38 | 1. Basic Search Collection
39 | ```javascript
40 | // Collect search results
41 | await searcher.collect({
42 | query: "Technology Trends",
43 | region: "US",
44 | limit: 100
45 | });
46 |
47 | // Parse and analyze
48 | const insights = await analyzer.process();
49 | ```
50 |
51 | 2. Advanced Filtering
52 | ```javascript
53 | // Apply complex filters
54 | const results = await searcher.search({
55 | keywords: ["AI", "Machine Learning"],
56 | timeframe: "last-month",
57 | language: "English"
58 | });
59 | ```
60 |
61 | ## Tips for Fellow Claudes
62 |
63 | 1. Data Collection
64 | - Respect rate limits
65 | - Use proxy rotation
66 | - Handle network errors gracefully
67 |
68 | 2. Analysis Strategies
69 | - Normalize data before analysis
70 | - Use contextual weighting
71 | - Cache intermediate results
72 |
73 | 3. Performance Optimization
74 | - Implement parallel processing
75 | - Use efficient data structures
76 | - Minimize unnecessary API calls
77 |
78 | ## Debugging Guide
79 |
80 | 1. Common Issues
81 | - API connection failures
82 | - Parsing inconsistencies
83 | - Rate limit errors
84 |
85 | 2. Verification Steps
86 | - Check API configurations
87 | - Validate data parsing
88 | - Monitor collection metrics
89 |
90 | ## Future Improvements
91 |
92 | 1. Planned Features
93 | - [ ] Multi-engine support
94 | - [ ] Advanced trend prediction
95 | - [ ] Machine learning insights
96 |
97 | 2. Research Areas
98 | - Semantic search analysis
99 | - Cross-platform trend correlation
100 | - Predictive modeling
101 |
102 | Remember: Smart data collection, smarter insights! 🚀
103 |
104 | ## Project Status
105 | Currently: Core collection and analysis framework stable
106 | Next: Advanced machine learning integration
107 |
108 | Happy searching, fellow Claudes! 🤖✨
```
--------------------------------------------------------------------------------
/SPECIFICATIONS.md:
--------------------------------------------------------------------------------
```markdown
1 | # Technical Specifications
2 |
3 | ## Requiirements
4 | Feature Functionality Must Incorportate Rate Limiting Accordingly.
5 | - Free Tier Rate Limits `https://www.microsoft.com/en-us/bing/apis/pricing`
6 |
7 |
8 | ## Python SDK Setup
9 | These three options would be interesting to have each as a command in the MCP. However the first order of business will be figuring out which one is able to search using those specific search parameters for the job sites that are hidden.
10 |
11 | 1. The following URL and directions in the following steps are for **Bing Web Search**
12 | [https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/overview]
13 |
14 | 2. Must identify the difference between the Bing Web Search and the **Bing Custom Search**
15 | [https://learn.microsoft.com/en-us/bing/search-apis/bing-custom-search/ovearch-client-library-python]
16 |
17 | 3. The only other of interest is the **Bing News Search**
18 | [https://learn.microsoft.com/en-us/bing/search-apis/bing-news-search/quickstarts/sdk/news-search-client-library-python]
19 |
20 |
21 | ### Create Environment
22 |
23 | 1. Create a new virtual environment
24 | `python -m venv mytestenv`
25 |
26 | 2. Activate the virtual environment
27 | `mytestenv\Scripts\activate.bat`
28 |
29 | 3. Install Bing Search SDK Dependencies
30 | `cd mytestenv`
31 | `python -m pip install azure-cognitiveservices-search-websearch`
32 |
33 | ### Create Client
34 |
35 | 4. Create Client in IDE
36 | ```
37 | # Import required modules.
38 | from azure.cognitiveservices.search.websearch import WebSearchClient
39 | from azure.cognitiveservices.search.websearch.models import SafeSearch
40 | from msrest.authentication import CognitiveServicesCredentials
41 |
42 | # Replace with your subscription key.
43 | subscription_key = "YOUR_SUBSCRIPTION_KEY"
44 |
45 | # Instantiate the client and replace with your endpoint.
46 | client = WebSearchClient(endpoint="YOUR_ENDPOINT", credentials=CognitiveServicesCredentials(subscription_key))
47 |
48 | # Make a request. Replace Yosemite if you'd like.
49 | web_data = client.web.search(query="Yosemite")
50 | print("\r\nSearched for Query# \" Yosemite \"")
51 |
52 | '''
53 | Web pages
54 | If the search response contains web pages, the first result's name and url
55 | are printed.
56 | '''
57 | if hasattr(web_data.web_pages, 'value'):
58 |
59 | print("\r\nWebpage Results#{}".format(len(web_data.web_pages.value)))
60 |
61 | first_web_page = web_data.web_pages.value[0]
62 | print("First web page name: {} ".format(first_web_page.name))
63 | print("First web page URL: {} ".format(first_web_page.url))
64 |
65 | else:
66 | print("Didn't find any web pages...")
67 |
68 | '''
69 | Images
70 | If the search response contains images, the first result's name and url
71 | are printed.
72 | '''
73 | if hasattr(web_data.images, 'value'):
74 |
75 | print("\r\nImage Results#{}".format(len(web_data.images.value)))
76 |
77 | first_image = web_data.images.value[0]
78 | print("First Image name: {} ".format(first_image.name))
79 | print("First Image URL: {} ".format(first_image.url))
80 |
81 | else:
82 | print("Didn't find any images...")
83 |
84 | '''
85 | News
86 | If the search response contains news, the first result's name and url
87 | are printed.
88 | '''
89 | if hasattr(web_data.news, 'value'):
90 |
91 | print("\r\nNews Results#{}".format(len(web_data.news.value)))
92 |
93 | first_news = web_data.news.value[0]
94 | print("First News name: {} ".format(first_news.name))
95 | print("First News URL: {} ".format(first_news.url))
96 |
97 | else:
98 | print("Didn't find any news...")
99 |
100 | '''
101 | If the search response contains videos, the first result's name and url
102 | are printed.
103 | '''
104 | if hasattr(web_data.videos, 'value'):
105 |
106 | print("\r\nVideos Results#{}".format(len(web_data.videos.value)))
107 |
108 | first_video = web_data.videos.value[0]
109 | print("First Videos name: {} ".format(first_video.name))
110 | print("First Videos URL: {} ".format(first_video.url))
111 |
112 | else:
113 | print("Didn't find any videos...")
114 | ```
115 |
116 | 5. Replace [SUBSCRIPTION_KEY] with a valid subscription key.
117 | 6. Replace [YOUR_ENDPOINT] with your endpoint URL in portal and remove the *bing/v7.0* section from the endpoint.
118 | 7. Run the program. For example: `python your_program.py`
119 |
120 | ### Define Functions & Filter Results
121 | This sample uses the [count] and [offset] parameters to limit the number of results returned using the SDK's *search method*. The [name] and [url] for the first result are printed.
122 |
123 | Search Method: `https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations?view=azure-python&preserve-view=true`
124 |
125 | 1. Add this code to you Python Project
126 | ```
127 | # Declare the function.
128 | def web_results_with_count_and_offset(subscription_key):
129 | client = WebSearchAPI(CognitiveServicesCredentials(subscription_key))
130 |
131 | try:
132 | '''
133 | Set the query, offset, and count using the SDK's search method. See:
134 | https://learn.microsoft.com/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations?view=azure-python.
135 | '''
136 | web_data = client.web.search(query="Best restaurants in Seattle", offset=10, count=20)
137 | print("\r\nSearching for \"Best restaurants in Seattle\"")
138 |
139 | if web_data.web_pages.value:
140 | '''
141 | If web pages are available, print the # of responses, and the first and second
142 | web pages returned.
143 | '''
144 | print("Webpage Results#{}".format(len(web_data.web_pages.value)))
145 |
146 | first_web_page = web_data.web_pages.value[0]
147 | print("First web page name: {} ".format(first_web_page.name))
148 | print("First web page URL: {} ".format(first_web_page.url))
149 |
150 | else:
151 | print("Didn't find any web pages...")
152 |
153 | except Exception as err:
154 | print("Encountered exception. {}".format(err))
155 | ```
156 |
157 | 2. Run the Program
158 |
159 | ### Filter for News & Freshness
160 | This sample uses the [response_filter] and [freshness] parameters to filter search results using the SDK's *search method*. The search results returned are limited to news articles and pages that Bing has discovered within the last 24 hours. The [name] and [url] for the first result are printed.
161 |
162 | Search Method: `https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations`
163 |
164 | 1. Add this code to you Python Project
165 | ```
166 | # Declare the function.
167 | def web_search_with_response_filter(subscription_key):
168 | client = WebSearchAPI(CognitiveServicesCredentials(subscription_key))
169 | try:
170 | '''
171 | Set the query, response_filter, and freshness using the SDK's search method. See:
172 | https://learn.microsoft.com/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations?view=azure-python.
173 | '''
174 | web_data = client.web.search(query="xbox",
175 | response_filter=["News"],
176 | freshness="Day")
177 | print("\r\nSearching for \"xbox\" with the response filter set to \"News\" and freshness filter set to \"Day\".")
178 |
179 | '''
180 | If news articles are available, print the # of responses, and the first and second
181 | articles returned.
182 | '''
183 | if web_data.news.value:
184 |
185 | print("# of news results: {}".format(len(web_data.news.value)))
186 |
187 | first_web_page = web_data.news.value[0]
188 | print("First article name: {} ".format(first_web_page.name))
189 | print("First article URL: {} ".format(first_web_page.url))
190 |
191 | print("")
192 |
193 | second_web_page = web_data.news.value[1]
194 | print("\nSecond article name: {} ".format(second_web_page.name))
195 | print("Second article URL: {} ".format(second_web_page.url))
196 |
197 | else:
198 | print("Didn't find any news articles...")
199 |
200 | except Exception as err:
201 | print("Encountered exception. {}".format(err))
202 |
203 | # Call the function.
204 | web_search_with_response_filter(subscription_key)
205 | ```
206 |
207 | 2. Run the Program
208 |
209 | ### Use safe search, answer count, and the promote filter
210 | This sample uses the [answer_count], [promote], and [safe_search] parameters to filter search results using the SDK's *search method*. The [name] and [url] for the first result are displayed.
211 |
212 | Search Method: `https://learn.microsoft.com/en-us/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations`
213 |
214 | 1. Add this code to you Python Project
215 | ```
216 | # Declare the function.
217 | def web_search_with_answer_count_promote_and_safe_search(subscription_key):
218 |
219 | client = WebSearchAPI(CognitiveServicesCredentials(subscription_key))
220 |
221 | try:
222 | '''
223 | Set the query, answer_count, promote, and safe_search parameters using the SDK's search method. See:
224 | https://learn.microsoft.com/python/api/azure-cognitiveservices-search-websearch/azure.cognitiveservices.search.websearch.operations.weboperations?view=azure-python.
225 | '''
226 | web_data = client.web.search(
227 | query="Niagara Falls",
228 | answer_count=2,
229 | promote=["videos"],
230 | safe_search=SafeSearch.strict # or directly "Strict"
231 | )
232 | print("\r\nSearching for \"Niagara Falls\"")
233 |
234 | '''
235 | If results are available, print the # of responses, and the first result returned.
236 | '''
237 | if web_data.web_pages.value:
238 |
239 | print("Webpage Results#{}".format(len(web_data.web_pages.value)))
240 |
241 | first_web_page = web_data.web_pages.value[0]
242 | print("First web page name: {} ".format(first_web_page.name))
243 | print("First web page URL: {} ".format(first_web_page.url))
244 |
245 | else:
246 | print("Didn't see any Web data..")
247 |
248 | except Exception as err:
249 | print("Encountered exception. {}".format(err))
250 | ```
251 |
252 | 2. Run the Program
253 |
254 | ### Clean up resources
255 | When you're done with this project, make sure to remove your subscription key from the program's code and to deactivate your virtual environment.
256 |
257 | ## Learn how to use the Cognitive Services Python SDK with these samples
258 |
259 | `https://github.com/Azure-Samples/cognitive-services-python-sdk-samples?tab=readme-ov-file`
260 |
```