2024-08-02 21:19:54 +02:00
|
|
|
use std::error::Error;
|
2024-08-01 18:30:14 +02:00
|
|
|
use std::fs::File;
|
2024-08-02 21:19:54 +02:00
|
|
|
use std::io::Read;
|
2024-08-01 18:30:14 +02:00
|
|
|
|
|
|
|
pub fn pad_ins_wiki(old_pad_content: String) {
|
2024-08-02 21:19:54 +02:00
|
|
|
convert_markdown_to_mediawiki_and_save_as_txt(old_pad_content);
|
2024-08-01 18:30:14 +02:00
|
|
|
|
|
|
|
// Textdatei wieder einlesen
|
|
|
|
let mut file = File::open("pandoc-output.txt").expect("Fehler beim öffnen der MediaWiki-Textdatei!");
|
|
|
|
let mut contents = String::new();
|
|
|
|
file.read_to_string(&mut contents).expect("Fehler beim auslesen der MediaWiki-Textdatei!");
|
|
|
|
|
|
|
|
// Passwörter aus Datenbank lesen (ToBeDone)
|
|
|
|
let plenum_bot_user = String::from("PlenumBot@PlenumBot-PW1");
|
|
|
|
let plenum_bot_pw = String::from("**OLD_API_PW_REMOVED**");
|
2024-08-02 21:19:54 +02:00
|
|
|
let login_token = login_to_mediawiki(plenum_bot_user.clone(), plenum_bot_pw.clone()).expect("Fehler beim Einloggen!");
|
|
|
|
println!("plenum_bot_user: {plenum_bot_user}, plenum_bot_pw: {plenum_bot_pw}, login_token: {login_token}")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn convert_markdown_to_mediawiki_and_save_as_txt (old_pad_content: String) {
|
|
|
|
//Convert Markdown into Mediawiki
|
|
|
|
// Vanilla pandoc Befehl: pandoc --from markdown --to mediawiki --no-highlight
|
|
|
|
let mut p = pandoc::new();
|
|
|
|
p.set_input(pandoc::InputKind::Pipe(old_pad_content));
|
|
|
|
p.set_input_format(pandoc::InputFormat::Markdown, vec![]);
|
|
|
|
p.set_output(pandoc::OutputKind::File("./pandoc-output.txt".parse().unwrap()));
|
|
|
|
p.set_output_format(pandoc::OutputFormat::MediaWiki, vec![]);
|
|
|
|
p.execute().expect("Fehler beim Umwandeln des und speichern des Pads in eine mediawiki-Textdatei");
|
|
|
|
}
|
2024-08-01 18:30:14 +02:00
|
|
|
|
2024-08-02 21:19:54 +02:00
|
|
|
fn login_to_mediawiki (plenum_bot_user: String, plenum_bot_pw: String) -> Result<String, Box<dyn Error>> {
|
|
|
|
//let mut map = HashMap::new();
|
|
|
|
//map.insert("logintoken", "result");
|
|
|
|
let username = "cccb-wiki";
|
|
|
|
let password = "**OLD_PW_REMOVED**";
|
|
|
|
let auth_header_value = format!("{}:{}", username, password);
|
|
|
|
// let auth_header_value = format!("Basic {}", Engine::encode(&auth_value, ()));
|
|
|
|
/* NOCH NICHT GEFIXT
|
|
|
|
let client = reqwest::blocking::Client::new();
|
|
|
|
let resp = client
|
|
|
|
.get("https://wiki.berlin.ccc.de/api.php?action=query&meta=tokens&type=login&format=json")
|
|
|
|
.send()?
|
|
|
|
.text()?;
|
|
|
|
//let response = client
|
|
|
|
// .post("https://wiki.berlin.ccc.de/api.php?action=query&meta=tokens&type=login&format=json")
|
|
|
|
// .form(&[("Username", "cccb-wiki"), ("Password", "**OLD_PW_REMOVED**")])
|
|
|
|
// .send()
|
|
|
|
// .unwrap();
|
|
|
|
//.json(&map);
|
|
|
|
let html_source = resp.text()?;
|
|
|
|
//let login_token: String = map.get("logintoken").unwrap().to_string().clone();
|
|
|
|
println!("---HTML:---\n{}\n-----------", html_source);
|
|
|
|
|
|
|
|
*/
|
|
|
|
Ok(String::from("unimplemented"))
|
2024-08-01 18:30:14 +02:00
|
|
|
}
|