-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openai): add openai flag dynamic js snippets
- Loading branch information
Showing
8 changed files
with
209 additions
and
22 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
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
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,29 @@ | ||
import asyncio | ||
|
||
from spider_rs import Website | ||
|
||
async def main(): | ||
website = ( | ||
Website("https://choosealicense.com", False) | ||
.with_screenshot({ | ||
"params": { | ||
"cdp_params": { | ||
"format": None, | ||
"quality": None, | ||
"clip": None, | ||
"from_surface": None, | ||
"capture_beyond_viewport": None | ||
}, | ||
"full_page": True, | ||
"omit_background": False | ||
}, | ||
"bytes": False, | ||
"save": True, | ||
"output_dir": None | ||
}) | ||
) | ||
website.crawl(None, None, True) | ||
print(website.get_links()) | ||
|
||
|
||
asyncio.run(main()) |
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
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,56 @@ | ||
use pyo3::types::{PyAny, PyDict, PyList}; | ||
use pyo3::PyResult; | ||
use serde_json::Value as JsonValue; | ||
|
||
/// convert pyobject to json value | ||
pub fn pyobj_to_json_value(obj: &PyAny) -> PyResult<JsonValue> { | ||
// Handle None | ||
if obj.is_none() { | ||
Ok(JsonValue::Null) | ||
} else if let Ok(val) = obj.extract::<bool>() { | ||
Ok(JsonValue::Bool(val)) | ||
} else if let Ok(val) = obj.extract::<i64>() { | ||
Ok(JsonValue::Number(val.into())) | ||
} else if let Ok(val) = obj.extract::<f64>() { | ||
if let Some(num) = serde_json::Number::from_f64(val) { | ||
Ok(JsonValue::Number(num)) | ||
} else { | ||
Err(pyo3::exceptions::PyValueError::new_err( | ||
"Float value out of range", | ||
)) | ||
} | ||
} else if let Ok(val) = obj.extract::<&str>() { | ||
Ok(JsonValue::String(val.to_string())) | ||
} else if let Ok(list) = obj.downcast::<PyList>() { | ||
let mut vec = Vec::new(); | ||
for item in list.iter() { | ||
vec.push(pyobj_to_json_value(item)?); | ||
} | ||
Ok(JsonValue::Array(vec)) | ||
} else if let Ok(dict) = obj.downcast::<PyDict>() { | ||
let mut map = serde_json::Map::new(); | ||
for (k, v) in dict.iter() { | ||
let key: &str = k.extract()?; | ||
let value = pyobj_to_json_value(v)?; | ||
map.insert(key.to_string(), value); | ||
} | ||
Ok(JsonValue::Object(map)) | ||
} else { | ||
Err(pyo3::exceptions::PyTypeError::new_err( | ||
"Unsupported Python type", | ||
)) | ||
} | ||
} | ||
|
||
/// convert pydict to json value | ||
pub fn pydict_to_json_value(py_dict: &pyo3::types::PyDict) -> PyResult<JsonValue> { | ||
let mut map = serde_json::Map::new(); | ||
|
||
for (k, v) in py_dict.iter() { | ||
let key: &str = k.extract()?; | ||
let value: JsonValue = pyobj_to_json_value(v)?; | ||
map.insert(key.to_string(), value); | ||
} | ||
|
||
Ok(serde_json::Value::Object(map)) | ||
} |
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