cleaner code
All checks were successful
CI/CD Pipeline / deploy-main (push) Successful in 1m18s

This commit is contained in:
2025-10-02 10:08:12 +02:00
parent 46090d2632
commit 88bdc07e1b
2 changed files with 21 additions and 20 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/target /target
muell.ics

View File

@@ -1,7 +1,7 @@
use regex::Regex;
use chrono::{NaiveDate, Utc}; use chrono::{NaiveDate, Utc};
use uuid::Uuid; use regex::Regex;
use std::process; use std::process;
use uuid::Uuid;
fn parse_german_date(date_str: &str) -> Option<NaiveDate> { fn parse_german_date(date_str: &str) -> Option<NaiveDate> {
NaiveDate::parse_from_str(date_str, "%d.%m.%Y").ok() NaiveDate::parse_from_str(date_str, "%d.%m.%Y").ok()
@@ -42,9 +42,9 @@ fn fetch_waste_dates() -> Result<String, Box<dyn std::error::Error>> {
} }
fn html_to_ics(html_content: &str) -> Result<String, &'static str> { fn html_to_ics(html_content: &str) -> Result<String, &'static str> {
let pattern = Regex::new( let pattern =
r#"td_kal.*?(\d{2}\.\d{2}\.\d{4}).*?<a[^>]*>([^<]+)</a>.*?<span>([^<]+)</span>"# Regex::new(r"td_kal.*?(\d{2}\.\d{2}\.\d{4}).*?<a[^>]*>([^<]+)</a>.*?<span>([^<]+)</span>")
).unwrap(); .unwrap();
let mut ics_content = String::from( let mut ics_content = String::from(
"BEGIN:VCALENDAR\n\ "BEGIN:VCALENDAR\n\
@@ -54,7 +54,7 @@ fn html_to_ics(html_content: &str) -> Result<String, &'static str> {
METHOD:PUBLISH\n\ METHOD:PUBLISH\n\
X-WR-CALNAME:Abfalltermine Luftenberg\n\ X-WR-CALNAME:Abfalltermine Luftenberg\n\
X-WR-CALDESC:Waste collection dates for Luftenberg an der Donau\n\ X-WR-CALDESC:Waste collection dates for Luftenberg an der Donau\n\
X-WR-TIMEZONE:Europe/Vienna\n" X-WR-TIMEZONE:Europe/Vienna\n",
); );
let mut event_count = 0; let mut event_count = 0;
@@ -84,7 +84,7 @@ fn main() {
let html_content = match fetch_waste_dates() { let html_content = match fetch_waste_dates() {
Ok(content) => content, Ok(content) => content,
Err(e) => { Err(e) => {
eprintln!("Error fetching waste dates: {}", e); eprintln!("Error fetching waste dates: {e}");
process::exit(1); process::exit(1);
} }
}; };
@@ -92,10 +92,10 @@ fn main() {
let ics_output = match html_to_ics(&html_content) { let ics_output = match html_to_ics(&html_content) {
Ok(content) => content, Ok(content) => content,
Err(e) => { Err(e) => {
eprintln!("Error: {}", e); eprintln!("Error: {e}");
process::exit(1); process::exit(1);
} }
}; };
println!("{}", ics_output); println!("{ics_output}");
} }