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