blooming/source/byrbt/item.rs
1// Copyright 2023 RinChanNOWWW
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::io::BufRead;
16
17use chrono::DateTime;
18use chrono::Local;
19
20use crate::Item;
21use crate::Result;
22
23pub struct Byrbt;
24
25impl Byrbt {
26 pub fn parse_items<R: BufRead>(content: R) -> Result<Vec<Item>> {
27 let channel = rss_for_mikan::Channel::read_from(content)?;
28
29 Ok(channel
30 .items
31 .into_iter()
32 .map(|item| {
33 let date = item.pub_date.unwrap();
34 let pub_date = DateTime::parse_from_rfc2822(&date)
35 .unwrap()
36 .with_timezone(&Local {});
37 Item {
38 title: item.title.unwrap(),
39 pub_date,
40 url: item.link.unwrap(),
41 }
42 })
43 .collect::<Vec<_>>())
44 }
45}