Skip to content

Commit

Permalink
feat: add bindings functions
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Sep 29, 2023
1 parent aaa7da3 commit 1cf64cd
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

use std::{fmt::{self}, time::SystemTime};
use std::{fmt::{self}, time::SystemTime, path::PathBuf};
use rookie::{self, enums::{CookieToString,Cookie}};
use pyo3::types::{PyFloat, PyString, PyList};
use pyo3::prelude::*;
Expand Down Expand Up @@ -77,8 +77,41 @@ fn chrome(_py: Python, domains: Option<Vec<&str>>) -> PyResult<Vec<PyCookie>> {
Ok(py_cookies)
}


#[pyfunction]
fn brave(_py: Python, domains: Option<Vec<&str>>) -> PyResult<Vec<PyCookie>> {
let cookies = rookie::brave(domains).unwrap();

let py_cookies: Vec<PyCookie> = cookies.into_iter().map(|cookie| PyCookie { inner: cookie }).collect();

Ok(py_cookies)
}

#[pyfunction]
fn edge(_py: Python, domains: Option<Vec<&str>>) -> PyResult<Vec<PyCookie>> {
let cookies = rookie::edge(domains).unwrap();

let py_cookies: Vec<PyCookie> = cookies.into_iter().map(|cookie| PyCookie { inner: cookie }).collect();

Ok(py_cookies)
}


#[pyfunction]
fn chromium_based(_py: Python, key_path: String, db_path: String, domains: Option<Vec<&str>>) -> PyResult<Vec<PyCookie>> {
let cookies = rookie::chromium_based(PathBuf::from(key_path), PathBuf::from(db_path), domains).unwrap();

let py_cookies: Vec<PyCookie> = cookies.into_iter().map(|cookie| PyCookie { inner: cookie }).collect();

Ok(py_cookies)
}

#[pymodule]
fn rookiepy(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(firefox, m)?)?;
m.add_function(wrap_pyfunction!(chrome, m)?)?;
m.add_function(wrap_pyfunction!(brave, m)?)?;
m.add_function(wrap_pyfunction!(edge, m)?)?;
m.add_function(wrap_pyfunction!(chromium_based, m)?)?;
Ok(())
}

0 comments on commit 1cf64cd

Please sign in to comment.