MADE RUST TRANSFER ARGS TO PYTHON LETS GOOOOOOOOOOOOOOOOOOOOOOO
This commit is contained in:
+7
-4
@@ -4,7 +4,6 @@ mod events;
|
||||
mod messages;
|
||||
mod python;
|
||||
mod macros;
|
||||
mod python_comms;
|
||||
|
||||
use std::env;
|
||||
use std::process;
|
||||
@@ -42,7 +41,7 @@ async fn main() {
|
||||
&& !args.contains(&"--rs".to_string())
|
||||
{
|
||||
println!("----- PYTHON ONLY MODE -----");
|
||||
let _ = python::start();
|
||||
let _ = python::start(args);
|
||||
process::exit(0);
|
||||
}
|
||||
else if args.contains(&"--rs".to_string())
|
||||
@@ -54,15 +53,17 @@ async fn main() {
|
||||
}
|
||||
|
||||
let rt = Runtime::new().unwrap();
|
||||
let rust_args = args.clone();
|
||||
let python_args = args.clone();
|
||||
|
||||
let rust = thread::spawn(move || {
|
||||
rt.block_on(async {
|
||||
start(args).await;
|
||||
start(rust_args).await;
|
||||
});
|
||||
});
|
||||
|
||||
let python = thread::spawn(|| {
|
||||
let _ = python::start();
|
||||
let _ = python::start(python_args);
|
||||
});
|
||||
|
||||
rust.join().unwrap();
|
||||
@@ -71,6 +72,8 @@ async fn main() {
|
||||
|
||||
|
||||
async fn start(args: Vec<String>) {
|
||||
rs_println!("ARGS: {:?}", &args[1..]);
|
||||
|
||||
let data = gen_data(args);
|
||||
let mut bot = gen_bot(data).await;
|
||||
|
||||
|
||||
+4
-7
@@ -8,22 +8,18 @@ use pyo3::prelude::*;
|
||||
use pyo3::types::PyList;
|
||||
|
||||
|
||||
pub fn start() -> PyResult<()> {
|
||||
pub fn start(args: Vec<String>) -> PyResult<()> {
|
||||
rs_println!("Running Python program...");
|
||||
|
||||
let path = concat!(env!("CARGO_MANIFEST_DIR"), "\\src\\python");
|
||||
|
||||
let code = get_code(&(path.to_owned() + "\\main.py"));
|
||||
let app_path = CString::new(code).unwrap();
|
||||
let app_path = CString::new(format!("args = {:?}\n{}", args, code)).unwrap();
|
||||
|
||||
pyo3::prepare_freethreaded_python();
|
||||
|
||||
let from_python = Python::with_gil(|py| -> PyResult<Py<PyAny>> {
|
||||
let syspath = py
|
||||
.import("sys")?
|
||||
.getattr("path")?
|
||||
.downcast_into::<PyList>()?;
|
||||
|
||||
let syspath = py.import("sys")?.getattr("path")?.downcast_into::<PyList>()?;
|
||||
syspath.insert(0, path)?;
|
||||
let empty = CString::new("").unwrap();
|
||||
|
||||
@@ -38,6 +34,7 @@ pub fn start() -> PyResult<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
fn get_code(path: &str) -> String {
|
||||
return fs::read_to_string(path)
|
||||
.expect("Failed to read Python file.")
|
||||
|
||||
+6
-1
@@ -2,9 +2,11 @@ from io import TextIOWrapper
|
||||
from praw import models
|
||||
import praw
|
||||
import os
|
||||
|
||||
from macros import *
|
||||
|
||||
class Bot:
|
||||
args: list[str] = ["NO_RUST", "--dev", "--py"]
|
||||
password: str = os.environ.get("ASSISTANT_R_PASS")
|
||||
secret: str = os.environ.get("ASSISTANT_R_TOKEN")
|
||||
|
||||
@@ -22,4 +24,7 @@ class Bot:
|
||||
)
|
||||
sr: models.Subreddit = r.subreddit("bytedicetesting") #r.subreddit("boykisser")
|
||||
data_f: TextIOWrapper = None
|
||||
data: dict = {}
|
||||
data: dict = {}
|
||||
|
||||
def set_args(self, args: list[str]):
|
||||
self.args = args
|
||||
+6
-1
@@ -1,14 +1,19 @@
|
||||
import sys
|
||||
|
||||
from macros import *
|
||||
import bot as botPy
|
||||
import data
|
||||
from macros import *
|
||||
|
||||
|
||||
def main():
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
|
||||
bot = botPy.Bot()
|
||||
try: bot.set_args(args)
|
||||
except NameError:
|
||||
py_print("No command args found from Rust. Don't worry though, we have backup in place.")
|
||||
|
||||
py_print("ARGS:", str(bot.args[1:]))
|
||||
py_print("Reading data...")
|
||||
data.read_data(bot)
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
use serde_json::Value;
|
||||
|
||||
fn fetch_data() {
|
||||
// tell python to update JSON
|
||||
// read JSON
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user