first prototype
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1,3 @@ | ||||
| /target | ||||
| .envrc | ||||
| .direnv | ||||
|   | ||||
							
								
								
									
										1368
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1368
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -3,4 +3,13 @@ name = "vikunja-gatherer" | ||||
| version = "0.1.0" | ||||
| edition = "2021" | ||||
|  | ||||
| [lints.clippy] | ||||
| pedantic = "warn" | ||||
| nursery = "warn" | ||||
|  | ||||
| [dependencies] | ||||
| chrono = "0.4.38" | ||||
| markdown = "0.3.0" | ||||
| regex = "1.11.0" | ||||
| reqwest = { version = "0.12.8", features = ["blocking", "json"] } | ||||
| serde = { version = "1.0.210", features = ["derive"] } | ||||
|   | ||||
| @@ -24,7 +24,10 @@ | ||||
|         { | ||||
|           devShells.default = mkShell { | ||||
|             # 👇 we can just use `rustToolchain` here: | ||||
|             buildInputs = [ rustToolchain ]; | ||||
|             buildInputs = [ | ||||
|               rustToolchain | ||||
|               openssl | ||||
|             ]; | ||||
|           }; | ||||
|         } | ||||
|       ); | ||||
|   | ||||
							
								
								
									
										82
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -1,3 +1,81 @@ | ||||
| fn main() { | ||||
|     println!("Hello, world!"); | ||||
| use std::{env, fs}; | ||||
|  | ||||
| use chrono::{Datelike, Utc}; | ||||
| use regex::Regex; | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||||
| struct Task { | ||||
|     title: String, | ||||
|     created: String, | ||||
|     description: String, | ||||
|     done: bool, | ||||
| } | ||||
|  | ||||
| fn main() { | ||||
|     let client = reqwest::blocking::Client::new(); | ||||
|     // get all tasks | ||||
|     let response = client | ||||
|         .get("https://vikunja.luhbots-hannover.de/api/v1/tasks/all") | ||||
|         .header( | ||||
|             reqwest::header::AUTHORIZATION, | ||||
|             format!("Bearer {}", env::var("VIKUNJA_TOKEN").unwrap()), | ||||
|         ) | ||||
|         .query(&[ | ||||
|             // search for tasks containing "Teamtreffen" | ||||
|             ("s", "Teamtreffen"), | ||||
|             // sort by creation data | ||||
|             ("sort_by", "created"), | ||||
|             // sort in descending order (newest first) | ||||
|             ("order_by", "desc"), | ||||
|         ]) | ||||
|         .send() | ||||
|         .unwrap(); | ||||
|  | ||||
|     // get the task for today from the returned tasks | ||||
|     let now = Utc::now(); | ||||
|     let current_card_title = format!( | ||||
|         "Teamtreffen {:02}.{:02}.{}", | ||||
|         now.day() - 1, | ||||
|         now.month(), | ||||
|         now.year() | ||||
|     ); | ||||
|     println!("searching for task with title {current_card_title:?}"); | ||||
|     let task = response | ||||
|         .json::<Vec<Task>>() | ||||
|         .unwrap() | ||||
|         .into_iter() | ||||
|         .find(|task| task.title == current_card_title) | ||||
|         .unwrap(); | ||||
|  | ||||
|     let re = Regex::new("<p>([^<]+)</p>").unwrap(); | ||||
|     let points = re | ||||
|         .captures_iter(&task.description) | ||||
|         .map(|c| c.extract::<1>().1[0]) | ||||
|         .collect::<Vec<_>>(); | ||||
|  | ||||
|     let template = fs::read_to_string("../vorlage.md").unwrap(); | ||||
|  | ||||
|     let mut template = template.replace( | ||||
|         "dd.mm.yyyy", | ||||
|         format!("{:02}.{:02}.{}", now.day(), now.month(), now.year()).as_str(), | ||||
|     ); | ||||
|  | ||||
|     template.extend( | ||||
|         points | ||||
|             .iter() | ||||
|             .filter(|point| **point != "Rasender Report" && **point != "Was ging die Woche?") | ||||
|             .map(|point| format!("\n# {point}\n")), | ||||
|     ); | ||||
|  | ||||
|     fs::write( | ||||
|         format!( | ||||
|             "{:02}.{:02}.{:02}.md", | ||||
|             now.year() % 100, | ||||
|             now.month(), | ||||
|             now.day() | ||||
|         ), | ||||
|         template, | ||||
|     ) | ||||
|     .unwrap(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user