Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit 5b9f0d4

Browse files
committed
feature: Add python script to set MatterMost status
- Add python script - Run python script from rust
1 parent 40e1eeb commit 5b9f0d4

2 files changed

Lines changed: 63 additions & 31 deletions

File tree

software/raspberrypi/backend/python/mattermost.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#!/usr/bin/env python
22

3+
import sys
4+
35
from mattermostdriver import Driver
46

57

68
def main(*args):
7-
url = args[0]
8-
login_id = args[1]
9-
api_token = args[2]
10-
scheme = args[3]
11-
port = args[4]
12-
state = args[5]
9+
print(args)
10+
11+
url = args[0][0]
12+
login_id = args[0][1]
13+
api_token = args[0][2]
14+
scheme = args[0][3]
15+
port = args[0][4]
16+
state = args[0][5]
1317

1418
driver = Driver(
1519
{
@@ -42,3 +46,7 @@ def main(*args):
4246
)
4347

4448
driver.logout()
49+
50+
51+
if __name__ == "__main__":
52+
main(sys.argv[1:])
Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
pub mod configuration;
22

3-
// mod client;
3+
mod client;
4+
// mod types;
45

56
use std::process::Command;
67

78
use configuration::MatterMost;
89

910
pub fn mattermost(configuration: &MatterMost, state: bool) {
1011
if configuration.enable {
11-
// let code = std::include_str!("../../backend/python/mattermost.py");
12-
let _cmd = Command::new("./ve/bin/python")
12+
let code = std::include_str!("../../../backend/python/mattermost.py");
13+
let output = Command::new("python3")
14+
// let output = Command::new("./ve/bin/python3")
1315
.args([
14-
"./backend/python/mattermost.py ",
16+
// "python/mattermost.py",
17+
"-c",
18+
code,
1519
configuration.url.as_str(),
1620
configuration.loginid.as_str(),
1721
configuration.apitoken.as_str(),
@@ -21,14 +25,20 @@ pub fn mattermost(configuration: &MatterMost, state: bool) {
2125
])
2226
.output()
2327
.expect("Error: Failed to set MatterMost message");
28+
29+
println!("output start");
30+
use std::io::{self, Write};
31+
io::stdout().write_all(&output.stdout).unwrap();
32+
io::stderr().write_all(&output.stderr).unwrap();
33+
println!("output end");
2434
}
2535
}
2636

2737
#[cfg(test)]
2838
mod tests {
2939
use wiremock::{
3040
http::Method,
31-
matchers::{any, method},
41+
matchers::{body_json, header, method, path},
3242
{Mock, MockServer, ResponseTemplate},
3343
};
3444

@@ -40,7 +50,7 @@ mod tests {
4050
async fn mattermost_disabled() {
4151
let mock_server = MockServer::start().await;
4252

43-
Mock::given(method(Method::PUT))
53+
Mock::given(method(Method::GET))
4454
.respond_with(ResponseTemplate::new(200))
4555
.expect(0)
4656
.mount(&mock_server)
@@ -53,25 +63,39 @@ mod tests {
5363
mattermost(&mm_config, true);
5464
}
5565

56-
#[ignore = "TODO"]
57-
#[tokio::test]
58-
async fn send_mattermost_message() {
59-
let mock_server = MockServer::start().await;
66+
// #[tokio::test]
67+
// async fn send_mattermost_message() {
68+
// let mock_server = MockServer::start().await;
6069

61-
Mock::given(any())
62-
.respond_with(ResponseTemplate::new(200))
63-
.expect(1)
64-
.mount(&mock_server)
65-
.await;
70+
// let user_responce = super::types::user::UserResponce {
71+
// id: "bla".to_string(),
72+
// ..Default::default()
73+
// };
74+
// Mock::given(method(Method::GET))
75+
// .and(path("api/v4/users/me"))
76+
// .and(header("content-type", "application/json"))
77+
// .and(body_json(&user_responce))
78+
// .respond_with(ResponseTemplate::new(200))
79+
// .expect(1)
80+
// .mount(&mock_server)
81+
// .await;
6682

67-
let mm_config = MatterMost {
68-
enable: true,
69-
url: mock_server.uri(),
70-
loginid: String::new(),
71-
apitoken: String::new(),
72-
scheme: String::from("http"),
73-
port: mock_server.address().port(),
74-
};
75-
mattermost(&mm_config, true);
76-
}
83+
// // Mock::given(method(Method::GET))
84+
// // .and(path("api/v4/teams/name/section77"))
85+
// // .and(bearer_token(""))
86+
// // .respond_with(ResponseTemplate::new(200))
87+
// // .expect(1)
88+
// // .mount(&mock_server)
89+
// // .await;
90+
91+
// let mm_config = MatterMost {
92+
// enable: true,
93+
// url: mock_server.address().ip().to_string(),
94+
// loginid: String::from("clubstatus"),
95+
// apitoken: String::from("apitoken"),
96+
// scheme: String::from("http"),
97+
// port: mock_server.address().port(),
98+
// };
99+
// mattermost(&mm_config, true);
100+
// }
77101
}

0 commit comments

Comments
 (0)