commit dc3c341d7199c73e1816d1065c8f419fb2c18456
parent 0f47d47cc86053c26d690ab0f258d0311ff86403
Author: lash <dev@holbrook.no>
Date: Mon, 1 Jul 2024 01:20:07 +0100
Add hardcoded example for channel create and export
Diffstat:
4 files changed, 165 insertions(+), 2 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -36,6 +36,19 @@ dependencies = [
]
[[package]]
+name = "atom_syndication"
+version = "0.12.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2f34613907f31c9dbef0240156db3c9263f34842b6e1a8999d2304ea62c8a30"
+dependencies = [
+ "chrono",
+ "derive_builder",
+ "diligent-date-parser",
+ "never",
+ "quick-xml",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -120,7 +133,7 @@ dependencies = [
"ansi_term",
"atty",
"bitflags 1.3.2",
- "strsim",
+ "strsim 0.8.0",
"textwrap",
"unicode-width",
"vec_map",
@@ -136,12 +149,14 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
name = "crier"
version = "0.0.1"
dependencies = [
+ "atom_syndication",
"chrono",
"clap",
"digest",
"feed-rs",
"http",
"rs_sha512",
+ "rss",
"tempfile",
]
@@ -156,6 +171,72 @@ dependencies = [
]
[[package]]
+name = "darling"
+version = "0.20.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1"
+dependencies = [
+ "darling_core",
+ "darling_macro",
+]
+
+[[package]]
+name = "darling_core"
+version = "0.20.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120"
+dependencies = [
+ "fnv",
+ "ident_case",
+ "proc-macro2",
+ "quote",
+ "strsim 0.11.1",
+ "syn",
+]
+
+[[package]]
+name = "darling_macro"
+version = "0.20.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178"
+dependencies = [
+ "darling_core",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "derive_builder"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7"
+dependencies = [
+ "derive_builder_macro",
+]
+
+[[package]]
+name = "derive_builder_core"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d"
+dependencies = [
+ "darling",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "derive_builder_macro"
+version = "0.20.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b"
+dependencies = [
+ "derive_builder_core",
+ "syn",
+]
+
+[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -166,6 +247,15 @@ dependencies = [
]
[[package]]
+name = "diligent-date-parser"
+version = "0.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6cf7fe294274a222363f84bcb63cdea762979a0443b4cf1f4f8fd17c86b1182"
+dependencies = [
+ "chrono",
+]
+
+[[package]]
name = "encoding_rs"
version = "0.8.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -287,6 +377,12 @@ dependencies = [
]
[[package]]
+name = "ident_case"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
+
+[[package]]
name = "idna"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -342,6 +438,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
+name = "never"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c96aba5aa877601bb3f6dd6a63a969e1f82e60646e81e71b14496995e9853c91"
+
+[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -468,6 +570,18 @@ dependencies = [
]
[[package]]
+name = "rss"
+version = "2.0.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f374fd66bb795938b78c021db1662d43a8ffbc42ec1ac25429fc4833b732751"
+dependencies = [
+ "atom_syndication",
+ "derive_builder",
+ "never",
+ "quick-xml",
+]
+
+[[package]]
name = "rustix"
version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -530,6 +644,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
+name = "strsim"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
+
+[[package]]
name = "syn"
version = "2.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
@@ -8,7 +8,8 @@ rust-version = "1.79"
[dependencies]
#rss = "^2.0.3"
-feed-rs = "^2.0.0"
+feed-rs = "^2.0"
+rss = "^2.0"
#activitypub_federation = "^0.4.0"
#json-ld = "^0.14.1"
digest = "^0.10.7"
@@ -18,6 +19,7 @@ clap = "2.34.0"
rs_sha512 = "^0.1.3"
http = "^1.0"
chrono = "^0.4"
+atom_syndication = "^0.12"
[dev-dependencies]
tempfile = "3.3.0"
diff --git a/src/lib.rs b/src/lib.rs
@@ -6,6 +6,9 @@ use feed_rs::model::Entry;
use feed_rs::model::Feed;
use rs_sha512::Sha512Hasher;
use chrono::DateTime;
+use chrono::Local;
+use atom_syndication::Feed as OutFeed;
+use std::io::Write;
mod io;
@@ -50,6 +53,21 @@ impl Sequencer {
}
c
}
+
+ fn write_to(&self, w: impl Write) -> Result<(), atom_syndication::Error> {
+ let mut v = Vec::<u8>::new();
+ //let mut feed = FeedBuilder::default();
+ //feed.title("Mixer feed");
+ //feed.build().write_to(v).unwrap();
+ //feed.build().write_to(w).unwrap();
+ let mut feed = OutFeed::default();
+ feed.set_id("urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6");
+ feed.set_title("Mixed feed");
+ feed.set_updated(Local::now().to_utc());
+ //feed.write_to(&mut v)?;
+ feed.write_to(w)?;
+ Ok(())
+ }
}
impl Iterator for Sequencer {
diff --git a/src/tests.rs b/src/tests.rs
@@ -1,7 +1,11 @@
use std::clone::Clone;
+use std::fs::Metadata;
+use std::fs::metadata;
+use std::fs::File;
use feed_rs::model::Entry;
use chrono::DateTime;
+use tempfile::NamedTempFile;
use super::Sequencer;
use super::io::FeedGet;
@@ -71,3 +75,22 @@ fn test_feed_mix() {
assert_eq!(seq.by_ref().count(), 25);
assert_eq!(seq.count(), 25);
}
+
+#[test]
+#[cfg(feature = "fs")]
+fn test_feed_write() {
+ let r: Metadata;
+ let fs = Fs{};
+ let f: NamedTempFile;
+ let fr: File;
+ let fp: String;
+
+ let feed = fs.get("testdata/test.atom.xml", None).unwrap();
+ let mut seq = Sequencer::new();
+ seq.add_from(feed);
+ f = NamedTempFile::new().unwrap();
+ fr = f.reopen().unwrap();
+ fp = String::from(f.path().to_str().unwrap());
+ seq.write_to(f).unwrap();
+ assert_eq!(fr.metadata().unwrap().len(), 204);
+}