From 1742f768bf7664b397b468bd3d66b9d8076d7734 Mon Sep 17 00:00:00 2001 From: murmeldin Date: Fri, 2 Aug 2024 01:00:34 +0200 Subject: [PATCH] =?UTF-8?q?Jetzt=20l=C3=A4uft=20alles=20wiededer=20nach=20?= =?UTF-8?q?dem=20merge=20(Error=20Correction)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/main.rs b/src/main.rs index 71f3041..c36fd19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,8 @@ pub mod variables_and_settings; use std::borrow::Cow; use std::error::Error; use std::env; +use std::fs::File; +use std::io::Read; // use std::future::Future; use chrono::{Datelike, Local, NaiveDate, Weekday}; @@ -48,6 +50,7 @@ use uuid::Uuid; use lettre::{Message, SmtpTransport, Transport}; use lettre::message::{header, SinglePart}; use lettre::transport::smtp::authentication::Credentials; +use reqwest; const FALLBACK_TEMPLATE: &str = variables_and_settings::FALLBACK_TEMPLATE; @@ -405,3 +408,56 @@ fn try_to_remove_top_instructions (pad_content: String) -> String { let result: Cow = re_top_instructions.replace_all(&pad_content, "---"); result.to_string() // Wenn es nicht geklappt hat, wird einfach das Pad mit dem Kommentar zurückgegeben } + +fn pad_ins_wiki(old_pad_content: String) { + convert_markdown_to_mediawiki_and_save_as_txt(old_pad_content); + + // 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**"); + 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"); +} + +fn login_to_mediawiki (plenum_bot_user: String, plenum_bot_pw: String) -> Result> { + //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")) +} \ No newline at end of file