Skip to content

Commit

Permalink
Handle redirects and don't show transcript if it 404s
Browse files Browse the repository at this point in the history
  • Loading branch information
danivovich committed Oct 24, 2024
1 parent 1a2773f commit 9bc0fe3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ gem 'rake'
gem 'jekyll-sitemap'
gem 'kramdown', '>= 2.3.1'
gem 'webrick'
gem 'faraday-follow_redirects'
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ GEM
execjs (2.9.1)
faraday (2.9.0)
faraday-net_http (>= 2.0, < 3.2)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.1.0)
net-http
ffi (1.16.3)
Expand Down Expand Up @@ -308,6 +310,7 @@ PLATFORMS
ruby

DEPENDENCIES
faraday-follow_redirects
github-pages
html-proofer
jekyll-sitemap
Expand Down
2 changes: 0 additions & 2 deletions _data/elixir_wizards_transcripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,3 @@ elixirconf2024-hype-isode:
English: "/podcast/elixir-wizards/transcripts/elixirconf2024-hype-isode.txt"
s13-e01-igniter-code-generation-zach-daniel:
English: "/podcast/elixir-wizards/transcripts/s13-e01-igniter-code-generation-zach-daniel.txt"
s13-e02-vintagecell-nerves-bryan-green:
English: "/podcast/elixir-wizards/transcripts/s13-e02-vintagecell-nerves-bryan-green.txt"
14 changes: 10 additions & 4 deletions _scripts/podcasts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'faraday'
require 'nokogiri'
require 'yaml'
require 'faraday/follow_redirects'

def parse_date(date)
Date.parse(date).strftime("%B %e, %Y")
Expand Down Expand Up @@ -62,15 +63,20 @@ def parse_date(date)
transcript_url = transcript.attributes["url"].value

unless File.exist?(transcript_path)
response = Faraday.get(transcript_url)
conn = Faraday.new(url: transcript_url) do |faraday|
faraday.response :follow_redirects # use Faraday::FollowRedirects::Middleware
end
response = conn.get(transcript_url)

if response.success?
File.write(transcript_path, response.body)
transcripts[slug] ||= {}
transcripts[slug]["English"] = "/#{transcript_path}"
else
puts "Couldn't get transcript for #{slug} #{transcript_url} due to #{response.status} on #{response.env.url}"
transcripts.delete(slug)
end
end

transcripts[slug] ||= {}
transcripts[slug]["English"] = "/#{transcript_path}"
end

transcripts
Expand Down

0 comments on commit 9bc0fe3

Please sign in to comment.