Jetzt läuft alles wiededer nach dem merge (Error Correction)
This commit is contained in:
		
							parent
							
								
									8a00931f49
								
							
						
					
					
						commit
						1742f768bf
					
				
					 1 changed files with 56 additions and 0 deletions
				
			
		
							
								
								
									
										56
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										56
									
								
								src/main.rs
									
										
									
									
									
								
							| 
						 | 
					@ -38,6 +38,8 @@ pub mod variables_and_settings;
 | 
				
			||||||
use std::borrow::Cow;
 | 
					use std::borrow::Cow;
 | 
				
			||||||
use std::error::Error;
 | 
					use std::error::Error;
 | 
				
			||||||
use std::env;
 | 
					use std::env;
 | 
				
			||||||
 | 
					use std::fs::File;
 | 
				
			||||||
 | 
					use std::io::Read;
 | 
				
			||||||
// use std::future::Future;
 | 
					// use std::future::Future;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use chrono::{Datelike, Local, NaiveDate, Weekday};
 | 
					use chrono::{Datelike, Local, NaiveDate, Weekday};
 | 
				
			||||||
| 
						 | 
					@ -48,6 +50,7 @@ use uuid::Uuid;
 | 
				
			||||||
use lettre::{Message, SmtpTransport, Transport};
 | 
					use lettre::{Message, SmtpTransport, Transport};
 | 
				
			||||||
use lettre::message::{header, SinglePart};
 | 
					use lettre::message::{header, SinglePart};
 | 
				
			||||||
use lettre::transport::smtp::authentication::Credentials;
 | 
					use lettre::transport::smtp::authentication::Credentials;
 | 
				
			||||||
 | 
					use reqwest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const FALLBACK_TEMPLATE: &str = variables_and_settings::FALLBACK_TEMPLATE;
 | 
					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<str> = re_top_instructions.replace_all(&pad_content, "---");
 | 
					    let result: Cow<str> = re_top_instructions.replace_all(&pad_content, "---");
 | 
				
			||||||
    result.to_string() // Wenn es nicht geklappt hat, wird einfach das Pad mit dem Kommentar zurückgegeben
 | 
					    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<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"))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue