diff options
author | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-01 22:21:57 +0200 |
---|---|---|
committer | Simon Garrelou <simon.garrelou@gmail.com> | 2023-07-01 22:21:57 +0200 |
commit | 377bfd98cea99483eda2d659d8f1423761ea25ed (patch) | |
tree | b98cf34073e4aa7dcbe9243edc4ed3c98a05588d | |
parent | e1488de3a644113b4de826767a003426c0004d42 (diff) | |
download | rss-377bfd98cea99483eda2d659d8f1423761ea25ed.tar.gz rss-377bfd98cea99483eda2d659d8f1423761ea25ed.zip |
Imporve filter, add render
-rw-r--r-- | Cargo.lock | 516 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/filter.rs | 82 | ||||
-rw-r--r-- | src/main.rs | 79 | ||||
-rw-r--r-- | src/render.rs | 15 |
5 files changed, 690 insertions, 6 deletions
@@ -3,6 +3,24 @@ | |||
3 | version = 3 | 3 | version = 3 |
4 | 4 | ||
5 | [[package]] | 5 | [[package]] |
6 | name = "aho-corasick" | ||
7 | version = "0.7.20" | ||
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
9 | checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" | ||
10 | dependencies = [ | ||
11 | "memchr", | ||
12 | ] | ||
13 | |||
14 | [[package]] | ||
15 | name = "aho-corasick" | ||
16 | version = "1.0.2" | ||
17 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
18 | checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" | ||
19 | dependencies = [ | ||
20 | "memchr", | ||
21 | ] | ||
22 | |||
23 | [[package]] | ||
6 | name = "android-tzdata" | 24 | name = "android-tzdata" |
7 | version = "0.1.1" | 25 | version = "0.1.1" |
8 | source = "registry+https://github.com/rust-lang/crates.io-index" | 26 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -104,6 +122,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
104 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | 122 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" |
105 | 123 | ||
106 | [[package]] | 124 | [[package]] |
125 | name = "block-buffer" | ||
126 | version = "0.10.4" | ||
127 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
128 | checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | ||
129 | dependencies = [ | ||
130 | "generic-array", | ||
131 | ] | ||
132 | |||
133 | [[package]] | ||
134 | name = "bstr" | ||
135 | version = "1.5.0" | ||
136 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
137 | checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5" | ||
138 | dependencies = [ | ||
139 | "memchr", | ||
140 | "serde", | ||
141 | ] | ||
142 | |||
143 | [[package]] | ||
107 | name = "bumpalo" | 144 | name = "bumpalo" |
108 | version = "3.13.0" | 145 | version = "3.13.0" |
109 | source = "registry+https://github.com/rust-lang/crates.io-index" | 146 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -143,6 +180,28 @@ dependencies = [ | |||
143 | ] | 180 | ] |
144 | 181 | ||
145 | [[package]] | 182 | [[package]] |
183 | name = "chrono-tz" | ||
184 | version = "0.6.1" | ||
185 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
186 | checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" | ||
187 | dependencies = [ | ||
188 | "chrono", | ||
189 | "chrono-tz-build", | ||
190 | "phf", | ||
191 | ] | ||
192 | |||
193 | [[package]] | ||
194 | name = "chrono-tz-build" | ||
195 | version = "0.0.2" | ||
196 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
197 | checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" | ||
198 | dependencies = [ | ||
199 | "parse-zoneinfo", | ||
200 | "phf", | ||
201 | "phf_codegen", | ||
202 | ] | ||
203 | |||
204 | [[package]] | ||
146 | name = "clap" | 205 | name = "clap" |
147 | version = "4.3.4" | 206 | version = "4.3.4" |
148 | source = "registry+https://github.com/rust-lang/crates.io-index" | 207 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -207,6 +266,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
207 | checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" | 266 | checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" |
208 | 267 | ||
209 | [[package]] | 268 | [[package]] |
269 | name = "cpufeatures" | ||
270 | version = "0.2.8" | ||
271 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
272 | checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" | ||
273 | dependencies = [ | ||
274 | "libc", | ||
275 | ] | ||
276 | |||
277 | [[package]] | ||
278 | name = "crypto-common" | ||
279 | version = "0.1.6" | ||
280 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
281 | checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" | ||
282 | dependencies = [ | ||
283 | "generic-array", | ||
284 | "typenum", | ||
285 | ] | ||
286 | |||
287 | [[package]] | ||
210 | name = "darling" | 288 | name = "darling" |
211 | version = "0.14.4" | 289 | version = "0.14.4" |
212 | source = "registry+https://github.com/rust-lang/crates.io-index" | 290 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -273,6 +351,22 @@ dependencies = [ | |||
273 | ] | 351 | ] |
274 | 352 | ||
275 | [[package]] | 353 | [[package]] |
354 | name = "deunicode" | ||
355 | version = "0.4.3" | ||
356 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
357 | checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" | ||
358 | |||
359 | [[package]] | ||
360 | name = "digest" | ||
361 | version = "0.10.7" | ||
362 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
363 | checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | ||
364 | dependencies = [ | ||
365 | "block-buffer", | ||
366 | "crypto-common", | ||
367 | ] | ||
368 | |||
369 | [[package]] | ||
276 | name = "diligent-date-parser" | 370 | name = "diligent-date-parser" |
277 | version = "0.1.4" | 371 | version = "0.1.4" |
278 | source = "registry+https://github.com/rust-lang/crates.io-index" | 372 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -390,6 +484,51 @@ dependencies = [ | |||
390 | ] | 484 | ] |
391 | 485 | ||
392 | [[package]] | 486 | [[package]] |
487 | name = "generic-array" | ||
488 | version = "0.14.7" | ||
489 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
490 | checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | ||
491 | dependencies = [ | ||
492 | "typenum", | ||
493 | "version_check", | ||
494 | ] | ||
495 | |||
496 | [[package]] | ||
497 | name = "getrandom" | ||
498 | version = "0.2.10" | ||
499 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
500 | checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" | ||
501 | dependencies = [ | ||
502 | "cfg-if", | ||
503 | "libc", | ||
504 | "wasi 0.11.0+wasi-snapshot-preview1", | ||
505 | ] | ||
506 | |||
507 | [[package]] | ||
508 | name = "globset" | ||
509 | version = "0.4.10" | ||
510 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
511 | checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" | ||
512 | dependencies = [ | ||
513 | "aho-corasick 0.7.20", | ||
514 | "bstr", | ||
515 | "fnv", | ||
516 | "log", | ||
517 | "regex", | ||
518 | ] | ||
519 | |||
520 | [[package]] | ||
521 | name = "globwalk" | ||
522 | version = "0.8.1" | ||
523 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
524 | checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" | ||
525 | dependencies = [ | ||
526 | "bitflags", | ||
527 | "ignore", | ||
528 | "walkdir", | ||
529 | ] | ||
530 | |||
531 | [[package]] | ||
393 | name = "h2" | 532 | name = "h2" |
394 | version = "0.3.19" | 533 | version = "0.3.19" |
395 | source = "registry+https://github.com/rust-lang/crates.io-index" | 534 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -470,6 +609,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
470 | checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" | 609 | checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" |
471 | 610 | ||
472 | [[package]] | 611 | [[package]] |
612 | name = "humansize" | ||
613 | version = "2.1.3" | ||
614 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
615 | checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" | ||
616 | dependencies = [ | ||
617 | "libm", | ||
618 | ] | ||
619 | |||
620 | [[package]] | ||
473 | name = "hyper" | 621 | name = "hyper" |
474 | version = "0.14.26" | 622 | version = "0.14.26" |
475 | source = "registry+https://github.com/rust-lang/crates.io-index" | 623 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -546,6 +694,23 @@ dependencies = [ | |||
546 | ] | 694 | ] |
547 | 695 | ||
548 | [[package]] | 696 | [[package]] |
697 | name = "ignore" | ||
698 | version = "0.4.20" | ||
699 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
700 | checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" | ||
701 | dependencies = [ | ||
702 | "globset", | ||
703 | "lazy_static", | ||
704 | "log", | ||
705 | "memchr", | ||
706 | "regex", | ||
707 | "same-file", | ||
708 | "thread_local", | ||
709 | "walkdir", | ||
710 | "winapi-util", | ||
711 | ] | ||
712 | |||
713 | [[package]] | ||
549 | name = "indexmap" | 714 | name = "indexmap" |
550 | version = "1.9.3" | 715 | version = "1.9.3" |
551 | source = "registry+https://github.com/rust-lang/crates.io-index" | 716 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -621,6 +786,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
621 | checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" | 786 | checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" |
622 | 787 | ||
623 | [[package]] | 788 | [[package]] |
789 | name = "libm" | ||
790 | version = "0.2.7" | ||
791 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
792 | checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" | ||
793 | |||
794 | [[package]] | ||
624 | name = "linux-raw-sys" | 795 | name = "linux-raw-sys" |
625 | version = "0.3.8" | 796 | version = "0.3.8" |
626 | source = "registry+https://github.com/rust-lang/crates.io-index" | 797 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -749,12 +920,104 @@ dependencies = [ | |||
749 | ] | 920 | ] |
750 | 921 | ||
751 | [[package]] | 922 | [[package]] |
923 | name = "parse-zoneinfo" | ||
924 | version = "0.3.0" | ||
925 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
926 | checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" | ||
927 | dependencies = [ | ||
928 | "regex", | ||
929 | ] | ||
930 | |||
931 | [[package]] | ||
752 | name = "percent-encoding" | 932 | name = "percent-encoding" |
753 | version = "2.3.0" | 933 | version = "2.3.0" |
754 | source = "registry+https://github.com/rust-lang/crates.io-index" | 934 | source = "registry+https://github.com/rust-lang/crates.io-index" |
755 | checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" | 935 | checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" |
756 | 936 | ||
757 | [[package]] | 937 | [[package]] |
938 | name = "pest" | ||
939 | version = "2.7.0" | ||
940 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
941 | checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9" | ||
942 | dependencies = [ | ||
943 | "thiserror", | ||
944 | "ucd-trie", | ||
945 | ] | ||
946 | |||
947 | [[package]] | ||
948 | name = "pest_derive" | ||
949 | version = "2.7.0" | ||
950 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
951 | checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b" | ||
952 | dependencies = [ | ||
953 | "pest", | ||
954 | "pest_generator", | ||
955 | ] | ||
956 | |||
957 | [[package]] | ||
958 | name = "pest_generator" | ||
959 | version = "2.7.0" | ||
960 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
961 | checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190" | ||
962 | dependencies = [ | ||
963 | "pest", | ||
964 | "pest_meta", | ||
965 | "proc-macro2", | ||
966 | "quote", | ||
967 | "syn 2.0.18", | ||
968 | ] | ||
969 | |||
970 | [[package]] | ||
971 | name = "pest_meta" | ||
972 | version = "2.7.0" | ||
973 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
974 | checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0" | ||
975 | dependencies = [ | ||
976 | "once_cell", | ||
977 | "pest", | ||
978 | "sha2", | ||
979 | ] | ||
980 | |||
981 | [[package]] | ||
982 | name = "phf" | ||
983 | version = "0.10.1" | ||
984 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
985 | checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" | ||
986 | dependencies = [ | ||
987 | "phf_shared", | ||
988 | ] | ||
989 | |||
990 | [[package]] | ||
991 | name = "phf_codegen" | ||
992 | version = "0.10.0" | ||
993 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
994 | checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" | ||
995 | dependencies = [ | ||
996 | "phf_generator", | ||
997 | "phf_shared", | ||
998 | ] | ||
999 | |||
1000 | [[package]] | ||
1001 | name = "phf_generator" | ||
1002 | version = "0.10.0" | ||
1003 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1004 | checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" | ||
1005 | dependencies = [ | ||
1006 | "phf_shared", | ||
1007 | "rand", | ||
1008 | ] | ||
1009 | |||
1010 | [[package]] | ||
1011 | name = "phf_shared" | ||
1012 | version = "0.10.0" | ||
1013 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1014 | checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" | ||
1015 | dependencies = [ | ||
1016 | "siphasher", | ||
1017 | "uncased", | ||
1018 | ] | ||
1019 | |||
1020 | [[package]] | ||
758 | name = "pin-project-lite" | 1021 | name = "pin-project-lite" |
759 | version = "0.2.9" | 1022 | version = "0.2.9" |
760 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1023 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -773,6 +1036,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
773 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" | 1036 | checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" |
774 | 1037 | ||
775 | [[package]] | 1038 | [[package]] |
1039 | name = "ppv-lite86" | ||
1040 | version = "0.2.17" | ||
1041 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1042 | checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" | ||
1043 | |||
1044 | [[package]] | ||
776 | name = "proc-macro2" | 1045 | name = "proc-macro2" |
777 | version = "1.0.60" | 1046 | version = "1.0.60" |
778 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1047 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -801,6 +1070,36 @@ dependencies = [ | |||
801 | ] | 1070 | ] |
802 | 1071 | ||
803 | [[package]] | 1072 | [[package]] |
1073 | name = "rand" | ||
1074 | version = "0.8.5" | ||
1075 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1076 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" | ||
1077 | dependencies = [ | ||
1078 | "libc", | ||
1079 | "rand_chacha", | ||
1080 | "rand_core", | ||
1081 | ] | ||
1082 | |||
1083 | [[package]] | ||
1084 | name = "rand_chacha" | ||
1085 | version = "0.3.1" | ||
1086 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1087 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" | ||
1088 | dependencies = [ | ||
1089 | "ppv-lite86", | ||
1090 | "rand_core", | ||
1091 | ] | ||
1092 | |||
1093 | [[package]] | ||
1094 | name = "rand_core" | ||
1095 | version = "0.6.4" | ||
1096 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1097 | checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" | ||
1098 | dependencies = [ | ||
1099 | "getrandom", | ||
1100 | ] | ||
1101 | |||
1102 | [[package]] | ||
804 | name = "redox_syscall" | 1103 | name = "redox_syscall" |
805 | version = "0.3.5" | 1104 | version = "0.3.5" |
806 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1105 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -810,6 +1109,23 @@ dependencies = [ | |||
810 | ] | 1109 | ] |
811 | 1110 | ||
812 | [[package]] | 1111 | [[package]] |
1112 | name = "regex" | ||
1113 | version = "1.8.4" | ||
1114 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1115 | checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" | ||
1116 | dependencies = [ | ||
1117 | "aho-corasick 1.0.2", | ||
1118 | "memchr", | ||
1119 | "regex-syntax", | ||
1120 | ] | ||
1121 | |||
1122 | [[package]] | ||
1123 | name = "regex-syntax" | ||
1124 | version = "0.7.2" | ||
1125 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1126 | checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" | ||
1127 | |||
1128 | [[package]] | ||
813 | name = "reqwest" | 1129 | name = "reqwest" |
814 | version = "0.11.18" | 1130 | version = "0.11.18" |
815 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1131 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -853,8 +1169,10 @@ dependencies = [ | |||
853 | "anyhow", | 1169 | "anyhow", |
854 | "chrono", | 1170 | "chrono", |
855 | "clap", | 1171 | "clap", |
1172 | "regex", | ||
856 | "reqwest", | 1173 | "reqwest", |
857 | "rss 2.0.4", | 1174 | "rss 2.0.4", |
1175 | "tera", | ||
858 | "tokio", | 1176 | "tokio", |
859 | ] | 1177 | ] |
860 | 1178 | ||
@@ -868,6 +1186,7 @@ dependencies = [ | |||
868 | "derive_builder", | 1186 | "derive_builder", |
869 | "never", | 1187 | "never", |
870 | "quick-xml", | 1188 | "quick-xml", |
1189 | "serde", | ||
871 | ] | 1190 | ] |
872 | 1191 | ||
873 | [[package]] | 1192 | [[package]] |
@@ -891,6 +1210,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
891 | checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" | 1210 | checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" |
892 | 1211 | ||
893 | [[package]] | 1212 | [[package]] |
1213 | name = "same-file" | ||
1214 | version = "1.0.6" | ||
1215 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1216 | checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" | ||
1217 | dependencies = [ | ||
1218 | "winapi-util", | ||
1219 | ] | ||
1220 | |||
1221 | [[package]] | ||
894 | name = "schannel" | 1222 | name = "schannel" |
895 | version = "0.1.21" | 1223 | version = "0.1.21" |
896 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1224 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -927,6 +1255,20 @@ name = "serde" | |||
927 | version = "1.0.164" | 1255 | version = "1.0.164" |
928 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1256 | source = "registry+https://github.com/rust-lang/crates.io-index" |
929 | checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" | 1257 | checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" |
1258 | dependencies = [ | ||
1259 | "serde_derive", | ||
1260 | ] | ||
1261 | |||
1262 | [[package]] | ||
1263 | name = "serde_derive" | ||
1264 | version = "1.0.164" | ||
1265 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1266 | checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" | ||
1267 | dependencies = [ | ||
1268 | "proc-macro2", | ||
1269 | "quote", | ||
1270 | "syn 2.0.18", | ||
1271 | ] | ||
930 | 1272 | ||
931 | [[package]] | 1273 | [[package]] |
932 | name = "serde_json" | 1274 | name = "serde_json" |
@@ -952,6 +1294,23 @@ dependencies = [ | |||
952 | ] | 1294 | ] |
953 | 1295 | ||
954 | [[package]] | 1296 | [[package]] |
1297 | name = "sha2" | ||
1298 | version = "0.10.7" | ||
1299 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1300 | checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" | ||
1301 | dependencies = [ | ||
1302 | "cfg-if", | ||
1303 | "cpufeatures", | ||
1304 | "digest", | ||
1305 | ] | ||
1306 | |||
1307 | [[package]] | ||
1308 | name = "siphasher" | ||
1309 | version = "0.3.10" | ||
1310 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1311 | checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" | ||
1312 | |||
1313 | [[package]] | ||
955 | name = "slab" | 1314 | name = "slab" |
956 | version = "0.4.8" | 1315 | version = "0.4.8" |
957 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1316 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -961,6 +1320,15 @@ dependencies = [ | |||
961 | ] | 1320 | ] |
962 | 1321 | ||
963 | [[package]] | 1322 | [[package]] |
1323 | name = "slug" | ||
1324 | version = "0.1.4" | ||
1325 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1326 | checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" | ||
1327 | dependencies = [ | ||
1328 | "deunicode", | ||
1329 | ] | ||
1330 | |||
1331 | [[package]] | ||
964 | name = "socket2" | 1332 | name = "socket2" |
965 | version = "0.4.9" | 1333 | version = "0.4.9" |
966 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1334 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1013,6 +1381,58 @@ dependencies = [ | |||
1013 | ] | 1381 | ] |
1014 | 1382 | ||
1015 | [[package]] | 1383 | [[package]] |
1384 | name = "tera" | ||
1385 | version = "1.19.0" | ||
1386 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1387 | checksum = "a5ab29bb4f3e256ae6ad5c3e2775aa1f8829f2c0c101fc407bfd3a6df15c60c5" | ||
1388 | dependencies = [ | ||
1389 | "chrono", | ||
1390 | "chrono-tz", | ||
1391 | "globwalk", | ||
1392 | "humansize", | ||
1393 | "lazy_static", | ||
1394 | "percent-encoding", | ||
1395 | "pest", | ||
1396 | "pest_derive", | ||
1397 | "rand", | ||
1398 | "regex", | ||
1399 | "serde", | ||
1400 | "serde_json", | ||
1401 | "slug", | ||
1402 | "thread_local", | ||
1403 | "unic-segment", | ||
1404 | ] | ||
1405 | |||
1406 | [[package]] | ||
1407 | name = "thiserror" | ||
1408 | version = "1.0.40" | ||
1409 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1410 | checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" | ||
1411 | dependencies = [ | ||
1412 | "thiserror-impl", | ||
1413 | ] | ||
1414 | |||
1415 | [[package]] | ||
1416 | name = "thiserror-impl" | ||
1417 | version = "1.0.40" | ||
1418 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1419 | checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" | ||
1420 | dependencies = [ | ||
1421 | "proc-macro2", | ||
1422 | "quote", | ||
1423 | "syn 2.0.18", | ||
1424 | ] | ||
1425 | |||
1426 | [[package]] | ||
1427 | name = "thread_local" | ||
1428 | version = "1.1.4" | ||
1429 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1430 | checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" | ||
1431 | dependencies = [ | ||
1432 | "once_cell", | ||
1433 | ] | ||
1434 | |||
1435 | [[package]] | ||
1016 | name = "time" | 1436 | name = "time" |
1017 | version = "0.1.45" | 1437 | version = "0.1.45" |
1018 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1438 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1123,6 +1543,77 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1123 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" | 1543 | checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" |
1124 | 1544 | ||
1125 | [[package]] | 1545 | [[package]] |
1546 | name = "typenum" | ||
1547 | version = "1.16.0" | ||
1548 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1549 | checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" | ||
1550 | |||
1551 | [[package]] | ||
1552 | name = "ucd-trie" | ||
1553 | version = "0.1.5" | ||
1554 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1555 | checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" | ||
1556 | |||
1557 | [[package]] | ||
1558 | name = "uncased" | ||
1559 | version = "0.9.9" | ||
1560 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1561 | checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68" | ||
1562 | dependencies = [ | ||
1563 | "version_check", | ||
1564 | ] | ||
1565 | |||
1566 | [[package]] | ||
1567 | name = "unic-char-property" | ||
1568 | version = "0.9.0" | ||
1569 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1570 | checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" | ||
1571 | dependencies = [ | ||
1572 | "unic-char-range", | ||
1573 | ] | ||
1574 | |||
1575 | [[package]] | ||
1576 | name = "unic-char-range" | ||
1577 | version = "0.9.0" | ||
1578 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1579 | checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" | ||
1580 | |||
1581 | [[package]] | ||
1582 | name = "unic-common" | ||
1583 | version = "0.9.0" | ||
1584 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1585 | checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" | ||
1586 | |||
1587 | [[package]] | ||
1588 | name = "unic-segment" | ||
1589 | version = "0.9.0" | ||
1590 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1591 | checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" | ||
1592 | dependencies = [ | ||
1593 | "unic-ucd-segment", | ||
1594 | ] | ||
1595 | |||
1596 | [[package]] | ||
1597 | name = "unic-ucd-segment" | ||
1598 | version = "0.9.0" | ||
1599 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1600 | checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" | ||
1601 | dependencies = [ | ||
1602 | "unic-char-property", | ||
1603 | "unic-char-range", | ||
1604 | "unic-ucd-version", | ||
1605 | ] | ||
1606 | |||
1607 | [[package]] | ||
1608 | name = "unic-ucd-version" | ||
1609 | version = "0.9.0" | ||
1610 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1611 | checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" | ||
1612 | dependencies = [ | ||
1613 | "unic-common", | ||
1614 | ] | ||
1615 | |||
1616 | [[package]] | ||
1126 | name = "unicode-bidi" | 1617 | name = "unicode-bidi" |
1127 | version = "0.3.13" | 1618 | version = "0.3.13" |
1128 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1619 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1167,6 +1658,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1167 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" | 1658 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" |
1168 | 1659 | ||
1169 | [[package]] | 1660 | [[package]] |
1661 | name = "version_check" | ||
1662 | version = "0.9.4" | ||
1663 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1664 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" | ||
1665 | |||
1666 | [[package]] | ||
1667 | name = "walkdir" | ||
1668 | version = "2.3.3" | ||
1669 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1670 | checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" | ||
1671 | dependencies = [ | ||
1672 | "same-file", | ||
1673 | "winapi-util", | ||
1674 | ] | ||
1675 | |||
1676 | [[package]] | ||
1170 | name = "want" | 1677 | name = "want" |
1171 | version = "0.3.0" | 1678 | version = "0.3.0" |
1172 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1679 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1281,6 +1788,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1281 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" | 1788 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
1282 | 1789 | ||
1283 | [[package]] | 1790 | [[package]] |
1791 | name = "winapi-util" | ||
1792 | version = "0.1.5" | ||
1793 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1794 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" | ||
1795 | dependencies = [ | ||
1796 | "winapi", | ||
1797 | ] | ||
1798 | |||
1799 | [[package]] | ||
1284 | name = "winapi-x86_64-pc-windows-gnu" | 1800 | name = "winapi-x86_64-pc-windows-gnu" |
1285 | version = "0.4.0" | 1801 | version = "0.4.0" |
1286 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1802 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -10,6 +10,8 @@ edition = "2021" | |||
10 | anyhow = "1.0.71" | 10 | anyhow = "1.0.71" |
11 | chrono = "0.4.26" | 11 | chrono = "0.4.26" |
12 | clap = { version = "4.3.4", features = ["derive"] } | 12 | clap = { version = "4.3.4", features = ["derive"] } |
13 | regex = "1.8.4" | ||
13 | reqwest = "0.11.18" | 14 | reqwest = "0.11.18" |
14 | rss = "2.0.4" | 15 | rss = { version = "2.0.4", features = ["serde"] } |
16 | tera = "1.19.0" | ||
15 | tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] } | 17 | tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] } |
diff --git a/src/filter.rs b/src/filter.rs new file mode 100644 index 0000000..c1c00b1 --- /dev/null +++ b/src/filter.rs | |||
@@ -0,0 +1,82 @@ | |||
1 | use anyhow::{Result, Context}; | ||
2 | use rss::Channel; | ||
3 | use regex::Regex; | ||
4 | use chrono::{DateTime, Datelike, NaiveDate}; | ||
5 | |||
6 | pub fn run(c: Channel, regex: bool, invert_match: bool, url: Option<String>, title: Option<String>, date: Option<String>) -> Result<Channel> { | ||
7 | let invalid_date = NaiveDate::parse_from_str("1970-01-01", "%Y-%m-%d")?.and_hms_opt(0, 0, 0).unwrap(); | ||
8 | |||
9 | let mut new_channel = c.clone(); | ||
10 | let filter_date = match &date { | ||
11 | Some(date) => { | ||
12 | NaiveDate::parse_from_str(&date, "%Y-%m-%d").context("invalid date")?.and_hms_opt(0, 0, 0).unwrap() | ||
13 | }, | ||
14 | None => { | ||
15 | invalid_date | ||
16 | } | ||
17 | }; | ||
18 | |||
19 | new_channel.items = c.items.iter().filter(|&e| { | ||
20 | let mut url_ok = true; | ||
21 | if let Some(url) = &url { | ||
22 | match &e.link { | ||
23 | Some(link) => { | ||
24 | if !do_match(regex, link, url) { | ||
25 | url_ok = false; | ||
26 | } | ||
27 | }, | ||
28 | None => { | ||
29 | url_ok = false; | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | |||
34 | let mut title_ok = true; | ||
35 | if let Some(title) = &title { | ||
36 | match &e.title { | ||
37 | Some(feed_title) => { | ||
38 | if !do_match(regex, feed_title, title) { | ||
39 | title_ok = false; | ||
40 | } | ||
41 | }, | ||
42 | None => { | ||
43 | title_ok = false; | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | let mut date_ok = true; | ||
49 | if filter_date.timestamp() != invalid_date.timestamp() { | ||
50 | let pub_date = DateTime::parse_from_rfc2822(&e.pub_date.as_ref().unwrap()).unwrap(); | ||
51 | |||
52 | if pub_date.year() != filter_date.year() || pub_date.month() != filter_date.month() || pub_date.day() != filter_date.day() { | ||
53 | date_ok = false; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | let mut ok = url_ok && title_ok && date_ok; | ||
58 | if invert_match { | ||
59 | ok = !ok; | ||
60 | } | ||
61 | |||
62 | return ok; | ||
63 | }).cloned().collect(); | ||
64 | |||
65 | Ok(new_channel) | ||
66 | } | ||
67 | |||
68 | fn do_match(is_regex: bool, haystack: &String, needle: &String) -> bool { | ||
69 | if is_regex { | ||
70 | return match_regex(haystack, needle); | ||
71 | } | ||
72 | return match_substr(haystack, needle); | ||
73 | } | ||
74 | |||
75 | fn match_substr(haystack: &String, needle: &String) -> bool { | ||
76 | return haystack.to_lowercase().contains(&needle.to_lowercase()); | ||
77 | } | ||
78 | |||
79 | fn match_regex(haystack: &String, pattern: &String) -> bool { | ||
80 | let re = Regex::new(pattern).unwrap(); | ||
81 | return re.is_match(haystack); | ||
82 | } \ No newline at end of file | ||
diff --git a/src/main.rs b/src/main.rs index 1836aeb..7fa00f7 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | use clap::{Subcommand, Parser, ValueEnum}; | 1 | use clap::{Subcommand, Parser, ValueEnum}; |
2 | use rss::Channel; | 2 | use rss::Channel; |
3 | use tokio; | 3 | use tokio; |
4 | use std::process::exit; | 4 | use std::{process::exit, io::Write}; |
5 | 5 | ||
6 | mod fetch; | 6 | mod fetch; |
7 | mod sort; | 7 | mod sort; |
8 | mod take; | 8 | mod take; |
9 | mod filter; | ||
10 | mod render; | ||
9 | 11 | ||
10 | #[derive(Parser)] | 12 | #[derive(Parser)] |
11 | struct Args { | 13 | struct Args { |
@@ -28,7 +30,34 @@ enum Commands { | |||
28 | }, | 30 | }, |
29 | 31 | ||
30 | /// Gets the first N items | 32 | /// Gets the first N items |
31 | Take { n: usize } | 33 | Take { n: usize }, |
34 | |||
35 | /// Filters a feed | ||
36 | Filter { | ||
37 | /// Treat filters as regexes instead of substrings | ||
38 | #[arg(short='E', long)] | ||
39 | regex: bool, | ||
40 | |||
41 | /// Only keep non-matching items | ||
42 | #[arg(short='v', long)] | ||
43 | invert_match: bool, | ||
44 | |||
45 | #[arg(short, long)] | ||
46 | url: Option<String>, | ||
47 | |||
48 | #[arg(short, long)] | ||
49 | title: Option<String>, | ||
50 | |||
51 | /// RFC- | ||
52 | #[arg(long)] | ||
53 | date: Option<String> | ||
54 | }, | ||
55 | |||
56 | /// Renders a RSS feed using a Tera template | ||
57 | Render { | ||
58 | /// Path to the template file | ||
59 | template: String | ||
60 | } | ||
32 | } | 61 | } |
33 | 62 | ||
34 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] | 63 | #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] |
@@ -80,7 +109,7 @@ async fn main() { | |||
80 | } | 109 | } |
81 | }, | 110 | }, |
82 | Err(e) => { | 111 | Err(e) => { |
83 | eprintln!("Could not parse RSS: {:?}", e); | 112 | eprintln!("sort: could not parse RSS: {:?}", e); |
84 | exit(1); | 113 | exit(1); |
85 | } | 114 | } |
86 | } | 115 | } |
@@ -94,13 +123,53 @@ async fn main() { | |||
94 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | 123 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); |
95 | }, | 124 | }, |
96 | Err(e) => { | 125 | Err(e) => { |
97 | eprintln!("Error with 'sort': {:?}", e); | 126 | eprintln!("Error with 'take': {:?}", e); |
127 | exit(1); | ||
128 | } | ||
129 | } | ||
130 | }, | ||
131 | Err(e) => { | ||
132 | eprintln!("take: could not parse RSS: {:?}", e); | ||
133 | exit(1); | ||
134 | } | ||
135 | } | ||
136 | }, | ||
137 | |||
138 | Commands::Filter { regex, invert_match, url, title, date } => { | ||
139 | match Channel::read_from(std::io::stdin().lock()) { | ||
140 | Ok (c) => { | ||
141 | match filter::run(c, regex, invert_match, url, title, date) { | ||
142 | Ok(c) => { | ||
143 | c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); | ||
144 | }, | ||
145 | Err(e) => { | ||
146 | eprintln!("Error with 'filter': {:?}", e); | ||
147 | exit(1); | ||
148 | } | ||
149 | } | ||
150 | }, | ||
151 | Err(e) => { | ||
152 | eprintln!("filter: could not parse RSS: {:?}", e); | ||
153 | exit(1); | ||
154 | } | ||
155 | } | ||
156 | }, | ||
157 | |||
158 | Commands::Render { template } => { | ||
159 | match Channel::read_from(std::io::stdin().lock()) { | ||
160 | Ok (c) => { | ||
161 | match render::run(c, template) { | ||
162 | Ok(t) => { | ||
163 | print!("{}", t); | ||
164 | }, | ||
165 | Err(e) => { | ||
166 | eprintln!("Error with 'render': {:?}", e); | ||
98 | exit(1); | 167 | exit(1); |
99 | } | 168 | } |
100 | } | 169 | } |
101 | }, | 170 | }, |
102 | Err(e) => { | 171 | Err(e) => { |
103 | eprintln!("Could not parse RSS: {:?}", e); | 172 | eprintln!("render: could not parse RSS: {:?}", e); |
104 | exit(1); | 173 | exit(1); |
105 | } | 174 | } |
106 | } | 175 | } |
diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 0000000..dca941f --- /dev/null +++ b/src/render.rs | |||
@@ -0,0 +1,15 @@ | |||
1 | use tera::{Tera, Context}; | ||
2 | use anyhow::Result; | ||
3 | use rss::Channel; | ||
4 | |||
5 | pub fn run(c: Channel, filename: String) -> Result<String> { | ||
6 | let mut tera = Tera::default(); | ||
7 | let mut ctx = Context::new(); | ||
8 | |||
9 | ctx.insert("items", c.items()); | ||
10 | |||
11 | let file_contents = std::fs::read_to_string(filename)?; | ||
12 | tera.add_raw_template("template", &file_contents)?; | ||
13 | |||
14 | Ok(tera.render("template", &ctx)?) | ||
15 | } \ No newline at end of file | ||