Skip to main content

finance_query/models/corporate/news/
scraped.rs

1//! Scraped news article model.
2
3use serde::{Deserialize, Serialize};
4
5/// A news article
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[cfg_attr(feature = "dataframe", derive(crate::ToDataFrame))]
8#[non_exhaustive]
9pub struct News {
10    /// Article title
11    pub title: String,
12
13    /// Article URL
14    pub link: String,
15
16    /// News source/publisher (e.g., "Reuters", "Bloomberg")
17    pub source: String,
18
19    /// Thumbnail image URL
20    pub img: String,
21
22    /// Relative time when the news was published (e.g., "1 hour ago", "2 days ago")
23    pub time: String,
24
25    /// Which provider supplied this article (None = Yahoo Finance default)
26    pub provider_id: Option<crate::providers::Provider>,
27
28    /// Sentiment score for this article's title (VADER lexicon-based).
29    /// Only present when the `sentiment` feature is enabled.
30    #[cfg(feature = "sentiment")]
31    #[serde(skip_serializing_if = "Option::is_none", default)]
32    pub sentiment: Option<crate::models::sentiment::Sentiment>,
33}
34
35impl News {
36    /// Create a new News article
37    pub(crate) fn new(
38        title: String,
39        link: String,
40        source: String,
41        img: String,
42        time: String,
43    ) -> Self {
44        Self {
45            title,
46            link,
47            source,
48            img,
49            time,
50            provider_id: None,
51            #[cfg(feature = "sentiment")]
52            sentiment: None,
53        }
54    }
55}