Skip to content

Commit

Permalink
feat: use cnn news feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Jun 14, 2024
1 parent 42890f1 commit 8a6bdb3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@Component
public class NewsFeedConnector implements NewsFeedClient {
public static final String YAHOO_FINANCE_URL = "https://finance.yahoo.com/news/rssindex";
public static final String SEEKING_ALPHA_URL = "https://seekingalpha.com/feed.xml";
public static final String CNN_FINANCE_URL = "http://rss.cnn.com/rss/money_news_companies.rss";
private static final Logger LOGGER = LoggerFactory.getLogger(NewsFeedConnector.class);

@Override
Expand All @@ -45,13 +45,13 @@ public SyndFeed importYahooNewsFeed() {
}

@Override
public SyndFeed importSeekingAlphaNewsFeed() {
public SyndFeed importCnnFinanceNewsFeed() {
SyndFeed feed = null;
try {
SyndFeedInput input = new SyndFeedInput();
feed = input.build(new XmlReader(URI.create(SEEKING_ALPHA_URL).toURL().openStream()));
feed = input.build(new XmlReader(URI.create(CNN_FINANCE_URL).toURL().openStream()));
} catch (IllegalArgumentException | FeedException | IOException e) {
LOGGER.error("SeekingAlpha Feed import failed.",e);
LOGGER.error("CnnFinance Feed import failed.",e);
}
return feed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public List<SyndEntry> getYahooFinace() {
return this.newsFeedService.getYahooNewsFeed();
}

@GetMapping("/seeking-alpha")
public List<SyndEntry> getSeekingAlpha() {
return this.newsFeedService.getSeekingAlphaNewsFeed();
@GetMapping("/cnn-finance")
public List<SyndEntry> getCnnFinance() {
return this.newsFeedService.getCnnFinanceNewsFeed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void updateLoggedOutUsers() {
@Scheduled(cron = "0 */15 * * * ?")
@Order(2)
public void updateNewsFeeds() {
this.newsFeedService.updateSeekingAlphaNewsFeed();
this.newsFeedService.updateCnnFinanceNewsFeed();
this.newsFeedService.updateYahooNewsFeed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void startupDone() throws InterruptedException, ExecutionException {
var portfolioList = this.portfolioService.findAllPortfolios();
portfolioList.forEach(myPortfolio -> this.portfolioService.updatePortfolioValues(myPortfolio));
LOGGER.info("Portfolios updated {}", portfolioList.size());
this.newsFeedService.updateSeekingAlphaNewsFeed();
this.newsFeedService.updateCnnFinanceNewsFeed();
this.newsFeedService.updateYahooNewsFeed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

public interface NewsFeedClient {
SyndFeed importYahooNewsFeed();
SyndFeed importSeekingAlphaNewsFeed();
SyndFeed importCnnFinanceNewsFeed();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class NewsFeedService {

private final NewsFeedClient newsFeedClient;
private volatile Optional<SyndFeed> yahooNewsFeedOptional = Optional.empty();
private volatile Optional<SyndFeed> seekingAlphaNewsFeedOptional = Optional.empty();
private volatile Optional<SyndFeed> cnnFinanceNewsFeedOptional = Optional.empty();

public NewsFeedService(NewsFeedClient newsFeedClient) {
this.newsFeedClient = newsFeedClient;
Expand All @@ -44,10 +44,10 @@ public void updateYahooNewsFeed() {
}

@Async
public void updateSeekingAlphaNewsFeed() {
public void updateCnnFinanceNewsFeed() {
var start = Instant.now();
this.seekingAlphaNewsFeedOptional = Optional.ofNullable(this.newsFeedClient.importSeekingAlphaNewsFeed());
LOGGER.info("SeekingAlpha news imported in: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
this.cnnFinanceNewsFeedOptional = Optional.ofNullable(this.newsFeedClient.importCnnFinanceNewsFeed());
LOGGER.info("CnnFinance news imported in: {}ms", Instant.now().toEpochMilli() - start.toEpochMilli());
}

public List<SyndEntry> getYahooNewsFeed() {
Expand All @@ -57,8 +57,8 @@ public List<SyndEntry> getYahooNewsFeed() {
}).toList();
}

public List<SyndEntry> getSeekingAlphaNewsFeed() {
return this.seekingAlphaNewsFeedOptional.stream().flatMap(myFeed -> myFeed.getEntries().stream()).map(myEntry -> {
public List<SyndEntry> getCnnFinanceNewsFeed() {
return this.cnnFinanceNewsFeedOptional.stream().flatMap(myFeed -> myFeed.getEntries().stream()).map(myEntry -> {
myEntry.getForeignMarkup().clear();
return myEntry;
}).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
></app-portfolio-timechart>
</ng-template>
</mat-tab>
<mat-tab label="Yahoo Finance"><app-news-list [newsItems]="yahooFinanceNews"></app-news-list></mat-tab>
<mat-tab label="Seeking Alpha"><app-news-list [newsItems]="seekingAlphaNews"></app-news-list></mat-tab>
<mat-tab label="Yahoo Finance" i18n-label="@@portfolioChartsYahooFinance"><app-news-list [newsItems]="yahooFinanceNews"></app-news-list></mat-tab>
<mat-tab label="Cnn Finance" i18n-label="@@portfolioChartsCnnFinance"><app-news-list [newsItems]="cnnFinanceNews"></app-news-list></mat-tab>
</mat-tab-group>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { NewsService } from "../../service/news.service";
styleUrls: ["./portfolio-charts.component.scss"],
})
export class PortfolioChartsComponent implements OnInit {
protected seekingAlphaNews: NewsItem[] = [];
protected cnnFinanceNews: NewsItem[] = [];
protected yahooFinanceNews: NewsItem[] = [];
selPortfolio: Portfolio;
reloadData = false;
Expand All @@ -39,7 +39,7 @@ export class PortfolioChartsComponent implements OnInit {
) {}

ngOnInit(): void {
this.newsService.getSeekingAlphaNews().subscribe(result => this.seekingAlphaNews = result);
this.newsService.getCnnFinanceNews().subscribe(result => this.cnnFinanceNews = result);
this.newsService.getYahooNews().subscribe(result => this.yahooFinanceNews = result);
this.route.paramMap
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class NewsService {
return this.httpClient.get<NewsItem[]>('/rest/newsfeed/yahoo-finance');
}

getSeekingAlphaNews(): Observable<NewsItem[]> {
return this.httpClient.get<NewsItem[]>('/rest/newsfeed/seeking-alpha');
getCnnFinanceNews(): Observable<NewsItem[]> {
return this.httpClient.get<NewsItem[]>('/rest/newsfeed/cnn-finance');
}
}

0 comments on commit 8a6bdb3

Please sign in to comment.