-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
duck-duck-scrape is unmaintained and doesn't work anymore. We use the duckduckgo-search Python package instead. It is added to requirements.txt as an optional dependency.
- Loading branch information
1 parent
be27724
commit ad41eef
Showing
8 changed files
with
85 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
duckduckgo-search>=6.3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Similar to the CURL interface, the DDGS interface is used to communicate | ||
// with the `ddgs` CLI to perform DuckDuckGo searches. | ||
// REQUIREMENT: `pip install duckduckgo-search` in order to install the `ddgs` CLI. | ||
|
||
import { exec } from "child_process"; | ||
import { DEFAULT_ENV } from "#root/src/helpers/env.js"; | ||
import { escapeString } from "#root/src/helpers/helper.js"; | ||
import { getSupportPath } from "#root/src/helpers/extension_helper.js"; | ||
import fs from "fs"; | ||
|
||
// Return an array of the search results. | ||
// Each result is of the form: {title, href, body} | ||
export async function ddgsRequest(query, { maxResults = 15 } = {}) { | ||
query = escapeString(query); | ||
|
||
const ddgs_cmd = `ddgs text -k '${query}' -s off -m ${maxResults} -o "ddgs_results.json"`; | ||
const cwd = getSupportPath(); | ||
|
||
const childProcess = exec(ddgs_cmd, { | ||
env: DEFAULT_ENV, | ||
cwd: cwd, | ||
}); | ||
|
||
const exitCode = await new Promise((resolve, reject) => { | ||
childProcess.on("exit", () => resolve(0)); | ||
childProcess.on("error", (err) => reject(err)); | ||
}); | ||
|
||
if (exitCode !== 0) { | ||
throw new Error(`ddgs exited with code ${exitCode}`); | ||
} | ||
|
||
let results = fs.readFileSync(`${cwd}/ddgs_results.json`, "utf8"); | ||
results = JSON.parse(results); | ||
|
||
// clean up the file | ||
fs.writeFileSync(`${cwd}/ddgs_results.json`, ""); | ||
|
||
return results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const DEFAULT_PATH = | ||
"/opt/homebrew/opt/llvm/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin"; | ||
|
||
export const DEFAULT_ENV = { | ||
...process.env, | ||
PATH: DEFAULT_PATH, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters