push
This commit is contained in:
parent
5230762190
commit
e8e84e8d37
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -920,6 +920,12 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ics"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3ebec52f461ade2d19e7b594ecbcd0723ba0ab0eefa8aae2281b78ff461a91fa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
@ -1773,6 +1779,7 @@ dependencies = [
|
|||||||
"argon2",
|
"argon2",
|
||||||
"chrono",
|
"chrono",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"ics",
|
||||||
"log",
|
"log",
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_dyn_templates",
|
"rocket_dyn_templates",
|
||||||
|
@ -16,3 +16,4 @@ serde = { version = "1.0", features = [ "derive" ]}
|
|||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
chrono = { version = "0.4", features = ["serde"]}
|
chrono = { version = "0.4", features = ["serde"]}
|
||||||
tera = { version = "1.18", features = ["date-locale"]}
|
tera = { version = "1.18", features = ["date-locale"]}
|
||||||
|
ics = "0.5"
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
|
use ics::{
|
||||||
|
properties::{DtStart, Summary},
|
||||||
|
Event, ICalendar,
|
||||||
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::{FromRow, SqlitePool};
|
use sqlx::{FromRow, SqlitePool};
|
||||||
|
|
||||||
@ -207,25 +213,22 @@ FROM user_trip WHERE trip_details_id = (SELECT trip_details_id FROM planned_even
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_ics_feed(db: &SqlitePool) -> String {
|
pub async fn get_ics_feed(db: &SqlitePool) -> String {
|
||||||
let mut res = String::new();
|
let mut calendar = ICalendar::new("2.0", "ics-rs");
|
||||||
res.push_str("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//rudernlinz.at//Trips//DE\r\nX-WR-CALNAME:Ruderausfahrten\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Vienna\r\nTZURL:http://tzurl.org/zoneinfo-outlook/Europe/Vienna\r\nX-LIC-LOCATION:Europe/Vienna\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE");
|
|
||||||
|
|
||||||
let events = PlannedEvent::all(db).await;
|
let events = PlannedEvent::all(db).await;
|
||||||
for event in events {
|
for event in events {
|
||||||
res.push_str("\r\nBEGIN:VEVENT");
|
let mut vevent = Event::new(format!("{}@rudernlinz.at", event.id), "19900101T180000");
|
||||||
res.push_str(&format!("\r\nUID:{}@rudernlinz.at", event.id));
|
vevent.push(DtStart::new(format!(
|
||||||
res.push_str(&format!(
|
"TZID=Europe/Vienna:{}T{}00",
|
||||||
"\r\nDTSTART;TZID=Europe/Vienna:{}T{}00",
|
|
||||||
event.day.replace('-', ""),
|
event.day.replace('-', ""),
|
||||||
event.planned_starting_time.replace(':', "")
|
event.planned_starting_time.replace(':', "")
|
||||||
));
|
)));
|
||||||
res.push_str(&format!("\r\nDTSTAMP;TZID=Europe/Vienna:19900101T180000"));
|
vevent.push(Summary::new(event.name));
|
||||||
res.push_str(&format!("\r\nSUMMARY:{}", event.name));
|
calendar.add_event(vevent);
|
||||||
res.push_str("\r\nEND:VEVENT");
|
|
||||||
}
|
}
|
||||||
|
let mut buf = Vec::new();
|
||||||
res.push_str("\r\nEND:VCALENDAR");
|
write!(&mut buf, "{}", calendar).unwrap();
|
||||||
res
|
String::from_utf8(buf).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user