Fallback to RSS item content when article fetching fails

This commit is contained in:
Shadowfacts 2019-03-10 19:44:31 -04:00
parent eaa463f2c0
commit 0ebaca4a83
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 19 additions and 15 deletions

View File

@ -93,23 +93,27 @@ defmodule Frenzy.UpdateFeeds do
url = get_real_url(entry)
case get_article_content(url) do
{:ok, content} ->
changeset =
Ecto.build_assoc(feed, :items, %{
guid: entry.id,
title: entry.title,
url: url,
date: parse_date(entry.published_at),
creator: "",
content: content
})
content =
case get_article_content(url) do
{:ok, content} ->
content
Repo.insert(changeset)
{:err, reason} ->
Logger.warn("Unable to fetch article for #{url}: #{reason}")
entry.content || entry.summary
end
{:err, reason} ->
Logger.error("Unable to create item for #{url}: #{reason}")
end
changeset =
Ecto.build_assoc(feed, :items, %{
guid: entry.id,
title: entry.title,
url: url,
date: parse_date(entry.published_at),
creator: "",
content: content
})
Repo.insert(changeset)
end
defp parse_date(str) do